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