Lab 6 (Laravel Intro)
Lab 6 (Laravel Intro)
13-Jan-24 2
Framework
Classes
Database
Config.
13-Jan-24 3
Web-Frameworks
• PHP web framework: Laravel
• C# based framework: ASP.NET Core
• Python web frameworks -> Django, Flask
• Java: Spring Boot
• Ruby: Ruby on Rails (Rails)
• TypeScript based: Angular by Google
• JavaScript based: React, Vue.js, Express.js
and So on…….
13-Jan-24 4
Laravel
• PHP based open source web-framework.
13-Jan-24 5
MVC Pattern
13-Jan-24 6
Why Laravel?
• MVC Support and Object-Oriented Approach • Eloquent ORM
• Built in Authentication and Authorization • Templating engine (Blade)
• Packaging System • Task Scheduling
• Multiple File System • Events and Broadcasting
• Artisan Console • Testing
13-Jan-24 7
Steps to follow
• Installation of PHP Local Server (i.e XAMPP)
13-Jan-24 8
Laravel Application Structure
13-Jan-24 9
Laravel’s App Directory
• Most of the code is
written in the app
folder.
• The App folder contains
the following sub-
folders:
Console
Exceptions
Http
Models
Providers
13-Jan-24 10
Laravel’s App Directory
• Console: This directory contains all the custom Artisan commands created using
make:command.
• Http: This directory contains all your controllers, middleware, views and requests.
• Models: This is a new directory added since Laravel 8 to hold Model files.
• Providers: This directory contains all your service providers for the application.
13-Jan-24 11
Other Directories
• Bootstrap: This directory contains framework bootstrap as well as
configuration files. It also contains Cache directory which contains
framework generated cache files. It also contains the file app.php that
initializes the scripts required for bootstrap.
13-Jan-24 12
Other Directories
• Storage: This directory contains blade templates, session files, cache
files and other.
13-Jan-24 13
Other Directories
• Public: This directory contains assets like images, js files and CSS. It
contains the front controllers used for initializing the Laravel web
application. (index.php)
• Resources: This directory contains all assets, view files and CSS or LESS
or SASS files. It also contains lang directory to store language files.
• Routes: This directory contains all routes definitions for the application.
php is the file which receives all the requests to your application and here
you can redirect the requests to their respective controller methods.
13-Jan-24 14
Routing in Laravel
• Basic routing is
meant to route
your request to an
appropriate
controller.
• app/Http/routes.php
13-Jan-24 15
Routing in Laravel
• app/Http/routes.php
13-Jan-24 16
Routing in Laravel
• You can also send and capture parameters passed with the URL.
13-Jan-24 18
Blade Templates
• Blade is a templating engine in a Laravel framework.
13-Jan-24 19
Displaying Data
Core PHP Syntax Blade Template Syntax
<?php {{ $name }}
echo $name;
?> {!! $name !!}
13-Jan-24 20
Blade Conditional Directives
• @if, @elseif, @else, and @endif.
• @unless, @endunless.
• @isset, @endisset
@if($name == "")
{{"Name is empty"}}
@elseif($name == "Saeed")
{{"Welcome Saeed"}}
@else
{{"Welcome Guest"}}
@endif
13-Jan-24 21
Blade Looping Directives
• @for and @endfor. @for ($i=1;$i<10;$i++)
13-Jan-24 22
Other Directives
• For Comments: {{-- Comments goes here --}}
13-Jan-24 23
Layout Blade Directives
• @yield directive is used to display the contents of a given section.
13-Jan-24 24
Layout Blade Directives
• To render the complete stack contents, pass the name of the stack
to the @stack directive
13-Jan-24 25
Laravel Controller
• Controller are class based php files.
• Controllers can group related request handling logic into a single
class.
• Brings OOP functionalities.
• Types of Controller:
1. Basic Controllers
2. Single Action Controllers
3. Resource Controllers (CRUD)
13-Jan-24 26
Controller Commands
• Basic Controller:
php artisan make:controller ControllerName
DemoController.php
<?php web.php
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Route;
use Illuminate\Http\Request;
use App\Http\Controllers\DemoController;
class DemoController extends Controller
{ Route::get('/', [DemoController::class, 'index']);
public function index(){
return view('home');
}
}
13-Jan-24 27
Controller Commands
• Single Action Controller:
php artisan make:controller ControllerName –invokable
• Resource Controller:
php artisan make:controller ControllerName –resource
13-Jan-24 28
References
• https://www.javatpoint.com/laravel
• https://www.tutorialspoint.com/laravel
• https://www.wscubetech.com/
13-Jan-24 29
Thank You!!!
13-Jan-24 30