Laravel level 2 (Let's Practical)

spicydog 89 views 8 slides Dec 02, 2018
Slide 1
Slide 1 of 8
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8

About This Presentation

This is a slide for lecture in topic of super introduction to Laravel for Lecture for Applied Computer Science, KMUTT, Bangkok, Thailand.


Slide Content

Laravel Level 2
A Tour on Practical Laravel
By Spicydog (14/11/2016)

Agenda
●Authentication
●Model Relationships
●Laravel Collective
●Form & Validation
●Session & Flash Data
●Middleware
●Workshop & Assignments

Laravel: Authentication
●Easy to use built-in Authentication
●Run php artisan make:auth to get bootstrapped codes
●Run php artisan migrate to change create the tables
●The default identification is email but you can change it freely
- Edit the column of users table migration
- Edit the codes in Controllers/Auth

Laravel: Model Relationships
●Laravel has Eloquent as ORM, so you can “ALMOST” leave the SQL aways
●1:1, 1:many, many:many, and more are all in Eloquent Relationships
●Follow the naming convention to get the shortest code possible

Laravel: Laravel Collective (HTML)
●Laravel Collective is a set tools those have been removed from Laravel
●This make coding easier and cleaner yet bad performance as a trade-off
●Yet we use because it makes coding easier like Form::text('username');
●It has so many useful features focusing for productivity

Here is how to install:
Run: composer require "laravelcollective/html":"^5.3.0"
Then add providers and aliases

Laravel: Form Validation
●Form validation is critical for most web applications!
●Of course, Laravel has built-in Form Validation
●Before saving data, do something like this
$this->validate($request, [
'title' => 'required|unique:posts|max:255',
'body' => 'required',
]);
●There are lots of rules with combination for what all you needs
●The errors automatically send back to the views in $errors variable

●Laravel Session and Flash Data is a temporary storage for each user
●Laravel just simply have a helper HTTP Session for you to use
●But Laravel Session can connect to database, so you can use multiple
Laravel applications on load balancer without any issue!

●Flash Data is one useful application of HTTP Session that
show once and gone!
●This is useful when you want to send temporary message to the users
e.g. “Login successfully” and “Form validation fail”
Set: session()->flash('status', 'Task was successful!');
Get: session('status');

Laravel: Session & Flash Data

●Middleware is layers of logics
●This is useful for functions such as authentication, authorization, logging
●Middleware are in “Http/Middleware”
●You can register and config middleware flow at “Http/Kernel.php”
●After that, you can flexibly use middleware whenever you want
●Mostly we use middleware in route and controller, Example.
Laravel: Middleware