SlideShare una empresa de Scribd logo
1 de 45
Laravel
The PHP Framework For Web Artisans
Presented by : Syeda Aimen Batool
Developer @ Swaam Tech
We will discuss:
• Laravel Features
• Composer and Laravel Setup
• Directory Structure
• Routing
• Controller & Model
• CRUD Examples
• Database Migrations
• User Authentication
• Controller to View Communication
• Basic Commands
• Databases (Basic Queries)
• Form Validation
• Blade Template Engine
Quick Guide On Laravel
www.swaam.com
Features
Laravel is an open source MVC PHP Framework under MIT license.
Bundles are packages which you can download to add particular
functionality in your web application to save coding and time.
Eloquent ORM provides a simple ActiveRecord implementation for
working with database.
Class Auto loading assures that correct components are loaded at
correct time.
Unit testing allows users to easily create and run unit tests to ensure
application stability.
Quick Guide On Laravel
www.swaam.com
Requirements
• Apache or any other compatible web server
• PHP Version should be 5.5.9 or greater
• PDO PHP Extension should be enabled
PDO is by default enable in php 5.1.0 or greater.
You can manually activate by uncommenting statement below in php.ini by removing semicolon at
beginning
extension=php_pdo.dll
• OpenSSL PHP Extension should be enabled
to manually activate OpenSSL extension uncomment the line extension=php_openssl.dll by removing
the semicolon at beginning
• okenizer PHP Extension should be enabled
This extension is by default enabled in php versions 4.3.0 or greater
Quick Guide On Laravel
MVC Layers
• Model (Eloquent ORM)
Model represents the logical structure of an application e.g. list of database record
• View (Blade Engine)
View displays the data user see on screen such as buttons, display boxes etc.
• Controller
Controller represents the classes connecting the view and model, it helps model and
view to communicate with each other
Quick Guide On Laravel
www.swaam.com
Composer and Laravel Setup:
• A dependencies management tool.
• Download Composer from here.
• Run setup.
• Browse php.exe file under xampp/php/php.exe.
• After successful installation; open your cmd.
open cmd
execute composer.phar to check if composer is successfully installed
• Download the Laravel installer by writing given command in cmd.
Composer global require “laravel/installer=~1.1”
• Create a new project by running following command in cmd.
Composer create-project laravel/laravel --prefer-dist
Installing…
Quick Guide On Laravel
www.swaam.com
Hello Laravel 
• After installation hit “http://localhost/laravel/public/” in your
browser
• Remove public from your url by following this:
– Go to D:xampphtdocslaravelpublic
– Cut index.php and .htaccess file and paste here: D:xampphtdocslaravel
– Open index.php and change bootstrap path:
../../bootstrap/ to ../bootstrap/ in whole file
– Now hit your url without public “http://localhost/laravel/”
– Congratulations ! You have successfully setup Laravel.
Quick Guide On Laravel
www.swaam.com
Directory Structure:
• Routes are available under app directory:
D:xamphtdocslaravelappHttproutes.php
• Controllers are available at:
D:xamphtdocslaravelappHttpController
• User Authentication is available at:
D:xamphtdocslaravelappHttpControllersAuth
• All your assets and views are available at:
D:xamphtdocslaravelresources
• Models are available at:
D:xamphtdocslaravelapp
Quick Guide On Laravel
www.swaam.com
My First Routes:
All routes are available at D:xamphtdocslaravelappHttproutes.php
• Default Route:
A root looks like => Route::get('/home', 'WelcomeController@index');
Where ‘/home’ is you will enter in url
'WelcomeController is your application controller
Index is a function in your controller
Hitting ‘/home’ in url will invoke your controller and call function index
– Route::get(‘Home', ‘HomeController@index');
– Route::post(‘application/create', ‘ApplicationController@create');
– Route::patch(‘application/update', ‘ApplicationController@update');
Quick Guide On Laravel
www.swaam.com
Named Routes:
• Giving a specific name to a route:
Route::get('songs',['as'=>'songs_path‘ , 'uses'=>'SongsController@index']);
where songs_path Is name specified to this particular route, we can use this name in our app instead of
writing route.
e.g. <a href="{{ route('songs_path')}}"> will be a hyperlink to this route.
• Just an other way:
$router -> get('songs',['as'=>'songs_path','uses'=>'SongsController@index']);
We can define routes in a way above also.
Quick Guide On Laravel
www.swaam.com
Make Controller
• Open cmd and write
php artisan make:controller SongController
• Controller is created with following
default functions:
I. create()
II. store(Request $request)
III. show($id)
IV. edit($id)
V. update(Request $request, $id)
VI. destroy($id)
Quick Guide On Laravel
Make Model
• Write following command in cmd:
php artisan make:model Song
• Model will be downloaded under app directory
Quick Guide On Laravel
Make Database Migration
• Write following command in cmd
php artisan make:migration create_songs_table --create=songs
Find your migration here
D:xampphtdocslaraveldatabasemigrations
• It has two functions up and down.
• Up function contains the description
of your database table fields.
• Down function contains the query to
drop your database table.
Quick Guide On Laravel
Run Migration
• Before running migration open .env file from your project’s root directory.
• Setup your database name and credentials:
• After defining your table fields in UP function; run following command in
cmd: php artisan migrate
• Your table is now created in database after successful run of above
command.
Quick Guide On Laravel
Define Your Routes
• You can not perform any action without defining your
application routes.
• Define all your routes in your route file.
Quick Guide On Laravel
User Authentication
• These lines help you to authenticate user in laravel
Route::controllers([
'auth' => 'AuthAuthController',
'password' => 'AuthPasswordController'
]);
URL above will be accessed by logged users only.
Quick Guide On Laravel
www.swaam.com
Songs Listing
Quick Guide On Laravel
Insert a Song
• An object of model song is created.
• Value are assigned to fields and then saved in table.
Quick Guide On Laravel
Insert a Song
• Another way
Quick Guide On Laravel
Insert a Song Form
Quick Guide On Laravel
Quick Guide On Laravel
Songs Listing
Quick Guide On Laravel
Update a Song
Quick Guide On Laravel
Updated Songs
Quick Guide On Laravel
Delete a Song
Quick Guide On Laravel
Updated Record
Quick Guide On Laravel
Controller to View
Passing data to view:
return view('songs.show',compact('song'));
where ‘song’ variable contains your data, compact method will send your data to the view named show under songs directory.
Quick Guide On Laravel
www.swaam.com
Success / Failure Message from Controller
• Passing success/failure message
• Another way
Setting message to a specific file create under songs directory.
Quick Guide On Laravel
Display Message in View
Quick Guide On Laravel
Commands You Must Know:
• To make a controller
php artisan make:controller SongController
• To make a migration
php artisan make:migration create_Songs_table --create=songs
• To make a model
php artisan make:model Song
• Checking request parameters (Debugging)
dd(Request::get('lyrics'));
dd(Request::input();)
Quick Guide On Laravel
www.swaam.com
DATABASE
INTERACTION
Quick Guide On Laravel
www.swaam.com
Databases Laravel Supports
Currently four databases are supported by laravel:
• MySQL
• Postgre
• SQLite
• SQL Server
Quick Guide On Laravel
www.swaam.com
CRUD
• Saving a new record
write the following lines of code in controller
$song = new Song; // Song is your model, $song is object of class Song
$song->title = ‘First Song';
$song->save(); // saving your data
• Saving a new record (another way)
in controller
$song = Song::create([title' => First song']);
• Retrieve the song by the attributes, or create it if it doesn't exist
in controller
$song = Song::firstOrCreate([‘title' => First song']);
Quick Guide On Laravel
www.swaam.com
CRUD Continued
• Updating a model
$song = Song::find(1);
$song->title = ‘2nd song ';
$song->save();
Find model by id and update the title field with new title.
• Delete a record
$song = Song::find(1);
$song->delete();
Quick Guide On Laravel
www.swaam.com
Some Common Queries
• Get all data
$result = Student::all();
• Get a single record
$song = DB::table(‘songs')->where('name', ‘First song')->first();
• Getting a single value from a row
$lyrics = DB::table(‘songs')->where('name', First song')->value(‘lyrics');
• Get a list of column values
$titles = DB::table(‘songs')->lists('title');
foreach ($titles as $title) {
echo $title;
}
Quick Guide On Laravel
www.swaam.com
Forms in Laravel
Laravel4 contained a form helper package which is removed from Laravel
If form helper is not included by default
Open cmd and write
composer require "illuminate/html":"5.0.*"
Then add the service provider and aliases
Open /config/app.php and update as follows:
'providers' => [ ...
'IlluminateHtmlHtmlServiceProvider', ],
‘aliases' => [ ...
'Form'=> 'IlluminateHtmlFormFacade',
‘HTML'=> 'IlluminateHtmlHtmlFacade',
],
Quick Guide On Laravel
www.swaam.com
Form Validation
$this->validate($request, [
'title' => 'required|max:2',
‘lyrics' => 'required|min:10',
]);
You can validate your fields using validate
function.
Don’t forget to include form helper!
Quick Guide On Laravel
www.swaam.com
Quick View of Blade Template
• Laravel officially use Blade Template engine for views.
• File is saved with .blade.php extention
• Rich syntax of blade templates is sync with Phpstorm latest
version.
Quick Guide On Laravel
www.swaam.com
Blade Template Syntax Trip
A blade layout
<html>
<body>
@section('sidebar')
This is the master sidebar.
@show
<div class="container">
@yield('content')
</div>
</body>
</html>
Quick Guide On Laravel
www.swaam.com
Blade Template Syntax Trip
@extends('layouts.master')
@section('sidebar')
<p>This is appended to the master sidebar.</p>
@stop
@section('content')
<p>This is my body content.</p>
@stop
@section defines the content section for our page, such as header, footer, left bar etc. which you can yield as in
previous slide.
Quick Guide On Laravel
www.swaam.com
Control Structures
• Conditional Statements
@if ($var == 1 )
value is one!
@elseif ($var == 2)
Value is two!
@else
Zero value !
@endif
@unless (Auth::check())
You are not signed in.
@endunless
Quick Guide On Laravel
www.swaam.com
Loops in Blade
@for(…)
// stuff to do
@endfor
@while(condition)
//stuf to do
@endwhile
@foreach($loops as $loop)
// stuff to do
@endforeach
Quick Guide On Laravel
www.swaam.com
Thank You.
Get in Touch Explore Our Services
We’ve helped several clients with industries like
Email: info@swaam.com Web Address: www.swaam.com

Más contenido relacionado

La actualidad más candente

Configuring the Apache Web Server
Configuring the Apache Web ServerConfiguring the Apache Web Server
Configuring the Apache Web Serverwebhostingguy
 
OWASP Top 10 - The Ten Most Critical Web Application Security Risks
OWASP Top 10 - The Ten Most Critical Web Application Security RisksOWASP Top 10 - The Ten Most Critical Web Application Security Risks
OWASP Top 10 - The Ten Most Critical Web Application Security RisksAll Things Open
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC PresentationVolkan Uzun
 
HTTP HOST header attacks
HTTP HOST header attacksHTTP HOST header attacks
HTTP HOST header attacksDefconRussia
 
OWASP Top 10 Web Application Vulnerabilities
OWASP Top 10 Web Application VulnerabilitiesOWASP Top 10 Web Application Vulnerabilities
OWASP Top 10 Web Application VulnerabilitiesSoftware Guru
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBRavi Teja
 
A2 - broken authentication and session management(OWASP thailand chapter Apri...
A2 - broken authentication and session management(OWASP thailand chapter Apri...A2 - broken authentication and session management(OWASP thailand chapter Apri...
A2 - broken authentication and session management(OWASP thailand chapter Apri...Noppadol Songsakaew
 
NOSQL- Presentation on NoSQL
NOSQL- Presentation on NoSQLNOSQL- Presentation on NoSQL
NOSQL- Presentation on NoSQLRamakant Soni
 
Introduction to NoSQL Databases
Introduction to NoSQL DatabasesIntroduction to NoSQL Databases
Introduction to NoSQL DatabasesDerek Stainer
 

La actualidad más candente (20)

Hash cat
Hash catHash cat
Hash cat
 
Dust.js
Dust.jsDust.js
Dust.js
 
Mongodb vs mysql
Mongodb vs mysqlMongodb vs mysql
Mongodb vs mysql
 
PHP - Web Development
PHP - Web DevelopmentPHP - Web Development
PHP - Web Development
 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
 
Express js
Express jsExpress js
Express js
 
Configuring the Apache Web Server
Configuring the Apache Web ServerConfiguring the Apache Web Server
Configuring the Apache Web Server
 
Building Advanced XSS Vectors
Building Advanced XSS VectorsBuilding Advanced XSS Vectors
Building Advanced XSS Vectors
 
OWASP Top 10 - The Ten Most Critical Web Application Security Risks
OWASP Top 10 - The Ten Most Critical Web Application Security RisksOWASP Top 10 - The Ten Most Critical Web Application Security Risks
OWASP Top 10 - The Ten Most Critical Web Application Security Risks
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
 
HTTP HOST header attacks
HTTP HOST header attacksHTTP HOST header attacks
HTTP HOST header attacks
 
RESTful API - Best Practices
RESTful API - Best PracticesRESTful API - Best Practices
RESTful API - Best Practices
 
Sql injection
Sql injectionSql injection
Sql injection
 
OWASP Top 10 Web Application Vulnerabilities
OWASP Top 10 Web Application VulnerabilitiesOWASP Top 10 Web Application Vulnerabilities
OWASP Top 10 Web Application Vulnerabilities
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
 
A2 - broken authentication and session management(OWASP thailand chapter Apri...
A2 - broken authentication and session management(OWASP thailand chapter Apri...A2 - broken authentication and session management(OWASP thailand chapter Apri...
A2 - broken authentication and session management(OWASP thailand chapter Apri...
 
An Introduction To REST API
An Introduction To REST APIAn Introduction To REST API
An Introduction To REST API
 
NOSQL- Presentation on NoSQL
NOSQL- Presentation on NoSQLNOSQL- Presentation on NoSQL
NOSQL- Presentation on NoSQL
 
Introduction to NoSQL Databases
Introduction to NoSQL DatabasesIntroduction to NoSQL Databases
Introduction to NoSQL Databases
 

Destacado

Intro to Laravel PHP Framework
Intro to Laravel PHP FrameworkIntro to Laravel PHP Framework
Intro to Laravel PHP FrameworkBill Condo
 
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 frameworkBukhori Aqid
 
Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1Vikas Chauhan
 
Laravel and Composer
Laravel and ComposerLaravel and Composer
Laravel and ComposerPhil Sturgeon
 
Laravel for Web Artisans
Laravel for Web ArtisansLaravel for Web Artisans
Laravel for Web ArtisansRaf Kewl
 
Hire laravel-php-developers- Hire Laravel Programmers
Hire laravel-php-developers- Hire Laravel ProgrammersHire laravel-php-developers- Hire Laravel Programmers
Hire laravel-php-developers- Hire Laravel ProgrammersSummation IT
 
Cake Php 1.2 (Ocphp)
Cake Php 1.2 (Ocphp)Cake Php 1.2 (Ocphp)
Cake Php 1.2 (Ocphp)guest193fe1
 
How to learn to build your own PHP framework
How to learn to build your own PHP frameworkHow to learn to build your own PHP framework
How to learn to build your own PHP frameworkDinh Pham
 
Php Frameworks
Php FrameworksPhp Frameworks
Php FrameworksRyan Davis
 
Benefits of the CodeIgniter Framework
Benefits of the CodeIgniter FrameworkBenefits of the CodeIgniter Framework
Benefits of the CodeIgniter FrameworkToby Beresford
 
Introduction to MVC Web Framework with CodeIgniter
Introduction to MVC Web Framework with CodeIgniterIntroduction to MVC Web Framework with CodeIgniter
Introduction to MVC Web Framework with CodeIgniterPongsakorn U-chupala
 
Introduction Yii Framework
Introduction Yii FrameworkIntroduction Yii Framework
Introduction Yii FrameworkTuan Nguyen
 
A Good PHP Framework For Beginners Like Me!
A Good PHP Framework For Beginners Like Me!A Good PHP Framework For Beginners Like Me!
A Good PHP Framework For Beginners Like Me!Muhammad Ghazali
 
PHP Frameworks & Introduction to CodeIgniter
PHP Frameworks & Introduction to CodeIgniterPHP Frameworks & Introduction to CodeIgniter
PHP Frameworks & Introduction to CodeIgniterJamshid Hashimi
 

Destacado (15)

Intro to Laravel PHP Framework
Intro to Laravel PHP FrameworkIntro to Laravel PHP Framework
Intro to Laravel PHP Framework
 
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
 
Laravel Tutorial PPT
Laravel Tutorial PPTLaravel Tutorial PPT
Laravel Tutorial PPT
 
Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1
 
Laravel and Composer
Laravel and ComposerLaravel and Composer
Laravel and Composer
 
Laravel for Web Artisans
Laravel for Web ArtisansLaravel for Web Artisans
Laravel for Web Artisans
 
Hire laravel-php-developers- Hire Laravel Programmers
Hire laravel-php-developers- Hire Laravel ProgrammersHire laravel-php-developers- Hire Laravel Programmers
Hire laravel-php-developers- Hire Laravel Programmers
 
Cake Php 1.2 (Ocphp)
Cake Php 1.2 (Ocphp)Cake Php 1.2 (Ocphp)
Cake Php 1.2 (Ocphp)
 
How to learn to build your own PHP framework
How to learn to build your own PHP frameworkHow to learn to build your own PHP framework
How to learn to build your own PHP framework
 
Php Frameworks
Php FrameworksPhp Frameworks
Php Frameworks
 
Benefits of the CodeIgniter Framework
Benefits of the CodeIgniter FrameworkBenefits of the CodeIgniter Framework
Benefits of the CodeIgniter Framework
 
Introduction to MVC Web Framework with CodeIgniter
Introduction to MVC Web Framework with CodeIgniterIntroduction to MVC Web Framework with CodeIgniter
Introduction to MVC Web Framework with CodeIgniter
 
Introduction Yii Framework
Introduction Yii FrameworkIntroduction Yii Framework
Introduction Yii Framework
 
A Good PHP Framework For Beginners Like Me!
A Good PHP Framework For Beginners Like Me!A Good PHP Framework For Beginners Like Me!
A Good PHP Framework For Beginners Like Me!
 
PHP Frameworks & Introduction to CodeIgniter
PHP Frameworks & Introduction to CodeIgniterPHP Frameworks & Introduction to CodeIgniter
PHP Frameworks & Introduction to CodeIgniter
 

Similar a Laravel Quick Guide

Getting to know Laravel 5
Getting to know Laravel 5Getting to know Laravel 5
Getting to know Laravel 5Bukhori Aqid
 
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...Dilouar Hossain
 
Laravel presentation
Laravel presentationLaravel presentation
Laravel presentationToufiq Mahmud
 
Web services with laravel
Web services with laravelWeb services with laravel
Web services with laravelConfiz
 
Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Viral Solani
 
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin Lorvent56
 
Web service with Laravel
Web service with LaravelWeb service with Laravel
Web service with LaravelAbuzer Firdousi
 
Web Development with Laravel 5
Web Development with Laravel 5Web Development with Laravel 5
Web Development with Laravel 5Soheil Khodayari
 
Lecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptxLecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptxSaziaRahman
 
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 TutorialJoe Ferguson
 
RoR 101: Session 2
RoR 101: Session 2RoR 101: Session 2
RoR 101: Session 2Rory Gianni
 
laravel-interview-questions.pdf
laravel-interview-questions.pdflaravel-interview-questions.pdf
laravel-interview-questions.pdfAnuragMourya8
 
MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5 MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5 Joe Ferguson
 

Similar a Laravel Quick Guide (20)

Getting to know Laravel 5
Getting to know Laravel 5Getting to know Laravel 5
Getting to know Laravel 5
 
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
 
Laravel presentation
Laravel presentationLaravel presentation
Laravel presentation
 
Web services with laravel
Web services with laravelWeb services with laravel
Web services with laravel
 
Laravel tips-2019-04
Laravel tips-2019-04Laravel tips-2019-04
Laravel tips-2019-04
 
Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)
 
Laravel 5.3 - Web Development Php framework
Laravel 5.3 - Web Development Php frameworkLaravel 5.3 - Web Development Php framework
Laravel 5.3 - Web Development Php framework
 
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
 
Web service with Laravel
Web service with LaravelWeb service with Laravel
Web service with Laravel
 
Javascript laravel's friend
Javascript laravel's friendJavascript laravel's friend
Javascript laravel's friend
 
Web Development with Laravel 5
Web Development with Laravel 5Web Development with Laravel 5
Web Development with Laravel 5
 
Laravel
LaravelLaravel
Laravel
 
Rails 4.0
Rails 4.0Rails 4.0
Rails 4.0
 
Lecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptxLecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptx
 
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
 
RoR 101: Session 2
RoR 101: Session 2RoR 101: Session 2
RoR 101: Session 2
 
laravel-interview-questions.pdf
laravel-interview-questions.pdflaravel-interview-questions.pdf
laravel-interview-questions.pdf
 
MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5 MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5
 
9. Radio1 in Laravel
9. Radio1 in Laravel 9. Radio1 in Laravel
9. Radio1 in Laravel
 
Presentation laravel 5 4
Presentation laravel 5 4Presentation laravel 5 4
Presentation laravel 5 4
 

Más de SWAAM Tech

Monkey runner & Monkey testing
Monkey runner & Monkey testingMonkey runner & Monkey testing
Monkey runner & Monkey testingSWAAM Tech
 
An Introduction to Performance Testing
An Introduction to Performance TestingAn Introduction to Performance Testing
An Introduction to Performance TestingSWAAM Tech
 
Android & iPhone App Testing
 Android & iPhone App Testing Android & iPhone App Testing
Android & iPhone App TestingSWAAM Tech
 
Power Over Vs. Power With !!
Power Over Vs. Power With !!Power Over Vs. Power With !!
Power Over Vs. Power With !!SWAAM Tech
 
A / B Testing
A / B Testing A / B Testing
A / B Testing SWAAM Tech
 
Mobile Application Testing
Mobile Application TestingMobile Application Testing
Mobile Application TestingSWAAM Tech
 

Más de SWAAM Tech (6)

Monkey runner & Monkey testing
Monkey runner & Monkey testingMonkey runner & Monkey testing
Monkey runner & Monkey testing
 
An Introduction to Performance Testing
An Introduction to Performance TestingAn Introduction to Performance Testing
An Introduction to Performance Testing
 
Android & iPhone App Testing
 Android & iPhone App Testing Android & iPhone App Testing
Android & iPhone App Testing
 
Power Over Vs. Power With !!
Power Over Vs. Power With !!Power Over Vs. Power With !!
Power Over Vs. Power With !!
 
A / B Testing
A / B Testing A / B Testing
A / B Testing
 
Mobile Application Testing
Mobile Application TestingMobile Application Testing
Mobile Application Testing
 

Último

Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Contact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New DelhiContact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New Delhimiss dipika
 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxDyna Gilbert
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012rehmti665
 
Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170Sonam Pathan
 
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170Sonam Pathan
 
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书zdzoqco
 
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作ys8omjxb
 
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一Fs
 
PHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationPHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationLinaWolf1
 
Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...Excelmac1
 
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Dana Luther
 
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)Christopher H Felton
 
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一Fs
 
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一Fs
 
Magic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptxMagic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptxMartaLoveguard
 
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一Fs
 
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja VipCall Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja VipCall Girls Lucknow
 

Último (20)

Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
 
Contact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New DelhiContact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New Delhi
 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptx
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
 
Model Call Girl in Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in  Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in  Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
 
Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170
 
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
 
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
 
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
 
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
 
Hot Sexy call girls in Rk Puram 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in  Rk Puram 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in  Rk Puram 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Rk Puram 🔝 9953056974 🔝 Delhi escort Service
 
PHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationPHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 Documentation
 
Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...
 
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
 
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
 
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
 
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
 
Magic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptxMagic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptx
 
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
 
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja VipCall Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
 

Laravel Quick Guide

  • 1.
  • 2. Laravel The PHP Framework For Web Artisans Presented by : Syeda Aimen Batool Developer @ Swaam Tech
  • 3. We will discuss: • Laravel Features • Composer and Laravel Setup • Directory Structure • Routing • Controller & Model • CRUD Examples • Database Migrations • User Authentication • Controller to View Communication • Basic Commands • Databases (Basic Queries) • Form Validation • Blade Template Engine Quick Guide On Laravel www.swaam.com
  • 4. Features Laravel is an open source MVC PHP Framework under MIT license. Bundles are packages which you can download to add particular functionality in your web application to save coding and time. Eloquent ORM provides a simple ActiveRecord implementation for working with database. Class Auto loading assures that correct components are loaded at correct time. Unit testing allows users to easily create and run unit tests to ensure application stability. Quick Guide On Laravel www.swaam.com
  • 5. Requirements • Apache or any other compatible web server • PHP Version should be 5.5.9 or greater • PDO PHP Extension should be enabled PDO is by default enable in php 5.1.0 or greater. You can manually activate by uncommenting statement below in php.ini by removing semicolon at beginning extension=php_pdo.dll • OpenSSL PHP Extension should be enabled to manually activate OpenSSL extension uncomment the line extension=php_openssl.dll by removing the semicolon at beginning • okenizer PHP Extension should be enabled This extension is by default enabled in php versions 4.3.0 or greater Quick Guide On Laravel
  • 6. MVC Layers • Model (Eloquent ORM) Model represents the logical structure of an application e.g. list of database record • View (Blade Engine) View displays the data user see on screen such as buttons, display boxes etc. • Controller Controller represents the classes connecting the view and model, it helps model and view to communicate with each other Quick Guide On Laravel www.swaam.com
  • 7. Composer and Laravel Setup: • A dependencies management tool. • Download Composer from here. • Run setup. • Browse php.exe file under xampp/php/php.exe. • After successful installation; open your cmd. open cmd execute composer.phar to check if composer is successfully installed • Download the Laravel installer by writing given command in cmd. Composer global require “laravel/installer=~1.1” • Create a new project by running following command in cmd. Composer create-project laravel/laravel --prefer-dist Installing… Quick Guide On Laravel www.swaam.com
  • 8. Hello Laravel  • After installation hit “http://localhost/laravel/public/” in your browser • Remove public from your url by following this: – Go to D:xampphtdocslaravelpublic – Cut index.php and .htaccess file and paste here: D:xampphtdocslaravel – Open index.php and change bootstrap path: ../../bootstrap/ to ../bootstrap/ in whole file – Now hit your url without public “http://localhost/laravel/” – Congratulations ! You have successfully setup Laravel. Quick Guide On Laravel www.swaam.com
  • 9. Directory Structure: • Routes are available under app directory: D:xamphtdocslaravelappHttproutes.php • Controllers are available at: D:xamphtdocslaravelappHttpController • User Authentication is available at: D:xamphtdocslaravelappHttpControllersAuth • All your assets and views are available at: D:xamphtdocslaravelresources • Models are available at: D:xamphtdocslaravelapp Quick Guide On Laravel www.swaam.com
  • 10. My First Routes: All routes are available at D:xamphtdocslaravelappHttproutes.php • Default Route: A root looks like => Route::get('/home', 'WelcomeController@index'); Where ‘/home’ is you will enter in url 'WelcomeController is your application controller Index is a function in your controller Hitting ‘/home’ in url will invoke your controller and call function index – Route::get(‘Home', ‘HomeController@index'); – Route::post(‘application/create', ‘ApplicationController@create'); – Route::patch(‘application/update', ‘ApplicationController@update'); Quick Guide On Laravel www.swaam.com
  • 11. Named Routes: • Giving a specific name to a route: Route::get('songs',['as'=>'songs_path‘ , 'uses'=>'SongsController@index']); where songs_path Is name specified to this particular route, we can use this name in our app instead of writing route. e.g. <a href="{{ route('songs_path')}}"> will be a hyperlink to this route. • Just an other way: $router -> get('songs',['as'=>'songs_path','uses'=>'SongsController@index']); We can define routes in a way above also. Quick Guide On Laravel www.swaam.com
  • 12. Make Controller • Open cmd and write php artisan make:controller SongController • Controller is created with following default functions: I. create() II. store(Request $request) III. show($id) IV. edit($id) V. update(Request $request, $id) VI. destroy($id) Quick Guide On Laravel
  • 13. Make Model • Write following command in cmd: php artisan make:model Song • Model will be downloaded under app directory Quick Guide On Laravel
  • 14. Make Database Migration • Write following command in cmd php artisan make:migration create_songs_table --create=songs Find your migration here D:xampphtdocslaraveldatabasemigrations • It has two functions up and down. • Up function contains the description of your database table fields. • Down function contains the query to drop your database table. Quick Guide On Laravel
  • 15. Run Migration • Before running migration open .env file from your project’s root directory. • Setup your database name and credentials: • After defining your table fields in UP function; run following command in cmd: php artisan migrate • Your table is now created in database after successful run of above command. Quick Guide On Laravel
  • 16. Define Your Routes • You can not perform any action without defining your application routes. • Define all your routes in your route file. Quick Guide On Laravel
  • 17. User Authentication • These lines help you to authenticate user in laravel Route::controllers([ 'auth' => 'AuthAuthController', 'password' => 'AuthPasswordController' ]); URL above will be accessed by logged users only. Quick Guide On Laravel www.swaam.com
  • 19. Insert a Song • An object of model song is created. • Value are assigned to fields and then saved in table. Quick Guide On Laravel
  • 20. Insert a Song • Another way Quick Guide On Laravel
  • 21. Insert a Song Form Quick Guide On Laravel
  • 22. Quick Guide On Laravel
  • 24. Update a Song Quick Guide On Laravel
  • 26. Delete a Song Quick Guide On Laravel
  • 28. Controller to View Passing data to view: return view('songs.show',compact('song')); where ‘song’ variable contains your data, compact method will send your data to the view named show under songs directory. Quick Guide On Laravel www.swaam.com
  • 29. Success / Failure Message from Controller • Passing success/failure message • Another way Setting message to a specific file create under songs directory. Quick Guide On Laravel
  • 30. Display Message in View Quick Guide On Laravel
  • 31. Commands You Must Know: • To make a controller php artisan make:controller SongController • To make a migration php artisan make:migration create_Songs_table --create=songs • To make a model php artisan make:model Song • Checking request parameters (Debugging) dd(Request::get('lyrics')); dd(Request::input();) Quick Guide On Laravel www.swaam.com
  • 32. DATABASE INTERACTION Quick Guide On Laravel www.swaam.com
  • 33. Databases Laravel Supports Currently four databases are supported by laravel: • MySQL • Postgre • SQLite • SQL Server Quick Guide On Laravel www.swaam.com
  • 34. CRUD • Saving a new record write the following lines of code in controller $song = new Song; // Song is your model, $song is object of class Song $song->title = ‘First Song'; $song->save(); // saving your data • Saving a new record (another way) in controller $song = Song::create([title' => First song']); • Retrieve the song by the attributes, or create it if it doesn't exist in controller $song = Song::firstOrCreate([‘title' => First song']); Quick Guide On Laravel www.swaam.com
  • 35. CRUD Continued • Updating a model $song = Song::find(1); $song->title = ‘2nd song '; $song->save(); Find model by id and update the title field with new title. • Delete a record $song = Song::find(1); $song->delete(); Quick Guide On Laravel www.swaam.com
  • 36. Some Common Queries • Get all data $result = Student::all(); • Get a single record $song = DB::table(‘songs')->where('name', ‘First song')->first(); • Getting a single value from a row $lyrics = DB::table(‘songs')->where('name', First song')->value(‘lyrics'); • Get a list of column values $titles = DB::table(‘songs')->lists('title'); foreach ($titles as $title) { echo $title; } Quick Guide On Laravel www.swaam.com
  • 37. Forms in Laravel Laravel4 contained a form helper package which is removed from Laravel If form helper is not included by default Open cmd and write composer require "illuminate/html":"5.0.*" Then add the service provider and aliases Open /config/app.php and update as follows: 'providers' => [ ... 'IlluminateHtmlHtmlServiceProvider', ], ‘aliases' => [ ... 'Form'=> 'IlluminateHtmlFormFacade', ‘HTML'=> 'IlluminateHtmlHtmlFacade', ], Quick Guide On Laravel www.swaam.com
  • 38. Form Validation $this->validate($request, [ 'title' => 'required|max:2', ‘lyrics' => 'required|min:10', ]); You can validate your fields using validate function. Don’t forget to include form helper! Quick Guide On Laravel www.swaam.com
  • 39. Quick View of Blade Template • Laravel officially use Blade Template engine for views. • File is saved with .blade.php extention • Rich syntax of blade templates is sync with Phpstorm latest version. Quick Guide On Laravel www.swaam.com
  • 40. Blade Template Syntax Trip A blade layout <html> <body> @section('sidebar') This is the master sidebar. @show <div class="container"> @yield('content') </div> </body> </html> Quick Guide On Laravel www.swaam.com
  • 41. Blade Template Syntax Trip @extends('layouts.master') @section('sidebar') <p>This is appended to the master sidebar.</p> @stop @section('content') <p>This is my body content.</p> @stop @section defines the content section for our page, such as header, footer, left bar etc. which you can yield as in previous slide. Quick Guide On Laravel www.swaam.com
  • 42. Control Structures • Conditional Statements @if ($var == 1 ) value is one! @elseif ($var == 2) Value is two! @else Zero value ! @endif @unless (Auth::check()) You are not signed in. @endunless Quick Guide On Laravel www.swaam.com
  • 43. Loops in Blade @for(…) // stuff to do @endfor @while(condition) //stuf to do @endwhile @foreach($loops as $loop) // stuff to do @endforeach Quick Guide On Laravel www.swaam.com
  • 45. Get in Touch Explore Our Services We’ve helped several clients with industries like Email: info@swaam.com Web Address: www.swaam.com