Laravel Tutorial
DAY 2
Route
URL Named Route
The route helper may be used to generate URLs to named routes.
Named routes allow you to generate URLs without being coupled to the actual URL defined on the route.
Therefore, if the route’s URL changes, no changes need to be made to your route function calls.

Routing - Group and Named Route
All Laravel routes are defined in your route files, which are located in the routes directory. For more information, click here.

Routing - Group and Named Route
php artisan route:list
Routing - Named Route
Named route with model binding

Model
- Model used to define fillable attributes.
- Model also can be used to define relationship
- 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

Relationship
Relationship 1:M
- A one-to-many relationship is used to define relationships where a single model owns any amount of other models.
- User has many schedules
- Schedule belongs to User
On Schedule.php

On User.php

Relationship - Lazy Load Attribute
A one-to-many relationship is used to define relationships where a single model owns any amount of other models

Show, Edit, Update & Delete
Views
Views are stored in the resources/views directory
Go to resources/views
Create trainings folder, create
- show.blade.php
- edit.blade.php

Controller
php artisan make:controller ScheduleController
7 method in controllers
- Index
- Create
- Store
- Show
- Edit
- Update
- Destroy
Show
Controller – Show
Description | URL | Controller Function | View File |
---|---|---|---|
Show one of the schedules | GET/schedules/{id} | show() | resources/views/schedules/show.blade.php |

Edit
Controller – Edit
Description | URL | Controller Function | View File |
---|---|---|---|
Pull a schedule form the database and allow editing | GET/schedules/{id}/edit | edit() | resources/views/schedules/edit.blade.php |
View – Edit View
Views are stored in the resources/views
directory
- Go to resources/views/schedules/edit.blade.php

Update
Controller – Update
Description | URL | Controller Function | View File |
---|---|---|---|
Process the create form submit and save the training to the database | POST/schedules/{id} | update() | NONE |

Delete
Controller – Destroy/Delete
Description | URL | Controller Function | View File |
---|---|---|---|
Delete the training from DB | GET/schedules/{id}/delete | delete() | NONE |

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.

Pagination
The paginate method automatically takes care of setting the proper limit and offset based on the current page being viewed by the user.
app/Http/Controllers/ScheduleController.php

resources/views/schedules/index.blade.php

Laravel Error Page
Custom HTTP Error Pages
Create folder name errors in
resources/views/
Example Http Error 404, create 404.blade.php
