0% found this document useful (0 votes)
24 views

Laravel - Introduction

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Laravel - Introduction

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

Introdu

ction
to

“The PHP Framework For Web Artisans"


HISTORY BEHIND THE VISION

• Taylor Otwell, a .NET developer in Arkansas (USA), was using


an early version of Codeigniter when the idea for Laravel
came to him.
• “I couldn't add all the features I wanted to”, he says, "without
mangling the internal code of the framework”.
• He wanted something leaner, simpler, and more flexible.
HISTORY BEHIND THE VISION
• Those desires, coupled with Taylor's .NET background,
spawned the framework that would become Laravel.
• He used the ideas of the .NET infrastructure which Microsoft
had built and spent hundreds of millions of dollars of research
on.
• With Laravel, Taylor sought to create a framework that would be
known for its simplicity.
❑ He added to that simplicity by including an expressive syntax, clear
structure, and incredibly thorough documentation.
• With that, Laravel was born.
THE EVOLUTION OF LARAVEL
• Taylor started with a simple routing layer and a really simple
controller-type interface (MVC)
■ v1 and v2 were released in June 2011 and September 2011 respectively, just
months apart
• In February 2012, Laravel 3 was released just over a year later and
this is when Laravel's user base and popularity really began to
grow.
THE EVOLUTION OF LARAVEL
• In May 2013, Laravel 4 was released as a complete rewrite of
the framework and incorporated a package manager called
Composer.
• Composer is an application-level package manager for PHP
that allowed people to collaborate instead of compete.
• Before Composer, there was no way to take two separate
packages and use different pieces of those packages together
to create a single solution.
• Laravel is built on top of several packages most notably
Symfony.
MVC is a software architectural pattern commonly used for developing user
interface that divide the related
program logic into three interconnected elements.
What is Laravel?
• a PHP framework inspired by Ruby on Rails
• In the beginning Laravel name was Bootplant then turned
Laravel.
• Laravel name came from a castle which is Cair Paravel.
• The source code of Laravel is hosted on GitHub and licensed
under the terms of MIT License
• Uses Symfony packages
• Free open-source license with many contributors worldwide
• Uses MVC PHP Framework
Version Release date PHP version

1.0 June 2011

2.0 September 2011

3.0 February 22, 2012

3.1 March 27, 2012

3.2 May 22, 2012

4.0 May 28, 2013 ≥ 5.3.0

4.1 December 12, 2013 ≥ 5.3.0

4.2 June 1, 2014 ≥ 5.4.0

5.0 February 4, 2015 ≥ 5.4.0

5.1 LTS June 9, 2015 ≥ 5.5.9

5.2 December 21, 2015 ≥ 5.5.9

5.3 August 23, 2016 ≥ 5.6.4

5.4 January 24, 2017 ≥ 5.6.4

5.5 LTS August 30, 2017 ≥ 7.0.0

5.6 February 7, 2018 ≥ 7.1.3

5.7 September 4, 2018 ≥ 7.1.3

5.8 February 26, 2019 ≥ 7.1.3

6 LTS September 3, 2019 7.2 – 8.0

7 March 3, 2020 7.2 – 8.0

8 September 8, 2020 7.3 – 8.1

9 February 8, 2022 8.0 – 8.1

10 February 14, 2023 ≥ 8.1

11 Q1 2024 ≥ 8.2
LARAVEL TODAY
• Laravel now stands at version 10 with 11 currently in development
• Support for PHP 7 has recently been added to Laravel 7.3 - 8.1.
Server Requirements
• PHP >= 7.2.5
• BCMath PHP Extension
• Ctype PHP Extension
• Fileinfo PHP extension
• JSON PHP Extension
• Mbstring PHP Extension
• OpenSSL PHP Extension
• PDO PHP Extension
• Tokenizer PHP Extension
• XML PHP Extension

Laravel utilizes Composer to manage its dependencies. So, before using Laravel, make
sure you have Composer installed on your machine.
I. Download and install Composer
II. Open CMD and paste the syntax: composer global require laravel/installer
• Eloquent ORM (object-relational mapping) - implements Active-Record
• Query builder - helps you to build secured SQL queries
• Restful controllers - provides a way for separating the different HTTP requests (GET, POST,
DELETE, etc.)
• Blade template engine - combines templates with a data model to produce views
• Migrations - version control system for database, update your database easier
ARCHITECTURE
• Model
■ Everything database related - Eloquent ORM (Object Relational
Mapper)
• View
■ HTML structure - Blade templating engine
• Controller
■ Processing requests and generating output

+ Facades, Dependency Injection, Repositories, etc...


File Structure
• app/Http folder contains the Controllers, Middlewares and Kernel file
• All the models should be located in app/Models folder
• The service providers that are bootstrapping functions in our app are located in
app/Providers folder
• All the config files are located in app/config folder
• database folder contains the Migrations, Seeder, and Factory.
• The public folder is the actual folder you are opening on the web server. All JS
/ CSS / Images / Uploads are located there.
• The resources folder contains all the translations, views and assets (SASS,
LESS, JS) that are compiled into public folder.
• The routes folder contains all the routes for the project
• All the logs / cache files are located in storage folder
• The vendor folder contains all the composer packages (dependencies)
ROUTES
The route is a way of creating a request URL for your application.

Routes (/routes) hold the application URLs


■ web.php for web routes
■ api.php for stateless requests
■ console.php for Artisan commands

Route::get('/post/{post}', function () {
//
})->name('post.show’);

// Visiting '/' will return 'Hello World!'


Route::get('/', function(){
return 'Hello World!';
});
2. Route to appropriate Laravel Controller

Routing

5 Render view in users browser Database


CONTROLLERS
• Handle the logic required for processing
requests
• Controllers are stored in the
app/Http/Controllers directory

<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use App\User;

class UserController extends Controller


{
/**
* Show the profile for the given user.
*
* @param int $id
* @return View
*/
public function show($id)
{
return view('user.profile', ['user' => User::findOrFail($id)]);
}
}
MODELS
• Classes that are used to access the database

• Models typically live in the app directory, but you are free
to place them anywhere that can be auto-loaded
according to your composer.json file

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Flight extends Model


{
//
}
MIDDLE
WARE
• The middleware is mechanism for filtering the HTTP requests
• Laravel includes several middleware's - Authentication, CSRF
Protection
• The auth middleware checks if the user visiting the page is
authenticated through session cookie
• The CSRF (Cross-Site Request Forgery) token protection
middleware protects your application from cross-site
request forgery attacks by adding token key for each
generated form
ARTISAN
• Artisan is the command-line interface included with Laravel
• It provides a number of helpful commands that can assist you
while you build your application

php artisan list

php artisan vendor:publish --provider="Laravel\Tinker\TinkerServiceProvider“

php artisan make:command SendEmails


VIEWS
Blade is a simple, yet powerful templating engine provided with Laravel.
Unlike other popular PHP templating engines, Blade does not restrict you
from using plain PHP code in your views. In fact, all Blade views are
compiled into plain PHP code and cached until they are modified, meaning
Blade adds essentially zero overhead to your application. Blade view files
use the .blade.php file extension and are typically stored in the
resources/views directory.
Two of the primary benefits of using Blade are template
inheritance and sections.

• The @section directive, as the name implies, defines a section of


content, while the @yield directive is used to display the contents of a
given section.
<!-- Stored in resources/views/layouts/app.blade.php -->

<html>
<head>
<title>App Name - @yield('title')</title>
</head>
<body>
@section('sidebar’)
This is the master sidebar.
@show

<div class="container">
@yield('content’)
</div>
</body>
</html>
Extending a Layout
When defining a child view, use the Blade @extends directive to specify
which layout the child view should "inherit". Views which extend a Blade
layout may inject content into the layout's sections using @section
directives. Remember, as seen in the example above, the contents of these
sections will be displayed in the layout using @yield:
<!-- Stored in resources/views/child.blade.php -->

@extends('layouts.app')

@section('title', 'Page Title')

@section('sidebar’)
@@parent

<p>This is appended to the master sidebar.</p>


@endsection

@section('content’)
<p>This is my body content.</p>
@endsection
Questions?
Let’s Install and Try Laravel
• XAMPP with PHP version 7.3 - 8.0
• Composer
• Text Editor – VS Code (Recommended)
• Git SCM (Optional)

Syntax
After installing Laravel,
composer global require laravel/installer

After installing Laravel,


composer create-project --prefer-dist laravel/laravel:^7.0 blog

You might also like