Developpement back-end -Initiation Laravel 10

YounessABOUQORA 31 views 178 slides Oct 20, 2024
Slide 1
Slide 1 of 178
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60
Slide 61
61
Slide 62
62
Slide 63
63
Slide 64
64
Slide 65
65
Slide 66
66
Slide 67
67
Slide 68
68
Slide 69
69
Slide 70
70
Slide 71
71
Slide 72
72
Slide 73
73
Slide 74
74
Slide 75
75
Slide 76
76
Slide 77
77
Slide 78
78
Slide 79
79
Slide 80
80
Slide 81
81
Slide 82
82
Slide 83
83
Slide 84
84
Slide 85
85
Slide 86
86
Slide 87
87
Slide 88
88
Slide 89
89
Slide 90
90
Slide 91
91
Slide 92
92
Slide 93
93
Slide 94
94
Slide 95
95
Slide 96
96
Slide 97
97
Slide 98
98
Slide 99
99
Slide 100
100
Slide 101
101
Slide 102
102
Slide 103
103
Slide 104
104
Slide 105
105
Slide 106
106
Slide 107
107
Slide 108
108
Slide 109
109
Slide 110
110
Slide 111
111
Slide 112
112
Slide 113
113
Slide 114
114
Slide 115
115
Slide 116
116
Slide 117
117
Slide 118
118
Slide 119
119
Slide 120
120
Slide 121
121
Slide 122
122
Slide 123
123
Slide 124
124
Slide 125
125
Slide 126
126
Slide 127
127
Slide 128
128
Slide 129
129
Slide 130
130
Slide 131
131
Slide 132
132
Slide 133
133
Slide 134
134
Slide 135
135
Slide 136
136
Slide 137
137
Slide 138
138
Slide 139
139
Slide 140
140
Slide 141
141
Slide 142
142
Slide 143
143
Slide 144
144
Slide 145
145
Slide 146
146
Slide 147
147
Slide 148
148
Slide 149
149
Slide 150
150
Slide 151
151
Slide 152
152
Slide 153
153
Slide 154
154
Slide 155
155
Slide 156
156
Slide 157
157
Slide 158
158
Slide 159
159
Slide 160
160
Slide 161
161
Slide 162
162
Slide 163
163
Slide 164
164
Slide 165
165
Slide 166
166
Slide 167
167
Slide 168
168
Slide 169
169
Slide 170
170
Slide 171
171
Slide 172
172
Slide 173
173
Slide 174
174
Slide 175
175
Slide 176
176
Slide 177
177
Slide 178
178

About This Presentation

Laravel est un framework PHP open-source qui facilite le développement d'applications web robustes et élégantes. Il suit le modèle MVC (Modèle-Vue-Contrôleur) et est conçu pour rendre le développement web plus accessible, en fournissant une syntaxe expressive et des fonctionnalités int�...


Slide Content

Laravel 10 Developpement back-end Pr. Y.abouqora

Laravel 01 Démarrer un projet laravel

Plan Jour 1 Créer un projet Laravel Travailler avec la base de données. Travailler avec le modèle Travailler avec les contrôleurs Travailler avec les vues Ce qu'il faut : Laragon phpMyAdmin VS Code 3

routes/ web.php app/Http/Controllers app/ resources/views

Create Laravel First Project Installez Laravel en lançant la commande Composer create-project dans votre terminal 5 composer create-project – prefer-dist laravel / laravel project - name

With Laragon ? Never been EASIER. laragon.org

Laragon Qu'est-ce que Laragon ? Laragon est un environnement de développement universel portable, isolé, rapide et puissant pour PHP, Node.js, Python, Java, Go, Ruby. Il est rapide, léger, facile à utiliser et à étendre. Pourquoi Laragon ? Laragon est idéal pour construire et gérer des applications web modernes. Il est axé sur la performance - conçu autour de la stabilité, de la simplicité, de la flexibilité et de la liberté. Laragon améliore le développement web. Les développeurs du monde entier utilisent Laragon pour créer des applications rapidement et facilement. Il est utilisé par des milliers de développeurs avec amour. Vous pouvez consulter les témoignages pour voir ce que les utilisateurs pensent de Laragon et la page des caractéristiques pour plus de détails. 7

Change DB root password 8

Laravel t02 Comment ajouter facilement une page de connexion et une liste d'utilisateurs ?

Turn On Laragon Par défaut, Laragon utilise le port 80 pour Apache et le port 3306 pour la base de données. 10

Create Project 11

Laravel project with Pretty URL Test the Pretty url in browser 12

Modifier DB credentials in .env 13

Download and install phpmyadmin.Net Essayez l'accès http://localhost/ pma 14

Phpmyadmin config.inc 15

Authentication Module Laravel rend la mise en œuvre de l'authentification très simple. En fait, presque tout est configuré pour vous dès le départ. 16 composer require laravel / ui --dev php artisan ui bootstrap -- auth npm install & npm run dev

Authentication Module 17

18

Laravel t03 Base de données– migration, seeder & factory

routes/ web.php app/Http/Controllers app/ resources/views

Working with Database Migrations de bases de données Les migrations sont comme un contrôle de version pour votre base de données. 22 public function up() { Schema :: create ('trainings', function ( Blueprint $table) { $ table  bigIncrements ('id’); $ table  string (' title ’); $ table  text ('description’); $ table  string ('trainer’); $ table  timestamps (); $ table  unsignedBigInteger (' user_id ’); $ table  foreign (' user_id ')—> references ('id')—>on(' users '); }); Make Migrations php artisan make:migration create_trainings_table

php artisan migrate 23 Run Migrations php artisan migrate

Model Models typically live in the app directory. All Eloquent models extend Illuminate\Database\Eloquent\Model class. 24

Model Model also can be used to to specify custom table. Model also can be used to define mutator Model also can be used to define local scope Model used to define fillable attributes. Model also can be used to define relationship 25

Working with Database Database Seeds Laravel includes a simple method of seeding your database with test data using seed classes. On database / seeds / DatabaseSeeder.php On database / seeds / TrainingsTableSeeder.php 26

Working with Database : run seeder 27

Working with Database Database Factories Laravel has a feature called model factories that allows you to build fake data for your models. 28

How to create and run migrations, seeder and factory? Here are the example. 29

Laravel t04 Views (create form, save new record, list records in index )

routes/ web.php app/Http/Controllers app/ resources/views

Create new record interface ( create.blade.php )

Training index.blade.php

Views Views contain the HTML served by your application and separate your controller / application logic from your presentation logic. Views are stored in the resources/views directory Go to resources/views Create training folder Inside training folder, create: create.blade.php index.blade.php 34

Views – Create View Views are stored in the resources/views directory Go to resources/views/trainings/ create.blade.php 35

Views – Index View Views are stored in the resources/views directory Go to resources/views/trainings/ index.blade.php 36

Laravel t07 Controller

routes/ web.php app/Http/Controllers app/ resources/views

Controller Instead of defining all of your request handling logic as Closures in route files, you may wish to organize this behavior using Controller classes. Controllers can group related request handling logic into a single class. Controllers are stored in the app/Http/Controllers directory. 39

Controller 7 method in controllers 40

Controller - Create 41

Controller - Index 42

Controller - Store 43

Laravel t09 Routing

routes/ web.php app/Http/Controllers app/ resources/views

Routing All Laravel routes are defined in your route files, which are located in the routes directory. https://laravel.com/docs/6.x/routing . 46

Simple Routing All Laravel routes are defined in your route files, which are located in the routes directory. https://laravel.com/docs/6.x/routing . 47

Simple routing ( routes/ web.php ) 48 index

Simple Routing php artisan route:list https://laravel.com/docs/6.x/routing . 49

php artisan route:list 50

51

Advanced ROUTING: group & named http://fstm.kuis.edu.my/blog/laravel 52

php artisan route:list http://fstm.kuis.edu.my/blog/laravel 53

Laravel t07 Search

Search Create form to input keyword Query the keyword that match with title 55

Search - Form Using GET method to named route training:index 56

Simple routing ( routes/ web.php ) 57 index

Simple Routing php artisan route:list https://laravel.com/docs/6.x/routing . 58

Search – Index Method Check if there is keyword, if there is keyword on query string, run query to search column where like title. If no keyword, the method will return collection rows from trainings table. 59

Laravel t08 Pagination

61

Search - Pagination The paginate method automatically takes care of setting the proper limit and offset based on the current page being viewed by the user and append with keywords. 62

TrainingController@index 63

Hacks Creating Index - https://github.com/samtarmizi/laravel-spr/commit/1c925853f61da081f0e3ce298e58a4a423b66040 Creating Create - https://github.com/samtarmizi/laravel-spr/commit/7a5b5f3b643bcb8a265af3bb9f4e94e3aef95aa1 Creating Store - https://github.com/samtarmizi/laravel-spr/commit/2513b55c65bc4d27afa5004144ee2c7d41b3cbd7 64

Laravel t10 npm not found

npm not found http://fstm.kuis.edu.my/blog/laravel 66

Authentication Module Laravel makes implementing authentication very simple. In fact, almost everything is configured for you out of the box. 67

Laragon Includes NODEJS http://fstm.kuis.edu.my/blog/laravel 68

Terminal in Laragon Laravel makes implementing authentication very simple. In fact, almost everything is configured for you out of the box. http://fstm.kuis.edu.my/blog/laravel 69

Locate nodejs in Laragon http://fstm.kuis.edu.my/blog/laravel 70

Environment variables http://fstm.kuis.edu.my/blog/laravel 71

Set path to nodejs http://fstm.kuis.edu.my/blog/laravel 72

NODEJS.ORG http://fstm.kuis.edu.my/blog/laravel 73

Laravel t11 Middleware enforced Auth

Middleware Middleware provide a convenient mechanism for filtering HTTP requests entering your application. For example, Laravel includes a middleware that verifies the user of your application is authenticated. If the user is not authenticated, the middleware will redirect the user to the login screen. http://fstm.kuis.edu.my/blog/laravel 75

Add to dashboard menu 76

Laravel t12 Test Laravel project from Github repo

NODEJS.ORG http://fstm.kuis.edu.my/blog/laravel 78

Github.com/khirulnizam/lara7 http://fstm.kuis.edu.my/blog/laravel 79

Git clone http://fstm.kuis.edu.my/blog/laravel 80

composer & npm install http://fstm.kuis.edu.my/blog/laravel 81

.env file 82

php artisan migrate & seed Inside Laravel project folder php artisan key:generate php artisan migrate php artisan db:seed 83

Laravel t13 Show records

Table with lots of column http://fstm.kuis.edu.my/blog/laravel 85

Github.com/khirulnizam/lara7 Slides & codes http://fstm.kuis.edu.my/blog/laravel 86

DISCLAIMER Codes are for demo purposes. Example showed here are only to validate the proof of concepts. Security aspect the demonstrated examples are beyond the coverage of these video tutorials. You are advised to explore / sought after advanced/security topics of PHP web programming as these tutorials only for beginner level. Suitable to view in DESKTOP 10/20/2024 fstm.kuis.edu.my 87

Views Views are stored in the resources/views directory Go to resources/views Go to trainings folder, create: show.blade.php edit.blade.php http://fstm.kuis.edu.my/blog/laravel 88

Controller 7 method in controllers http://fstm.kuis.edu.my/blog/laravel 89

routes/ web.php app/Http/Controllers app/ resources/views

Controller - Show http://fstm.kuis.edu.my/blog/laravel 91

Views – Show View Views are stored in the resources/views directory Go to resources/views/trainings/show.blade.php http://fstm.kuis.edu.my/blog/laravel 92

Github.com/khirulnizam/lara7 http://fstm.kuis.edu.my/blog/laravel 93

Github.com/khirulnizam/lara7 Slides & codes http://fstm.kuis.edu.my/blog/laravel 94

Laravel t14 Font-awesome thru CDN

Github.com/khirulnizam/lara7 Slides & codes http://fstm.kuis.edu.my/blog/laravel 96

CDN – CONTENT DELIVERY NETWORK CDN – load library/ framework from public host server t o provide high availability and performance https://www.bootstrapcdn.com/fontawesome/ 97

FONTAWESOME IN SIMPLE HTML http://fstm.kuis.edu.my/blog/laravel 98

Import font-awesome from CDN http://fstm.kuis.edu.my/blog/laravel 99

Tag: <i></i> <i class="fa fa-file-text"></i> <p>Used on a button:</p> <button> Show <i class="fa fa-file-text"></i> </button> 100

Import font-awesome CDN in Laravel layout 101

https://www.bootstrapcdn.com/fontawesome/ http://fstm.kuis.edu.my/blog/laravel 102

Implement in buttons http://fstm.kuis.edu.my/blog/laravel 103

Github.com/khirulnizam/lara7 Slides & codes 104

Laravel t15 Edit/Update

UPDATE RECORD PROCESS 10/20/2024 106 Index (choose ) id id Edit (form) Update (save)

DISCLAIMER Codes are for demo purposes. Example showed here are only to validate the proof of concepts. Security aspect the demonstrated examples are beyond the coverage of these video tutorials. You are advised to explore / sought after advanced/security topics of PHP web programming as these tutorials only for beginner level. Suitable to view in DESKTOP 10/20/2024 107

Github.com/khirulnizam/lara7 108 Slides & codes T12 Tutorial clone/download github repo

Controller - Edit 109

Views – Edit View Views are stored in the resources/views directory Go to resources/views/trainings/edit.blade.php 110

http://fstm.kuis.edu.my/blog/laravel 111

Controller - Update http://fstm.kuis.edu.my/blog/laravel 112

Output screen http://fstm.kuis.edu.my/blog/laravel 113

Laravel t16 Delete records

DISCLAIMER Codes are for demo purposes. Example showed here are only to validate the proof of concepts. Security aspect the demonstrated examples are beyond the coverage of these video tutorials. You are advised to explore / sought after advanced/security topics of PHP web programming as these tutorials only for beginner level. Suitable to view in DESKTOP 10/20/2024 115

Github.com/khirulnizam/lara7 116 Slides & codes T12 Tutorial clone/download github repo

Overview http://fstm.kuis.edu.my/blog/laravel 117

Delete button inside FORM http://fstm.kuis.edu.my/blog/laravel 118

Routing – Group and Named Route All Laravel routes are defined in your route files, which are located in the routes directory. https://laravel.com/docs/7.x/routing. 119

Routing – Group and Named Route php artisan route:list https://laravel.com/docs/7.x/routing . 120

Controller – Destroy/Delete 121

Laravel t17 @csrf (Built-in security token for post method)

DISCLAIMER Codes are for demo purposes. Example showed here are only to validate the proof of concepts. Security aspect the demonstrated examples are beyond the coverage of these video tutorials. You are advised to explore / sought after advanced/security topics of PHP web programming as these tutorials only for beginner level. Suitable to view in DESKTOP 10/20/2024 123

Github.com/khirulnizam/lara7 124 Slides & codes T12 Tutorial clone/download github repo

What is CSRF? 125 OWASP.org Cross-Site Request Forgery - is an attack that forces an end user to execute unwanted actions on a web application in which they're currently authenticated.

Implementation in Laravel blade 126

Location of csrf app_key Use to hash security token http://fstm.kuis.edu.my/blog/laravel 127

Laravel t18 Apply Bootstrap Layout

Output overview http://fstm.kuis.edu.my/blog/laravel 129

DISCLAIMER Codes are for demo purposes. Example showed here are only to validate the proof of concepts. Security aspect the demonstrated examples are beyond the coverage of these video tutorials. You are advised to explore / sought after advanced/security topics of PHP web programming as these tutorials only for beginner level. Suitable to view in DESKTOP 10/20/2024 130

Github.com/khirulnizam/lara7 131 Slides & codes T12 Tutorial clone/download github repo

Theme from https://startbootstrap.com/themes/landing-page/ http://fstm.kuis.edu.my/blog/laravel 132

http://fstm.kuis.edu.my/blog/laravel 133 Asset/resources for template

Blade asset( ) function – apply on both css & js http://fstm.kuis.edu.my/blog/laravel 134

@yield( ) http://fstm.kuis.edu.my/blog/laravel 135

@yield( ) 136

Output overview http://fstm.kuis.edu.my/blog/laravel 137

landingpage.blade.php http://fstm.kuis.edu.my/blog/laravel 138

route/web.php http://fstm.kuis.edu.my/blog/laravel 139

Github.com/khirulnizam/lara7 140 Slides & codes T12 Tutorial clone/download github repo

Laravel t19 Apply Bootstrap on Admin Dashboard

Output overview http://fstm.kuis.edu.my/blog/laravel 142

DISCLAIMER Codes are for demo purposes. Example showed here are only to validate the proof of concepts. Security aspect the demonstrated examples are beyond the coverage of these video tutorials. You are advised to explore / sought after advanced/security topics of PHP web programming as these tutorials only for beginner level. Suitable to view in DESKTOP 10/20/2024 143

Github.com/khirulnizam/lara7 144 Slides & codes T12 Tutorial clone/download github repo

Theme from https://startbootstrap.com/themes/sb-admin-2/ http://fstm.kuis.edu.my/blog/laravel 145

146 Asset/resources for template

First time display the new template http://fstm.kuis.edu.my/blog/laravel 147

Blade asset( ) function – apply on both css & js 148

@yield( ) http://fstm.kuis.edu.my/blog/laravel 149

@yield( ) 150 @yield( )

Output overview http://fstm.kuis.edu.my/blog/laravel 151

index.blade.php http://fstm.kuis.edu.my/blog/laravel 152

Github.com/khirulnizam/lara7 153 Slides & codes T12 Tutorial clone/download github repo

Laravel t20 Muat naik fail gambar

Upload image 155 Upload image Show uploaded image

DISCLAIMER Codes are for demo purposes. Example showed here are only to validate the proof of concepts. Security aspect the demonstrated examples are beyond the coverage of these video tutorials. You are advised to explore / sought after advanced/security topics of PHP web programming as these tutorials only for beginner level. Suitable to view in DESKTOP 10/20/2024 156

Github.com/khirulnizam/lara7 157 Slides & codes T12 Tutorial clone/download github repo

Add column to table trainings Field to hold image’s filename 158

Additional field to table trainings 159

function up() – additional migration file 160

php artisan migrate 161

create.blade.php – to select and upload image 162 Upload image

Add enctype in create.blade.php 163

Add input type=“file” in create.blade.php 164

app/ Training.php - Add fillable for the fields http://fstm.kuis.edu.my/blog/laravel 165

Validate uploaded file type 166

TrainingController@store – validate file type 167

TrainingController@store – continued… http://fstm.kuis.edu.my/blog/laravel 168

Storage not found http://fstm.kuis.edu.my/blog/laravel 169

Configuring Filesystem for Storage config/filesystems.php 170

File Storage Create Symbolic Link The public disk is intended for files that are going to be publicly accessible. By default, the public disk uses the local driver and stores these files in storage/app/public. To make them accessible from the web, you should create a symbolic link from  public/storage  to  storage/app/public . 171

Virtual link of public file storage 172

Physical link of public file storage http://fstm.kuis.edu.my/blog/laravel 173 The actual physical location of the file storage To make them accessible from the web, you should create a symbolic link from  public/storage  to  storage/app/public .

create.blade.php - Display validation errors http://fstm.kuis.edu.my/blog/laravel 174

Github.com/khirulnizam/lara7 175 Slides & codes T12 Tutorial clone/download github repo

Laravel t19 Table relationship

Laravel t20 Insert record with drop down data option

Laravel t21 Upload record with file (Muat naik sebarang fail)
Tags