SlideShare a Scribd company logo
LARAVEL 5
Introduction and Essential Training
By Pramod Kadam.
● Software Developer - 4.5 + Years experience.
● Sr. Software Developer at Ansh Systems Pvt. Ltd.
● Working technologies - PHP, Laravel5,
AngularJs, MySQL, Web services so on..
● Software Developer at Weblogicx
(weblogicx.com).
● LinkedIn : @pramodvkadam.
● Github : pramodvkadam.
● Stackoverflow : @statckoverflow
About Me
What and why Laravel?
● “Full stack” PHP framework for Web Artisans.
● Build on top of Symfony2 components.
● Most popular PHP framework 2013,2014,2015
and now.
● Easy configuration using php “dotenv”.
● Easy installation using composer.
System Requirement
● PHP >= 5.5.9
● OpenSSL PHP Extension
● PDO PHP Extension
● Mbstring PHP Extension
● Tokenizer PHP Extension
● Composer (Tool)
Installation
● Installing Laravel with the Laravel installer tool
○ For install laravel installer need following command
composer global require "laravel/installer=~1.1"
○ Once Laravel installer tool installed use following command
for create new project
laravel new projectName
●● Installing Laravel with Composer’s create-project
feature
○ If you don't want to install Laravel install tool use following
composer command for create project
○composer create-project laravel/laravel projectName --
prefer-dist
Laravel directory structure
● app
● bootstrap
● config
● database
● public
● resources
● storage
● tests
● vendor
● .env
● .env.example
● .gitattributes
● .gitignore
● artisan
● composer.json
● composer.lock
● gulpfile.js
● package.json
● phpspec.yml
● phpunit.xml
● readme.md
● server.php
Routing
● Laravel’s routes are defined in app/Http/routes.php
● The simplest route definition matches a URI (e.g. / ) with a
Closure:
Route::get('/', function () {
return 'Hello, World!';
});
● Routes with static html pages :
Route::get('/', function () {
return view('welcome');
});
Route::get('about', function () {
return view('about');
});
a.
Restful routes
Route::get('/', function () {
return 'Hello, World!';
});
Route::post('/', function () {});
Route::put('/', function () {});
Route::delete('/', function () {});
Route::any('/', function () {});
Route::match(['get', 'post'], '/', function () {});
Parameterised routes
● Strict parameters :
Route::get('users/{id}/friends', function ($id) {
// logic
});
● Optional parameters :
Route::get('users/{id?}', function ($id = 'fallbackId')
// logic
});
● Parameters with regular expression :
Route::get('users/{id}', function ($id) {
//
})->where('id', '[0-9]+');
Route::get('users/{username}', function ($username) {
//
})->where('username', '[A-Za-z]+');
Route Groups
● Route group middleware
Route::group(['middleware' => 'auth'], function () {
Route::get('dashboard', function () {
return view('dashboard');
});
Route::get('account', function () {
return view('account');
});
});
● Route group route prefix
Route::group(['prefix' => 'api'], function () {
Route::get('/', function () {
//
});
Route::get('users', function () {
//
});
});
1.
Views
● Static view
Route::get('/', function () {
return view('home');
return View::make('home');
});
Html page found in resources/views/home.blade.php
● Passing variables to views
Route::get('tasks', function () {
$tasks = array(1,2,3 ...);
return view('tasks.index',compact(‘tasks’));
// ->with('tasks', $tasks);
});
Controllers
● Laravel provides Artisan command for creating controller (you
can create manually also):
○ php artisan make:controller NewsController
● This will create a new file named NewsController.php in
app/Http/Controllers
● Following code will generate default
namespace AppHttpControllers;
use IlluminateHttpRequest;
use AppHttpRequests;
use AppHttpControllersController;
class NewsController extends Controller
{
// methods
}
Bind route with controller
● Route for the simplest controller
Route::get('/','NewsController@home');
● Simplest controller example
namespace AppHttpControllers;
use AppHttpControllersController;
class NewsController extends Controller
{
public function home()
{
return 'Hello, World!';
}
}
Getting user input in controller
● Binding basic form actions
// app/Http/routes.php
Route::get('new/create', 'NewsController@create');
Route::post('new', 'NewsController@store');
● Common form input controller method
// NewsController.php
...
public function store()
{
$news = new News;
$news->title = Input::get('title');
$news->description = Input::get('description');
$news->save();
return redirect('news');
}
● Injected Dependencies into Controllers
− // NewsController.php
− ...
− public function store(IlluminateHttpRequest
$request)
− {
● $news = new News;
● $news->title = $request->input('title');
● $news->description = $request-
>input('description');
● $news->save();
● return redirect('news');
− }
Resource controllers
● Resource controller binding
// app/Http/routes.php
Route::resource('news', 'NewsController')
● The methods of Laravel’s resource controllers
Form method spoofing & CSRF
● Form method spoofing
<form action="/tasks/5" method="POST">
<input type="hidden" name="_method" value="PUT/DELETE">
</form>
● CSRF protection
<form action="/tasks/5" method="POST">
<input type="hidden" name="_method" value="DELETE/PUT">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
</form>
● Handle csrf with ajax/jquery
● Storing the CSRF token in a meta tag
<meta name="csrf-token" content="{{ csrf_token() }}">
● Globally binding a jQuery header for CSRF
$.ajaxSetup({
● headers: {
● 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
● }
});
Redirects
● Three ways to return a redirect
Route::get('redirect-with-facade', function () {
return Redirect::to('auth/login');
});
Route::get('redirect-with-helper', function () {
return redirect()->to('auth/login');
});
Route::get('redirect-with-helper-shortcut', function () {
return redirect('auth/login');
});
Blade Templating
● PHP Code in html :
<?php if (empty($users)): ?>
No users.
<?php else: ?>
<?php foreach ($users as $user): ?>
<?= $user->first_name ?> <?= $user->last_name ?><br>
<?php endforeach; ?>
<?php endif; ?>
● {{-- Blade --}}
@forelse ($users as $user)
{{ $user->first_name }} {{ $user->last_name }}<br>
@empty
No users.
@endforelse
Control structures in Blade
● Conditionals
○ @if
Blade’s @if ($condition) compiles to <?php if ($condition): ?>. @else, @elseif,
and @endif also compile to the exact same syntax in PHP.
○ Example :
@if (count($talks) === 1)
There is one talk at this time period.
@elseif (count($talks) === 0)
There are no talks at this time period.
@else
There are {{ count($talks) }} talks at this time
period.
@endif
○ @unless and @endunless
@unless ($user->hasPaid())
You can complete your payment by switching to the payment tab.
@endunless
Control structures in Blade
● Loops
○ @for example:
@for ($i = 0; $i < $talk->slotsCount(); $i++)
The number is {{ $i }}
@endfor
○ @foreach example:
@foreach ($talks as $talk)
{{ $talk->title }} ({{ $talk->length }} minutes) @endforeach
○ @while example:
@while ($item = array_pop($items)) {{
$item->orSomething() }}<br>
@endwhile
○ @forelse example
@forelse ($talks as $talk)
{{ $talk->title }} ({{ $talk->length }} minutes)
@empty No talks this day
@endforelse
○ Or
{{ $name or ‘Defaut’ }}
Template inheritance in Blade
● Defining sections with @section/@show and @yield
<!-- resources/views/layouts/master.blade.php →
<html>
<head>
<title>My Site | @yield('title', 'Home
Page')</title>
</head>
<body>
<div class="container">
@yield('content')
</div>
@section('footerScripts')
<script src="app.js">
@show
</body>
Template inheritance in Blade
● Extending a Blade Layout
<!-- resources/views/dashboard.blade.php →
@extends('layouts.master')
@section('title', 'Dashboard')
@section('content')
Welcome to your application dashboard!
@endsection
@section('footerScripts')
@parent
<script src="dashboard.js">
@endsection
Database Migrations
●Generating Migrations
○ For create new table in database following artisan command use :
■ php artisan make:migration create_users_table --create=users
○ For update table schema use following command :
■ php artisan make:migration add_votes_to_users_table --table=users
●Migration Structure
public function up()
{ // create table schema
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('city');
$table->timestamps();
});
}
public function down()
{ // drop table
Schema::drop('users');
}
Database Migrations
●Running Migrations
○ For run migrations use following artisan command:
php artisan migrate
■ Note : to run migrations in production mode use “--force” option
●Rolling Back Migrations
○ For rollback migration to last migration use following artisan command
■ php artisan migrate:rollback
○ For reset all migrations use following artisan command
■ php artisan migrate:reset
Database Seeders
●Writing Seeders
○ For generate seeder use following artisan command
■ php artisan make:seeder UsersTableSeeder
class DatabaseSeeder extends Seeder
{
public function run()
{
DB::table('users')->insert([
'name' => str_random(10),
'email' => str_random(10).'@gmail.com',
'password' => bcrypt('secret'),
]);
}
}
●For run seeder use following command :
○ php artisan db:seed
○ php artisan db:seed --class=UsersTableSeeder
Eloquent ORM
● For model use as eloquent model should extends
IlluminateDatabaseEloquentModel class
● For instantly create eloquent model use following Artisan
command :
○ php artisan make:model User
● If you would like to generate a database migration when you
generate the model, you may use the --migration or -m option:
○ php artisan make:model User --migration
○ php artisan make:model User -m
Eloquent ORM
● Above command create following skeleton model:
<?php
namespace App;
use IlluminateDatabaseEloquentModel;
class User extends Model
{
//
}
Eloquent ORM Properties
● Table Names :
○ By default eloquent use model name as table name e.g:
User model use “users” table.
○ We can specify custom table name by $table protected
property to model e.g. protected $table = 'my_users';
● Primary Keys :
○ Eloquent defaultly use ‘id’ column as primary key with
autoincrement value.
○ We specify custom primary key and set autoincrement
false and non-integer as following:
protected $primaryKey = ‘guid’;
public $incrementing = false;
Eloquent ORM Properties
● Timestamps :
○ By default, Eloquent expects created_at and updated_at
columns to exist on your tables. If you do not wish to have
these columns automatically managed by Eloquent, set the
$timestamps property on your model to false:
public $timestamps = false;
○ And we can specify custom date format for timestamp :
protected $dateFormat = 'U';
● Database Connection :
○ By default, all Eloquent models will use the default
database connection configured for your application. If you
would like to specify a different connection for the model,
use the $connection property:
protected $connection = 'connection-name';
THANK YOU
References
○ Laravel - Laravel - The PHP Framework
For Web Artisans.
○ Composer - Composer.

More Related Content

What's hot (20)

Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5
Elena Kolevska
 
Adventures in Laravel 5 SunshinePHP 2016 Tutorial
Adventures in Laravel 5 SunshinePHP 2016 TutorialAdventures in Laravel 5 SunshinePHP 2016 Tutorial
Adventures in Laravel 5 SunshinePHP 2016 Tutorial
Joe Ferguson
 
Javascript laravel's friend
Javascript laravel's friendJavascript laravel's friend
Javascript laravel's friend
Bart Van Den Brande
 
Laravel 5
Laravel 5Laravel 5
Laravel 5
Sudip Simkhada
 
Laravel Design Patterns
Laravel Design PatternsLaravel Design Patterns
Laravel Design Patterns
Bobby Bouwmann
 
Kyiv.py #17 Flask talk
Kyiv.py #17 Flask talkKyiv.py #17 Flask talk
Kyiv.py #17 Flask talk
Alexey Popravka
 
Flask – Python
Flask – PythonFlask – Python
Flask – Python
Max Claus Nunes
 
REST APIs in Laravel 101
REST APIs in Laravel 101REST APIs in Laravel 101
REST APIs in Laravel 101
Samantha Geitz
 
RESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher PecoraroRESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher Pecoraro
Christopher Pecoraro
 
Intro to Laravel
Intro to LaravelIntro to Laravel
Intro to Laravel
Azukisoft Pte Ltd
 
Learn flask in 90mins
Learn flask in 90minsLearn flask in 90mins
Learn flask in 90mins
Larry Cai
 
LvivPy - Flask in details
LvivPy - Flask in detailsLvivPy - Flask in details
LvivPy - Flask in details
Max Klymyshyn
 
Flask patterns
Flask patternsFlask patterns
Flask patterns
it-people
 
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
Edureka!
 
Laravel.IO A Use-Case Architecture
Laravel.IO A Use-Case ArchitectureLaravel.IO A Use-Case Architecture
Laravel.IO A Use-Case Architecture
Shawn McCool
 
Getting Started-with-Laravel
Getting Started-with-LaravelGetting Started-with-Laravel
Getting Started-with-Laravel
Mindfire Solutions
 
Top laravel packages to install handpicked list from expert
Top laravel packages to install handpicked list from expertTop laravel packages to install handpicked list from expert
Top laravel packages to install handpicked list from expert
Katy Slemon
 
Flask
FlaskFlask
Flask
Mamta Kumari
 
Flask Basics
Flask BasicsFlask Basics
Flask Basics
Eueung Mulyana
 
Web service with Laravel
Web service with LaravelWeb service with Laravel
Web service with Laravel
Abuzer Firdousi
 
Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5
Elena Kolevska
 
Adventures in Laravel 5 SunshinePHP 2016 Tutorial
Adventures in Laravel 5 SunshinePHP 2016 TutorialAdventures in Laravel 5 SunshinePHP 2016 Tutorial
Adventures in Laravel 5 SunshinePHP 2016 Tutorial
Joe Ferguson
 
Laravel Design Patterns
Laravel Design PatternsLaravel Design Patterns
Laravel Design Patterns
Bobby Bouwmann
 
REST APIs in Laravel 101
REST APIs in Laravel 101REST APIs in Laravel 101
REST APIs in Laravel 101
Samantha Geitz
 
RESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher PecoraroRESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher Pecoraro
Christopher Pecoraro
 
Learn flask in 90mins
Learn flask in 90minsLearn flask in 90mins
Learn flask in 90mins
Larry Cai
 
LvivPy - Flask in details
LvivPy - Flask in detailsLvivPy - Flask in details
LvivPy - Flask in details
Max Klymyshyn
 
Flask patterns
Flask patternsFlask patterns
Flask patterns
it-people
 
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
Edureka!
 
Laravel.IO A Use-Case Architecture
Laravel.IO A Use-Case ArchitectureLaravel.IO A Use-Case Architecture
Laravel.IO A Use-Case Architecture
Shawn McCool
 
Top laravel packages to install handpicked list from expert
Top laravel packages to install handpicked list from expertTop laravel packages to install handpicked list from expert
Top laravel packages to install handpicked list from expert
Katy Slemon
 
Web service with Laravel
Web service with LaravelWeb service with Laravel
Web service with Laravel
Abuzer Firdousi
 

Viewers also liked (6)

Why Laravel?
Why Laravel?Why Laravel?
Why Laravel?
Jonathan Goode
 
Laravel Introduction
Laravel IntroductionLaravel Introduction
Laravel Introduction
Ahmad Shah Hafizan Hamidin
 
Laravel introduction
Laravel introductionLaravel introduction
Laravel introduction
Simon Funk
 
Laravel and Django and Rails, Oh My!
Laravel and Django and Rails, Oh My!Laravel and Django and Rails, Oh My!
Laravel and Django and Rails, Oh My!
Chris Roberts
 
Knowing Laravel 5 : The most popular PHP framework
Knowing Laravel 5 : The most popular PHP frameworkKnowing Laravel 5 : The most popular PHP framework
Knowing Laravel 5 : The most popular PHP framework
Bukhori Aqid
 
Laravel 5
Laravel 5Laravel 5
Laravel 5
Brian Feaver
 
Laravel introduction
Laravel introductionLaravel introduction
Laravel introduction
Simon Funk
 
Laravel and Django and Rails, Oh My!
Laravel and Django and Rails, Oh My!Laravel and Django and Rails, Oh My!
Laravel and Django and Rails, Oh My!
Chris Roberts
 
Knowing Laravel 5 : The most popular PHP framework
Knowing Laravel 5 : The most popular PHP frameworkKnowing Laravel 5 : The most popular PHP framework
Knowing Laravel 5 : The most popular PHP framework
Bukhori Aqid
 
Ad

Similar to Laravel5 Introduction and essentials (20)

PerlDancer for Perlers (FOSDEM 2011)
PerlDancer for Perlers (FOSDEM 2011)PerlDancer for Perlers (FOSDEM 2011)
PerlDancer for Perlers (FOSDEM 2011)
xSawyer
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
Hisateru Tanaka
 
Drupal 8 migrate!
Drupal 8 migrate!Drupal 8 migrate!
Drupal 8 migrate!
Pavel Makhrinsky
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
Darren Craig
 
How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js framework
Ben Lin
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
Alex Su
 
RESTful web services
RESTful web servicesRESTful web services
RESTful web services
Tudor Constantin
 
Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics
Eliran Eliassy
 
Introduction to angular js
Introduction to angular jsIntroduction to angular js
Introduction to angular js
Marco Vito Moscaritolo
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
diego_k
 
Curscatalyst
CurscatalystCurscatalyst
Curscatalyst
Kar Juan
 
nodejs tutorial foor free download from academia
nodejs tutorial foor free download from academianodejs tutorial foor free download from academia
nodejs tutorial foor free download from academia
rani marri
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php Presentation
Alan Pinstein
 
symfony on action - WebTech 207
symfony on action - WebTech 207symfony on action - WebTech 207
symfony on action - WebTech 207
patter
 
SF Grails - Ratpack - Compact Groovy Webapps - James Williams
SF Grails - Ratpack - Compact Groovy Webapps - James WilliamsSF Grails - Ratpack - Compact Groovy Webapps - James Williams
SF Grails - Ratpack - Compact Groovy Webapps - James Williams
Philip Stehlik
 
Laravel Routing and Query Building
Laravel   Routing and Query BuildingLaravel   Routing and Query Building
Laravel Routing and Query Building
Mindfire Solutions
 
Mojolicious - A new hope
Mojolicious - A new hopeMojolicious - A new hope
Mojolicious - A new hope
Marcus Ramberg
 
Using the new WordPress REST API
Using the new WordPress REST APIUsing the new WordPress REST API
Using the new WordPress REST API
Caldera Labs
 
Lviv 2013 d7 vs d8
Lviv 2013   d7 vs d8Lviv 2013   d7 vs d8
Lviv 2013 d7 vs d8
Andy Postnikov
 
Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендера
Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендераAndy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендера
Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендера
LEDC 2016
 
PerlDancer for Perlers (FOSDEM 2011)
PerlDancer for Perlers (FOSDEM 2011)PerlDancer for Perlers (FOSDEM 2011)
PerlDancer for Perlers (FOSDEM 2011)
xSawyer
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
Hisateru Tanaka
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
Darren Craig
 
How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js framework
Ben Lin
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
Alex Su
 
Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics
Eliran Eliassy
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
diego_k
 
Curscatalyst
CurscatalystCurscatalyst
Curscatalyst
Kar Juan
 
nodejs tutorial foor free download from academia
nodejs tutorial foor free download from academianodejs tutorial foor free download from academia
nodejs tutorial foor free download from academia
rani marri
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php Presentation
Alan Pinstein
 
symfony on action - WebTech 207
symfony on action - WebTech 207symfony on action - WebTech 207
symfony on action - WebTech 207
patter
 
SF Grails - Ratpack - Compact Groovy Webapps - James Williams
SF Grails - Ratpack - Compact Groovy Webapps - James WilliamsSF Grails - Ratpack - Compact Groovy Webapps - James Williams
SF Grails - Ratpack - Compact Groovy Webapps - James Williams
Philip Stehlik
 
Laravel Routing and Query Building
Laravel   Routing and Query BuildingLaravel   Routing and Query Building
Laravel Routing and Query Building
Mindfire Solutions
 
Mojolicious - A new hope
Mojolicious - A new hopeMojolicious - A new hope
Mojolicious - A new hope
Marcus Ramberg
 
Using the new WordPress REST API
Using the new WordPress REST APIUsing the new WordPress REST API
Using the new WordPress REST API
Caldera Labs
 
Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендера
Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендераAndy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендера
Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендера
LEDC 2016
 
Ad

Recently uploaded (20)

Top 10 Mobile Banking Apps in the USA.pdf
Top 10 Mobile Banking Apps in the USA.pdfTop 10 Mobile Banking Apps in the USA.pdf
Top 10 Mobile Banking Apps in the USA.pdf
LL Technolab
 
How John started to like TDD (instead of hating it) (ViennaJUG, June'25)
How John started to like TDD (instead of hating it) (ViennaJUG, June'25)How John started to like TDD (instead of hating it) (ViennaJUG, June'25)
How John started to like TDD (instead of hating it) (ViennaJUG, June'25)
Nacho Cougil
 
Shortcomings of EHS Software – And How to Overcome Them
Shortcomings of EHS Software – And How to Overcome ThemShortcomings of EHS Software – And How to Overcome Them
Shortcomings of EHS Software – And How to Overcome Them
TECH EHS Solution
 
Micro-Metrics Every Performance Engineer Should Validate Before Sign-Off
Micro-Metrics Every Performance Engineer Should Validate Before Sign-OffMicro-Metrics Every Performance Engineer Should Validate Before Sign-Off
Micro-Metrics Every Performance Engineer Should Validate Before Sign-Off
Tier1 app
 
Autoposting.ai Sales Deck - Skyrocket your LinkedIn's ROI
Autoposting.ai Sales Deck - Skyrocket your LinkedIn's ROIAutoposting.ai Sales Deck - Skyrocket your LinkedIn's ROI
Autoposting.ai Sales Deck - Skyrocket your LinkedIn's ROI
Udit Goenka
 
Secure and Simplify IT Management with ManageEngine Endpoint Central.pdf
Secure and Simplify IT Management with ManageEngine Endpoint Central.pdfSecure and Simplify IT Management with ManageEngine Endpoint Central.pdf
Secure and Simplify IT Management with ManageEngine Endpoint Central.pdf
Northwind Technologies
 
Issues in AI Presentation and machine learning.pptx
Issues in AI Presentation and machine learning.pptxIssues in AI Presentation and machine learning.pptx
Issues in AI Presentation and machine learning.pptx
Jalalkhan657136
 
Internship in South western railways on software
Internship in South western railways on softwareInternship in South western railways on software
Internship in South western railways on software
abhim5889
 
Why Indonesia’s $12.63B Alt-Lending Boom Needs Loan Servicing Automation & Re...
Why Indonesia’s $12.63B Alt-Lending Boom Needs Loan Servicing Automation & Re...Why Indonesia’s $12.63B Alt-Lending Boom Needs Loan Servicing Automation & Re...
Why Indonesia’s $12.63B Alt-Lending Boom Needs Loan Servicing Automation & Re...
Prachi Desai
 
Content Mate Web App Triples Content Managers‘ Productivity
Content Mate Web App Triples Content Managers‘ ProductivityContent Mate Web App Triples Content Managers‘ Productivity
Content Mate Web App Triples Content Managers‘ Productivity
Alex Vladimirovich
 
Boost Student Engagement with Smart Attendance Software for Schools
Boost Student Engagement with Smart Attendance Software for SchoolsBoost Student Engagement with Smart Attendance Software for Schools
Boost Student Engagement with Smart Attendance Software for Schools
Visitu
 
Oliveira2024 - Combining GPT and Weak Supervision.pdf
Oliveira2024 - Combining GPT and Weak Supervision.pdfOliveira2024 - Combining GPT and Weak Supervision.pdf
Oliveira2024 - Combining GPT and Weak Supervision.pdf
GiliardGodoi1
 
List Unfolding - 'unfold' as the Computational Dual of 'fold', and how 'unfol...
List Unfolding - 'unfold' as the Computational Dual of 'fold', and how 'unfol...List Unfolding - 'unfold' as the Computational Dual of 'fold', and how 'unfol...
List Unfolding - 'unfold' as the Computational Dual of 'fold', and how 'unfol...
Philip Schwarz
 
Rebuilding Cadabra Studio: AI as Our Core Foundation
Rebuilding Cadabra Studio: AI as Our Core FoundationRebuilding Cadabra Studio: AI as Our Core Foundation
Rebuilding Cadabra Studio: AI as Our Core Foundation
Cadabra Studio
 
iOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod KumariOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod Kumar
Pramod Kumar
 
Agentic AI Desgin Principles in five slides.pptx
Agentic AI Desgin Principles in five slides.pptxAgentic AI Desgin Principles in five slides.pptx
Agentic AI Desgin Principles in five slides.pptx
MOSIUOA WESI
 
How to Generate Financial Statements in QuickBooks Like a Pro (1).pdf
How to Generate Financial Statements in QuickBooks Like a Pro (1).pdfHow to Generate Financial Statements in QuickBooks Like a Pro (1).pdf
How to Generate Financial Statements in QuickBooks Like a Pro (1).pdf
QuickBooks Training
 
UberEats clone app Development TechBuilder
UberEats clone app Development  TechBuilderUberEats clone app Development  TechBuilder
UberEats clone app Development TechBuilder
TechBuilder
 
GirikHire Unlocking the Future of Tech Talent with AI-Powered Hiring Solution...
GirikHire Unlocking the Future of Tech Talent with AI-Powered Hiring Solution...GirikHire Unlocking the Future of Tech Talent with AI-Powered Hiring Solution...
GirikHire Unlocking the Future of Tech Talent with AI-Powered Hiring Solution...
GirikHire
 
grade 9 ai project cycle Artificial intelligence.pptx
grade 9 ai project cycle Artificial intelligence.pptxgrade 9 ai project cycle Artificial intelligence.pptx
grade 9 ai project cycle Artificial intelligence.pptx
manikumar465287
 
Top 10 Mobile Banking Apps in the USA.pdf
Top 10 Mobile Banking Apps in the USA.pdfTop 10 Mobile Banking Apps in the USA.pdf
Top 10 Mobile Banking Apps in the USA.pdf
LL Technolab
 
How John started to like TDD (instead of hating it) (ViennaJUG, June'25)
How John started to like TDD (instead of hating it) (ViennaJUG, June'25)How John started to like TDD (instead of hating it) (ViennaJUG, June'25)
How John started to like TDD (instead of hating it) (ViennaJUG, June'25)
Nacho Cougil
 
Shortcomings of EHS Software – And How to Overcome Them
Shortcomings of EHS Software – And How to Overcome ThemShortcomings of EHS Software – And How to Overcome Them
Shortcomings of EHS Software – And How to Overcome Them
TECH EHS Solution
 
Micro-Metrics Every Performance Engineer Should Validate Before Sign-Off
Micro-Metrics Every Performance Engineer Should Validate Before Sign-OffMicro-Metrics Every Performance Engineer Should Validate Before Sign-Off
Micro-Metrics Every Performance Engineer Should Validate Before Sign-Off
Tier1 app
 
Autoposting.ai Sales Deck - Skyrocket your LinkedIn's ROI
Autoposting.ai Sales Deck - Skyrocket your LinkedIn's ROIAutoposting.ai Sales Deck - Skyrocket your LinkedIn's ROI
Autoposting.ai Sales Deck - Skyrocket your LinkedIn's ROI
Udit Goenka
 
Secure and Simplify IT Management with ManageEngine Endpoint Central.pdf
Secure and Simplify IT Management with ManageEngine Endpoint Central.pdfSecure and Simplify IT Management with ManageEngine Endpoint Central.pdf
Secure and Simplify IT Management with ManageEngine Endpoint Central.pdf
Northwind Technologies
 
Issues in AI Presentation and machine learning.pptx
Issues in AI Presentation and machine learning.pptxIssues in AI Presentation and machine learning.pptx
Issues in AI Presentation and machine learning.pptx
Jalalkhan657136
 
Internship in South western railways on software
Internship in South western railways on softwareInternship in South western railways on software
Internship in South western railways on software
abhim5889
 
Why Indonesia’s $12.63B Alt-Lending Boom Needs Loan Servicing Automation & Re...
Why Indonesia’s $12.63B Alt-Lending Boom Needs Loan Servicing Automation & Re...Why Indonesia’s $12.63B Alt-Lending Boom Needs Loan Servicing Automation & Re...
Why Indonesia’s $12.63B Alt-Lending Boom Needs Loan Servicing Automation & Re...
Prachi Desai
 
Content Mate Web App Triples Content Managers‘ Productivity
Content Mate Web App Triples Content Managers‘ ProductivityContent Mate Web App Triples Content Managers‘ Productivity
Content Mate Web App Triples Content Managers‘ Productivity
Alex Vladimirovich
 
Boost Student Engagement with Smart Attendance Software for Schools
Boost Student Engagement with Smart Attendance Software for SchoolsBoost Student Engagement with Smart Attendance Software for Schools
Boost Student Engagement with Smart Attendance Software for Schools
Visitu
 
Oliveira2024 - Combining GPT and Weak Supervision.pdf
Oliveira2024 - Combining GPT and Weak Supervision.pdfOliveira2024 - Combining GPT and Weak Supervision.pdf
Oliveira2024 - Combining GPT and Weak Supervision.pdf
GiliardGodoi1
 
List Unfolding - 'unfold' as the Computational Dual of 'fold', and how 'unfol...
List Unfolding - 'unfold' as the Computational Dual of 'fold', and how 'unfol...List Unfolding - 'unfold' as the Computational Dual of 'fold', and how 'unfol...
List Unfolding - 'unfold' as the Computational Dual of 'fold', and how 'unfol...
Philip Schwarz
 
Rebuilding Cadabra Studio: AI as Our Core Foundation
Rebuilding Cadabra Studio: AI as Our Core FoundationRebuilding Cadabra Studio: AI as Our Core Foundation
Rebuilding Cadabra Studio: AI as Our Core Foundation
Cadabra Studio
 
iOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod KumariOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod Kumar
Pramod Kumar
 
Agentic AI Desgin Principles in five slides.pptx
Agentic AI Desgin Principles in five slides.pptxAgentic AI Desgin Principles in five slides.pptx
Agentic AI Desgin Principles in five slides.pptx
MOSIUOA WESI
 
How to Generate Financial Statements in QuickBooks Like a Pro (1).pdf
How to Generate Financial Statements in QuickBooks Like a Pro (1).pdfHow to Generate Financial Statements in QuickBooks Like a Pro (1).pdf
How to Generate Financial Statements in QuickBooks Like a Pro (1).pdf
QuickBooks Training
 
UberEats clone app Development TechBuilder
UberEats clone app Development  TechBuilderUberEats clone app Development  TechBuilder
UberEats clone app Development TechBuilder
TechBuilder
 
GirikHire Unlocking the Future of Tech Talent with AI-Powered Hiring Solution...
GirikHire Unlocking the Future of Tech Talent with AI-Powered Hiring Solution...GirikHire Unlocking the Future of Tech Talent with AI-Powered Hiring Solution...
GirikHire Unlocking the Future of Tech Talent with AI-Powered Hiring Solution...
GirikHire
 
grade 9 ai project cycle Artificial intelligence.pptx
grade 9 ai project cycle Artificial intelligence.pptxgrade 9 ai project cycle Artificial intelligence.pptx
grade 9 ai project cycle Artificial intelligence.pptx
manikumar465287
 

Laravel5 Introduction and essentials

  • 1. LARAVEL 5 Introduction and Essential Training By Pramod Kadam.
  • 2. ● Software Developer - 4.5 + Years experience. ● Sr. Software Developer at Ansh Systems Pvt. Ltd. ● Working technologies - PHP, Laravel5, AngularJs, MySQL, Web services so on.. ● Software Developer at Weblogicx (weblogicx.com). ● LinkedIn : @pramodvkadam. ● Github : pramodvkadam. ● Stackoverflow : @statckoverflow About Me
  • 3. What and why Laravel? ● “Full stack” PHP framework for Web Artisans. ● Build on top of Symfony2 components. ● Most popular PHP framework 2013,2014,2015 and now. ● Easy configuration using php “dotenv”. ● Easy installation using composer.
  • 4. System Requirement ● PHP >= 5.5.9 ● OpenSSL PHP Extension ● PDO PHP Extension ● Mbstring PHP Extension ● Tokenizer PHP Extension ● Composer (Tool)
  • 5. Installation ● Installing Laravel with the Laravel installer tool ○ For install laravel installer need following command composer global require "laravel/installer=~1.1" ○ Once Laravel installer tool installed use following command for create new project laravel new projectName ●● Installing Laravel with Composer’s create-project feature ○ If you don't want to install Laravel install tool use following composer command for create project ○composer create-project laravel/laravel projectName -- prefer-dist
  • 6. Laravel directory structure ● app ● bootstrap ● config ● database ● public ● resources ● storage ● tests ● vendor ● .env ● .env.example ● .gitattributes ● .gitignore ● artisan ● composer.json ● composer.lock ● gulpfile.js ● package.json ● phpspec.yml ● phpunit.xml ● readme.md ● server.php
  • 7. Routing ● Laravel’s routes are defined in app/Http/routes.php ● The simplest route definition matches a URI (e.g. / ) with a Closure: Route::get('/', function () { return 'Hello, World!'; }); ● Routes with static html pages : Route::get('/', function () { return view('welcome'); }); Route::get('about', function () { return view('about'); }); a.
  • 8. Restful routes Route::get('/', function () { return 'Hello, World!'; }); Route::post('/', function () {}); Route::put('/', function () {}); Route::delete('/', function () {}); Route::any('/', function () {}); Route::match(['get', 'post'], '/', function () {});
  • 9. Parameterised routes ● Strict parameters : Route::get('users/{id}/friends', function ($id) { // logic }); ● Optional parameters : Route::get('users/{id?}', function ($id = 'fallbackId') // logic }); ● Parameters with regular expression : Route::get('users/{id}', function ($id) { // })->where('id', '[0-9]+'); Route::get('users/{username}', function ($username) { // })->where('username', '[A-Za-z]+');
  • 10. Route Groups ● Route group middleware Route::group(['middleware' => 'auth'], function () { Route::get('dashboard', function () { return view('dashboard'); }); Route::get('account', function () { return view('account'); }); }); ● Route group route prefix Route::group(['prefix' => 'api'], function () { Route::get('/', function () { // }); Route::get('users', function () { // }); }); 1.
  • 11. Views ● Static view Route::get('/', function () { return view('home'); return View::make('home'); }); Html page found in resources/views/home.blade.php ● Passing variables to views Route::get('tasks', function () { $tasks = array(1,2,3 ...); return view('tasks.index',compact(‘tasks’)); // ->with('tasks', $tasks); });
  • 12. Controllers ● Laravel provides Artisan command for creating controller (you can create manually also): ○ php artisan make:controller NewsController ● This will create a new file named NewsController.php in app/Http/Controllers ● Following code will generate default namespace AppHttpControllers; use IlluminateHttpRequest; use AppHttpRequests; use AppHttpControllersController; class NewsController extends Controller { // methods }
  • 13. Bind route with controller ● Route for the simplest controller Route::get('/','NewsController@home'); ● Simplest controller example namespace AppHttpControllers; use AppHttpControllersController; class NewsController extends Controller { public function home() { return 'Hello, World!'; } }
  • 14. Getting user input in controller ● Binding basic form actions // app/Http/routes.php Route::get('new/create', 'NewsController@create'); Route::post('new', 'NewsController@store'); ● Common form input controller method // NewsController.php ... public function store() { $news = new News; $news->title = Input::get('title'); $news->description = Input::get('description'); $news->save(); return redirect('news'); }
  • 15. ● Injected Dependencies into Controllers − // NewsController.php − ... − public function store(IlluminateHttpRequest $request) − { ● $news = new News; ● $news->title = $request->input('title'); ● $news->description = $request- >input('description'); ● $news->save(); ● return redirect('news'); − }
  • 16. Resource controllers ● Resource controller binding // app/Http/routes.php Route::resource('news', 'NewsController') ● The methods of Laravel’s resource controllers
  • 17. Form method spoofing & CSRF ● Form method spoofing <form action="/tasks/5" method="POST"> <input type="hidden" name="_method" value="PUT/DELETE"> </form> ● CSRF protection <form action="/tasks/5" method="POST"> <input type="hidden" name="_method" value="DELETE/PUT"> <input type="hidden" name="_token" value="{{ csrf_token() }}"> </form> ● Handle csrf with ajax/jquery ● Storing the CSRF token in a meta tag <meta name="csrf-token" content="{{ csrf_token() }}"> ● Globally binding a jQuery header for CSRF $.ajaxSetup({ ● headers: { ● 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') ● } });
  • 18. Redirects ● Three ways to return a redirect Route::get('redirect-with-facade', function () { return Redirect::to('auth/login'); }); Route::get('redirect-with-helper', function () { return redirect()->to('auth/login'); }); Route::get('redirect-with-helper-shortcut', function () { return redirect('auth/login'); });
  • 19. Blade Templating ● PHP Code in html : <?php if (empty($users)): ?> No users. <?php else: ?> <?php foreach ($users as $user): ?> <?= $user->first_name ?> <?= $user->last_name ?><br> <?php endforeach; ?> <?php endif; ?> ● {{-- Blade --}} @forelse ($users as $user) {{ $user->first_name }} {{ $user->last_name }}<br> @empty No users. @endforelse
  • 20. Control structures in Blade ● Conditionals ○ @if Blade’s @if ($condition) compiles to <?php if ($condition): ?>. @else, @elseif, and @endif also compile to the exact same syntax in PHP. ○ Example : @if (count($talks) === 1) There is one talk at this time period. @elseif (count($talks) === 0) There are no talks at this time period. @else There are {{ count($talks) }} talks at this time period. @endif ○ @unless and @endunless @unless ($user->hasPaid()) You can complete your payment by switching to the payment tab. @endunless
  • 21. Control structures in Blade ● Loops ○ @for example: @for ($i = 0; $i < $talk->slotsCount(); $i++) The number is {{ $i }} @endfor ○ @foreach example: @foreach ($talks as $talk) {{ $talk->title }} ({{ $talk->length }} minutes) @endforeach ○ @while example: @while ($item = array_pop($items)) {{ $item->orSomething() }}<br> @endwhile ○ @forelse example @forelse ($talks as $talk) {{ $talk->title }} ({{ $talk->length }} minutes) @empty No talks this day @endforelse ○ Or {{ $name or ‘Defaut’ }}
  • 22. Template inheritance in Blade ● Defining sections with @section/@show and @yield <!-- resources/views/layouts/master.blade.php → <html> <head> <title>My Site | @yield('title', 'Home Page')</title> </head> <body> <div class="container"> @yield('content') </div> @section('footerScripts') <script src="app.js"> @show </body>
  • 23. Template inheritance in Blade ● Extending a Blade Layout <!-- resources/views/dashboard.blade.php → @extends('layouts.master') @section('title', 'Dashboard') @section('content') Welcome to your application dashboard! @endsection @section('footerScripts') @parent <script src="dashboard.js"> @endsection
  • 24. Database Migrations ●Generating Migrations ○ For create new table in database following artisan command use : ■ php artisan make:migration create_users_table --create=users ○ For update table schema use following command : ■ php artisan make:migration add_votes_to_users_table --table=users ●Migration Structure public function up() { // create table schema Schema::create('users', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->string('city'); $table->timestamps(); }); } public function down() { // drop table Schema::drop('users'); }
  • 25. Database Migrations ●Running Migrations ○ For run migrations use following artisan command: php artisan migrate ■ Note : to run migrations in production mode use “--force” option ●Rolling Back Migrations ○ For rollback migration to last migration use following artisan command ■ php artisan migrate:rollback ○ For reset all migrations use following artisan command ■ php artisan migrate:reset
  • 26. Database Seeders ●Writing Seeders ○ For generate seeder use following artisan command ■ php artisan make:seeder UsersTableSeeder class DatabaseSeeder extends Seeder { public function run() { DB::table('users')->insert([ 'name' => str_random(10), 'email' => str_random(10).'@gmail.com', 'password' => bcrypt('secret'), ]); } } ●For run seeder use following command : ○ php artisan db:seed ○ php artisan db:seed --class=UsersTableSeeder
  • 27. Eloquent ORM ● For model use as eloquent model should extends IlluminateDatabaseEloquentModel class ● For instantly create eloquent model use following Artisan command : ○ php artisan make:model User ● If you would like to generate a database migration when you generate the model, you may use the --migration or -m option: ○ php artisan make:model User --migration ○ php artisan make:model User -m
  • 28. Eloquent ORM ● Above command create following skeleton model: <?php namespace App; use IlluminateDatabaseEloquentModel; class User extends Model { // }
  • 29. Eloquent ORM Properties ● Table Names : ○ By default eloquent use model name as table name e.g: User model use “users” table. ○ We can specify custom table name by $table protected property to model e.g. protected $table = 'my_users'; ● Primary Keys : ○ Eloquent defaultly use ‘id’ column as primary key with autoincrement value. ○ We specify custom primary key and set autoincrement false and non-integer as following: protected $primaryKey = ‘guid’; public $incrementing = false;
  • 30. Eloquent ORM Properties ● Timestamps : ○ By default, Eloquent expects created_at and updated_at columns to exist on your tables. If you do not wish to have these columns automatically managed by Eloquent, set the $timestamps property on your model to false: public $timestamps = false; ○ And we can specify custom date format for timestamp : protected $dateFormat = 'U'; ● Database Connection : ○ By default, all Eloquent models will use the default database connection configured for your application. If you would like to specify a different connection for the model, use the $connection property: protected $connection = 'connection-name';
  • 31. THANK YOU References ○ Laravel - Laravel - The PHP Framework For Web Artisans. ○ Composer - Composer.