SlideShare a Scribd company logo
Laravel - Website Development in Php Framework.
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

More Related Content

PDF
OpenSCAP Overview(security scanning for docker image and container)
PPTX
Building IAM for OpenStack
PDF
Install active directory on windows server 2016 step by step
PDF
ReCertifying Active Directory
PDF
Docker London: Container Security
PPTX
Geek Sync I The Importance of Data Model Change Management
PDF
Different Methodology To Recon Your Targets
OpenSCAP Overview(security scanning for docker image and container)
Building IAM for OpenStack
Install active directory on windows server 2016 step by step
ReCertifying Active Directory
Docker London: Container Security
Geek Sync I The Importance of Data Model Change Management
Different Methodology To Recon Your Targets

What's hot (20)

PPTX
Enterprise container platform verrazzano
PPTX
HCL Domino Volt Installation, Configuration & New Features
PDF
0101 foundation - detailed view of hana architecture
PPTX
Docker Container Security
PDF
Guardicore - Shrink Your Attack Surface with Micro-Segmentation
PPTX
OpenStack Glance
PDF
BAS011_VMware資料中心虛擬化-基礎_v190418
PPT
ASP.NET Tutorial - Presentation 1
PPT
Guía de instalación de la version VMware ESXi 6.0.0
PDF
Derbycon - The Unintended Risks of Trusting Active Directory
PDF
Introduction to Docker storage, volume and image
PPTX
Cloud Oracle
PDF
Programmation sous Android
PDF
Secure Programming Practices in C++ (NDC Security 2018)
PDF
Free radius for wpa2 enterprise with active directory integration
PDF
Docker by Example - Basics
PPTX
Building Your Portfolio Site on Salesforce Experience Cloud
PPTX
Vulnerable_and_outdated_components_suman.pptx
PPTX
Metadata Extraction and Content Transformation
PDF
Oracle 10g to 11g upgrade on sap(10.2.0.5.0 to 11.2.0.3)
Enterprise container platform verrazzano
HCL Domino Volt Installation, Configuration & New Features
0101 foundation - detailed view of hana architecture
Docker Container Security
Guardicore - Shrink Your Attack Surface with Micro-Segmentation
OpenStack Glance
BAS011_VMware資料中心虛擬化-基礎_v190418
ASP.NET Tutorial - Presentation 1
Guía de instalación de la version VMware ESXi 6.0.0
Derbycon - The Unintended Risks of Trusting Active Directory
Introduction to Docker storage, volume and image
Cloud Oracle
Programmation sous Android
Secure Programming Practices in C++ (NDC Security 2018)
Free radius for wpa2 enterprise with active directory integration
Docker by Example - Basics
Building Your Portfolio Site on Salesforce Experience Cloud
Vulnerable_and_outdated_components_suman.pptx
Metadata Extraction and Content Transformation
Oracle 10g to 11g upgrade on sap(10.2.0.5.0 to 11.2.0.3)
Ad

Viewers also liked (15)

PDF
Intro to Laravel PHP Framework
PDF
Knowing Laravel 5 : The most popular PHP framework
PPTX
Laravel Tutorial PPT
PPTX
Laravel Beginners Tutorial 1
PDF
Laravel and Composer
PPTX
Laravel for Web Artisans
PPTX
Hire laravel-php-developers- Hire Laravel Programmers
PDF
Cake Php 1.2 (Ocphp)
PPT
How to learn to build your own PHP framework
PPT
Php Frameworks
PPT
Benefits of the CodeIgniter Framework
PPTX
Introduction to MVC Web Framework with CodeIgniter
PDF
Introduction Yii Framework
ODP
A Good PHP Framework For Beginners Like Me!
PPTX
PHP Frameworks & Introduction to CodeIgniter
Intro to Laravel PHP Framework
Knowing Laravel 5 : The most popular PHP framework
Laravel Tutorial PPT
Laravel Beginners Tutorial 1
Laravel and Composer
Laravel for Web Artisans
Hire laravel-php-developers- Hire Laravel Programmers
Cake Php 1.2 (Ocphp)
How to learn to build your own PHP framework
Php Frameworks
Benefits of the CodeIgniter Framework
Introduction to MVC Web Framework with CodeIgniter
Introduction Yii Framework
A Good PHP Framework For Beginners Like Me!
PHP Frameworks & Introduction to CodeIgniter
Ad

Similar to Laravel - Website Development in Php Framework. (20)

PDF
Laravel Level 1 (The Basic)
PPTX
What-is-Laravel and introduciton to Laravel
DOCX
Laravel
PPTX
What-is-Laravel-23-August-2017.pptx
PPTX
CRUD presentation of laravel application.pptx
PDF
Memphis php 01 22-13 - laravel basics
PPTX
Laravel overview
PPTX
Laravel5 Introduction and essentials
PPTX
Laravel
PPTX
Laravel 5
PDF
Getting to know Laravel 5
PPTX
Laravel ppt
PPT
Laravel & Composer presentation - WebHostFace
PDF
Laravel Introduction
PDF
Web Development with Laravel 5
PDF
Laravel 4 presentation
PDF
Best Laravel Eloquent Tips and Tricks
PDF
Object Oriented Programming with Laravel - Session 6
PPTX
Getting started with laravel
PDF
laravel-interview-questions.pdf
Laravel Level 1 (The Basic)
What-is-Laravel and introduciton to Laravel
Laravel
What-is-Laravel-23-August-2017.pptx
CRUD presentation of laravel application.pptx
Memphis php 01 22-13 - laravel basics
Laravel overview
Laravel5 Introduction and essentials
Laravel
Laravel 5
Getting to know Laravel 5
Laravel ppt
Laravel & Composer presentation - WebHostFace
Laravel Introduction
Web Development with Laravel 5
Laravel 4 presentation
Best Laravel Eloquent Tips and Tricks
Object Oriented Programming with Laravel - Session 6
Getting started with laravel
laravel-interview-questions.pdf

More from SWAAM Tech (6)

PPTX
Monkey runner & Monkey testing
PPTX
An Introduction to Performance Testing
PPT
Android & iPhone App Testing
PDF
Power Over Vs. Power With !!
PPTX
A / B Testing
PPTX
Mobile Application Testing
Monkey runner & Monkey testing
An Introduction to Performance Testing
Android & iPhone App Testing
Power Over Vs. Power With !!
A / B Testing
Mobile Application Testing

Recently uploaded (20)

PPTX
international classification of diseases ICD-10 review PPT.pptx
PPTX
SAP Ariba Sourcing PPT for learning material
PDF
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
PDF
Triggering QUIC, presented by Geoff Huston at IETF 123
PPTX
Funds Management Learning Material for Beg
PDF
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
PDF
Unit-1 introduction to cyber security discuss about how to secure a system
PDF
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
PPTX
Module 1 - Cyber Law and Ethics 101.pptx
PDF
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
PDF
WebRTC in SignalWire - troubleshooting media negotiation
PPT
Design_with_Watersergyerge45hrbgre4top (1).ppt
PPTX
Introduction to Information and Communication Technology
PPTX
Introuction about ICD -10 and ICD-11 PPT.pptx
PDF
Paper PDF World Game (s) Great Redesign.pdf
PPTX
INTERNET------BASICS-------UPDATED PPT PRESENTATION
PPTX
presentation_pfe-universite-molay-seltan.pptx
PDF
An introduction to the IFRS (ISSB) Stndards.pdf
PDF
Slides PDF The World Game (s) Eco Economic Epochs.pdf
PDF
RPKI Status Update, presented by Makito Lay at IDNOG 10
international classification of diseases ICD-10 review PPT.pptx
SAP Ariba Sourcing PPT for learning material
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
Triggering QUIC, presented by Geoff Huston at IETF 123
Funds Management Learning Material for Beg
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
Unit-1 introduction to cyber security discuss about how to secure a system
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
Module 1 - Cyber Law and Ethics 101.pptx
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
WebRTC in SignalWire - troubleshooting media negotiation
Design_with_Watersergyerge45hrbgre4top (1).ppt
Introduction to Information and Communication Technology
Introuction about ICD -10 and ICD-11 PPT.pptx
Paper PDF World Game (s) Great Redesign.pdf
INTERNET------BASICS-------UPDATED PPT PRESENTATION
presentation_pfe-universite-molay-seltan.pptx
An introduction to the IFRS (ISSB) Stndards.pdf
Slides PDF The World Game (s) Eco Economic Epochs.pdf
RPKI Status Update, presented by Makito Lay at IDNOG 10

Laravel - Website Development in Php Framework.

  • 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