Laravel @ Kelltontech 22nd November '16
What's Laravel ? THE PHP FRAMEWORK FOR WEB ARTISANS. PHP THAT DOESN'T HURT. CODE HAPPY & ENJOY THE FRESH AIR.
Where To Start From? Laravel is very flexible framwork. There are at least 3 options how to create new project: ✔ via laravel installer ✔ via composer ✔ clone from github
Via Laravel Installer? This will download laravel installer via composer composer global require "laravel/installer" This simple command will create app laravel new blog
Other Options Via composer composer create-project --prefer-dist laravel/laravel blog Get From github https://github.com/laravel/laravel
Development Environment After installing Laravel, you should configure your web server's document / web root to be the public directory. The index.php in this directory serves as the front controller for all HTTP requests entering your application.
Laravel and Composer ✔ Add/remove/update packages ✔ Dump autoload file and generate new one ✔ Update laravel version
Laravel Directory Structure ✔ The app directory, as you might expect, contains the core code of your application. ✔ The bootstrap directory contains files that bootstrap the framework and configure autoloading. ✔ The config directory, as the name implies, contains all of your application's configuration files ✔ The database directory contains your database migration and seeds. ✔ The public directory contains the index.php file. ✔ The resources directory contains your views as well as your raw, un-compiled assets such as views.
More Directories ✔ The routes directory contains all of the route definitions for your application. - The web.php file contains routes that the RouteServiceProvider places in the web middleware group, - The api.php file contains routes that the RouteServiceProvider places in the api middleware group, - The console.php file is where you may define all of your Closure based console commands. ✔ The storage directory contains your compiled Blade templates, file based sessions, file caches, and other files generated by the framework. ✔ The vendor directory contains your Composer dependencies.
Magic Artisan Command line tool for web artisans php artisan list Basically artisan is a php script which performs all actions in Laravel for example: ✔ Manage migrations ✔ Check application routes ✔ Clear app cache ✔ Create Artisan command ✔ Run database seeds
Laravel And Namespaces Laravel actively uses php namespaces to keep classnames short and keep possibility to use same class names for different components. I would suggest everyone to use namespaces too. For example all Admin functionality under Admin namespace.
Laravel Routes Route::get('foo', callback); Route::get('/welcome/{name?}', function($name = null){ return 'Name comes from paramatere >> '.$name; })->where('name', '[A-Za-z]+'); Route::group(['prefix' => 'name'], function () { Route::get('/user/profile', function () { return 'name with profile.'; }); });
Routing Helping Methods Route::current(); Route::currentRouteName(); Route::currentRouteAction();
Laravel Middlewares Before / After Middleware ✔ Middleware provide a convenient mechanism for filtering HTTP requests entering your application. ✔ php artisan make:middleware CheckAge ✔ Location of create middleware app/Http/Middleware ✔ If you want a middleware to run during every HTTP request to your application, simply list the middleware class in the $middleware property of your app/Http/Kernel.php class.
Laravel Controllers php artisan make:controller newController –resource There’s one main Controller class which all controllers should extend. By default Laravel has BaseController (extends from Controller) and HomeController (extends from BaseController) class UserController extends Controller{ public function __construct(){ $this->middleware('auth'); } }
Talking About Views ✔ All views are located in app/views directory ✔ Can be separated in subdirectories ✔ Can be both blade or simple php files ✔ It is recommended to use balde template engine since it is very convenient and helps to eliminate random logic blocks in views ✔ View::make(‘user.profile’, $data)
Insights In Blade Comments {{-- Comment visible only in blade file --}} Loops: @forelse($users as $user) <li>{{ $user->name }}</li> @empty <p>No users</p> @endforelse Conditions: @unless (Auth::check()) // similar to if(!) You are not signed in. @endunless
Models ✔ Models are located under app/ directory. ✔ php artisan make:model Userkelltontech. ✔ Table convention is "snake cased" flights for Flight Model. ✔ Protect mass update protected $fillable = ['name'];/ guarded ✔ AppFlight::findOrFail(1); ✔ FindOrFail(1); ✔ Flight::popular()->women()->orderBy('created_at')->get(); Enable soft Delete ✔ Add deleted_at ✔ use IlluminateDatabaseEloquentSoftDeletes; ✔ Use trait SoftDeletes;
Laravel Migrations ✔ php artisan make:migration create_users_table –create=flights ✔ Each migration has two functions up and down to migrate and rollback $table->increments('id'); $table->string('name', 255); $table->string('email', 255); $table->integer('nerd_level'); $table->timestamps();
Useful General Modules ✔ Queue ✔ Events File ✔ Storage ✔ Laravel Notifications provide a simple, expressive API for sending notifications across a variety of delivery channels such as email, Slack, SMS
Request Lifecycle ✔ The entry point for all requests to a Laravel application is the public/index.php file ✔ Index.php loads Composer generated autoloader definition then retreives instance of bootstrap/app.php script. ✔ The incoming request is sent to kernel (HTTP/console) which contains bootstrappers (These bootstrappers configure error handling, configure logging, detect the application environment). It contains all middlewares as well. ✔ One of the most important Kernel bootstrapping actions is loading the service providers for your application.
Thanks By Swapnil Tripathi

Laravel 5.3 - Web Development Php framework

  • 1.
  • 2.
    What's Laravel ? THEPHP FRAMEWORK FOR WEB ARTISANS. PHP THAT DOESN'T HURT. CODE HAPPY & ENJOY THE FRESH AIR.
  • 3.
    Where To StartFrom? Laravel is very flexible framwork. There are at least 3 options how to create new project: ✔ via laravel installer ✔ via composer ✔ clone from github
  • 4.
    Via Laravel Installer? Thiswill download laravel installer via composer composer global require "laravel/installer" This simple command will create app laravel new blog
  • 5.
    Other Options Via composer composercreate-project --prefer-dist laravel/laravel blog Get From github https://github.com/laravel/laravel
  • 6.
    Development Environment After installingLaravel, you should configure your web server's document / web root to be the public directory. The index.php in this directory serves as the front controller for all HTTP requests entering your application.
  • 7.
    Laravel and Composer ✔Add/remove/update packages ✔ Dump autoload file and generate new one ✔ Update laravel version
  • 8.
    Laravel Directory Structure ✔The app directory, as you might expect, contains the core code of your application. ✔ The bootstrap directory contains files that bootstrap the framework and configure autoloading. ✔ The config directory, as the name implies, contains all of your application's configuration files ✔ The database directory contains your database migration and seeds. ✔ The public directory contains the index.php file. ✔ The resources directory contains your views as well as your raw, un-compiled assets such as views.
  • 9.
    More Directories ✔ Theroutes directory contains all of the route definitions for your application. - The web.php file contains routes that the RouteServiceProvider places in the web middleware group, - The api.php file contains routes that the RouteServiceProvider places in the api middleware group, - The console.php file is where you may define all of your Closure based console commands. ✔ The storage directory contains your compiled Blade templates, file based sessions, file caches, and other files generated by the framework. ✔ The vendor directory contains your Composer dependencies.
  • 10.
    Magic Artisan Command linetool for web artisans php artisan list Basically artisan is a php script which performs all actions in Laravel for example: ✔ Manage migrations ✔ Check application routes ✔ Clear app cache ✔ Create Artisan command ✔ Run database seeds
  • 11.
    Laravel And Namespaces Laravelactively uses php namespaces to keep classnames short and keep possibility to use same class names for different components. I would suggest everyone to use namespaces too. For example all Admin functionality under Admin namespace.
  • 12.
    Laravel Routes Route::get('foo', callback); Route::get('/welcome/{name?}',function($name = null){ return 'Name comes from paramatere >> '.$name; })->where('name', '[A-Za-z]+'); Route::group(['prefix' => 'name'], function () { Route::get('/user/profile', function () { return 'name with profile.'; }); });
  • 13.
  • 14.
    Laravel Middlewares Before /After Middleware ✔ Middleware provide a convenient mechanism for filtering HTTP requests entering your application. ✔ php artisan make:middleware CheckAge ✔ Location of create middleware app/Http/Middleware ✔ If you want a middleware to run during every HTTP request to your application, simply list the middleware class in the $middleware property of your app/Http/Kernel.php class.
  • 15.
    Laravel Controllers php artisanmake:controller newController –resource There’s one main Controller class which all controllers should extend. By default Laravel has BaseController (extends from Controller) and HomeController (extends from BaseController) class UserController extends Controller{ public function __construct(){ $this->middleware('auth'); } }
  • 16.
    Talking About Views ✔All views are located in app/views directory ✔ Can be separated in subdirectories ✔ Can be both blade or simple php files ✔ It is recommended to use balde template engine since it is very convenient and helps to eliminate random logic blocks in views ✔ View::make(‘user.profile’, $data)
  • 17.
    Insights In Blade Comments {{--Comment visible only in blade file --}} Loops: @forelse($users as $user) <li>{{ $user->name }}</li> @empty <p>No users</p> @endforelse Conditions: @unless (Auth::check()) // similar to if(!) You are not signed in. @endunless
  • 18.
    Models ✔ Models arelocated under app/ directory. ✔ php artisan make:model Userkelltontech. ✔ Table convention is "snake cased" flights for Flight Model. ✔ Protect mass update protected $fillable = ['name'];/ guarded ✔ AppFlight::findOrFail(1); ✔ FindOrFail(1); ✔ Flight::popular()->women()->orderBy('created_at')->get(); Enable soft Delete ✔ Add deleted_at ✔ use IlluminateDatabaseEloquentSoftDeletes; ✔ Use trait SoftDeletes;
  • 19.
    Laravel Migrations ✔ phpartisan make:migration create_users_table –create=flights ✔ Each migration has two functions up and down to migrate and rollback $table->increments('id'); $table->string('name', 255); $table->string('email', 255); $table->integer('nerd_level'); $table->timestamps();
  • 20.
    Useful General Modules ✔Queue ✔ Events File ✔ Storage ✔ Laravel Notifications provide a simple, expressive API for sending notifications across a variety of delivery channels such as email, Slack, SMS
  • 21.
    Request Lifecycle ✔ Theentry point for all requests to a Laravel application is the public/index.php file ✔ Index.php loads Composer generated autoloader definition then retreives instance of bootstrap/app.php script. ✔ The incoming request is sent to kernel (HTTP/console) which contains bootstrappers (These bootstrappers configure error handling, configure logging, detect the application environment). It contains all middlewares as well. ✔ One of the most important Kernel bootstrapping actions is loading the service providers for your application.
  • 22.