2. Final Report Tasniflagich


 Middlewares and grouping


Download 3.88 Mb.
Pdf ko'rish
bet10/15
Sana25.07.2023
Hajmi3.88 Mb.
#1662428
1   ...   7   8   9   10   11   12   13   14   15
Bog'liq
2.Final Report Tasniflagich

3.3.2 Middlewares and grouping
Tasniflagich has an admin panel to add, edit existing goods (work, services), in order to set
policy in laravel we can add middleware to our routes, in order to prevent this actions from
unknown users. Figure 7 represents the “group” method of Route class. By group method we can
combine a set of routes and give them common characteristics such as middleware, prefix,
domain, Controller name, name prefix. To the “group” method we passed property middleware
with value “isAdmin”. ”isAdmin” is a middleware to differentiate administrators from general
users. This middleware was created by me previously.
Figure 7. grouping routes and adding middleware
Laravel has a script to create a middleware scaffold file (look Figure 8), which creates a
given file name in app/Http/Middleware directory. To use this middleware in api.php we should
link
it
to
application’s
route
middlewares
in
app/Http/Kernel.php
to
property
$routeMiddleware
Figure 8. creating new middleware
Finally, we reviewed all parts to define application routes. At the end it should look like in
Figure 9.
Figure 9. api.php result
TTPU
16
2022


TTPU
17
2022


3.4 Models
3.4.1 Introduction to models
Laravel includes Eloquent, an object-relational mapper (ORM) that makes it enjoyable to
interact with your database. When using Eloquent, each database table has a corresponding
"Model" that is used to interact with that table. In addition to retrieving records from the database
table, Eloquent models allow you to insert, update, and delete records from the table as well. We
can create models via artisan in the console.
Figure 10. Create model in console

Download 3.88 Mb.

Do'stlaringiz bilan baham:
1   ...   7   8   9   10   11   12   13   14   15




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling