Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 35

What is Laravel?

Laravel is an open source MVC PHP Framework


under MIT License

MVC Architecture

Model : Model deals with backend logical


structure of the application such as data base
records. In laravel it is denoted as Eloquent
model.
View : View deals with frontend such as the
HTML, CSS. In laravel it works with Blade
Template Engine and denoted as View.
Controller : Model and View can be
communicated through Controllers. In laravel it is
denoted as Controller.

MVC Architecture

Installing Laravel
Requirements:
The Laravel framework has a few system
requirements.

PHP version should be 5.5.9 or greater

Apache or any other compatible web server


Datatabase like MySQL
Composer dependency manager
IDE Tool Such as PHP Storm or Any Editor like
Sublim Text, Notepad++.

Installing Laravel
In Linux Apache, MySQL & PHP can be
installed through terminal
$ apt-get install php5-common libapache2mod-php5 php5-cli php5-mysql php5-curl

Installing Laravel
To Check PHP
use php -v at terminal to check PHP version

Or else use localhost to check php information

Installing Laravel

Installing Laravel
Laravel utilizes Composer to manage its
dependencies. To install composer through
terminal
$ curl -sS https://getcomposer.org/installer |
php
$ mv composer.phar /usr/local/bin/composer
$ composer global require
"laravel/installer=~1.1"

Installing Laravel

Installing Laravel

To check Composer

Create Laravel App


To Create Laravel Application through
terminal
$ composer create-project laravel/laravel
name-of-the-app

Create Laravel App


Browse to the following URL in your web
browser.
http://localhost/project-name/public/

Laravel directory structure

After crating laravel first app you will notice


there is huge laravel directory structure

Laravel directory
structure
Let us discuss the directory structure in brief

It comes as no surprise that all Laravel projects have


essentially the same directory structure - one in which
every file has its designated place. By gently forcing this
directory structure upon developers, Laravel ensures that
your work is semi-automatically organized the Laravel
way.
As you can see, this standard directory structure consists
of quite a few subdirectories. This wealth of subdirectories
can be overwhelming at first, but well explore them one
by one. Most of your work will happen in the app/ folder,
but heres a basic rundown on the function of each of the
files and folders:

Laravel directory
structure

Top-level Folders
and their purpose
/app/ Contains the controllers, models, views and assets for
your application. This is where the majority of the code for
your application will live. You will be spending most of your
time in this folder!
/public/ The only folder seen to the world as-is. This is the
directory that you have to point your web server to. It
contains the bootstrap file index.php which jump-starts the
Laravel framework core. The public directory can also be
used to hold any publicly accessible static assets such as
CSS, Javascript files, images and other files.
/vendor/ A place for all third-party code. In a typical Laravel
application, this includes the Laravel source code and its
dependencies, and plugins containing additional
prepackaged functionality.

Laravel directory
structure
/app/Http/routes.php

Suppose routes.php file contains the below


mentioned code
Route::get('/', function()

{
return view('welcome');

});

When you browse


http://localhost/project-name/public/

It goes to routes.php and finds get request and as a


result it goes to return view('welcome'). So it then
moves to view directory.

Laravel directory
structure

/resources/views/welcome.blade.php

Blade is the simple, yet powerful


templating engine provided with
Laravel.

The complete user viewable


contents can be placed here

It uses html, css,javascript and php

Laravel directory
structure
Suppose routes.php has the below code

Route::resource('photo', 'PhotoController');
It goes to App/Http/Controllers/ directory and
finds PhotoController.php which contains
logic for backend data.
This single route declaration creates multiple
routes to handle a variety of RESTful actions
on the photo resource.

Laravel directory
structure

Methods or Actions Handled By Resource Controller


Verb Path
Action
Route Name
GET
/photo
index
photo.index
GET
/photo/create
create
photo.create
POST /photo
store
photo.store
GET
/photo/{photo}
show
photo.show
GET
/photo/{photo}/editedit
photo.edit
PUT/PATCH /photo/{photo} update
photo.update
DELETE /photo/{photo}
destroy
photo.destroy

Laravel directory
structure

PhotoController.php
class PhotoController extends Controller

{
public function index()
{
return view('welcome');
}
public
public
public
public
public
public
}

function
function
function
function
function
function

create(){ //logic for create photo }


store(){ //logic for store photo }
show(){ //logic for show photo}
edit(){ //logic for edit photo }
update(){ //logic for update photo }
destroy(){ //logic for destroy photo }

Josh- An Example Laravel


App
Want to be more familiar with Laravel ?
You can go for Josh which is an excellent admin

template for Laravel framework.


This template made with rich features

Responsive clean design


User friendly
Laravel
HTML5
CSS3
Bootstrap 3.3.4

Josh- Installation
Josh doesn't ship with whole laravel files, so you

need to intall laravel first.

install laravel using composer by executing $ composer


create-project laravel/laravel your_project_name

Next setup Database

Laravel 5 ships with .env file.


Incase, you don't find it in root folder of your laravel
installation,
execute following command in terminal to make it.
cp .env.example .env
then edit database, environment related details in that
file.

Josh- Installation
Directory Permissions
Laravel 5.1 requires directories within the
storage and the bootstrap/cache directories
should be writable by your web server
Todo this run the below commands on
terminal
$ chmod -R 775 storage
$ chmod 775 bootstrap/cache

Josh- Installation
Mail Setup
Laravel 5.1 stored all mail information in .env
so setup details in .env
Still you need to set sender name and email
details in config/mail.php
If you are testing locally or don't want to send
any mails, then please set 'pretend' => true,
in config/mail.php at bottom of the page.

Josh- Installation
Copying Josh files
now copy files downloaded from

http://codecanyon.net/item/josh-laravel-admintemplate-front-end-crud/8754542
to your laravel 5.1 installation.

updating autoload
composer should know some new files were

added so that it can autoload them


Hit $ composer dump-autoload in terminal for
that

Josh- Installation
Delete existing migration files
Since we are not relying on default migration
tables, please remove following two files from
database/migrations folder

2014_10_12_000000_create_users_table.ph
p
2014_10_12_100000_create_password_rese
ts_table.php

Otherwise you will get error at later stage of

installation.

JoshInstallation
Install Packages
We use good number of packages to provide

great functionality without re-inventing wheel.


Now add below mentioned packages in
composer.json in require array

"cartalyst/sentinel": "2.0.*",
"laravelcollective/html": "5.1.*",
"cviebrock/eloquent-sluggable": "dev-master",
"cviebrock/eloquent-taggable": "dev-master",
"yajra/laravel-datatables-oracle": "~5.0"

update vendors

now hit $ composer update in terminal to


download above packages.

Josh- Installation
Add service providers
Open config/app.php and add following lines in the
providers array
Cartalyst\Sentinel\Laravel\SentinelServiceProvider:
:class,
Collective\Html\HtmlServiceProvider::class,
Cviebrock\EloquentSluggable\SluggableServicePro
vider::class,
Cviebrock\EloquentTaggable\ServiceProvider::class
,
yajra\Datatables\DatatablesServiceProvider::class

Josh- Installation
In the $aliases array add following facades
'Activation' =>
Cartalyst\Sentinel\Laravel\Facades\Activation::class,
'Reminder' =>
Cartalyst\Sentinel\Laravel\Facades\Reminder::class,
'Sentinel'
=>
Cartalyst\Sentinel\Laravel\Facades\Sentinel::class,
'Form'
=> Collective\Html\FormFacade::class,
'Html'
=> Collective\Html\HtmlFacade::class,
'Datatables' => yajra\Datatables\Datatables::class,

Josh- Installation
publish vendors
now we need to publish vendor files so that they
will publish config files, migrations.
Excecute following command in command
prompt/terminal
$ php artisan sluggable:table blogs
$ php artisan taggable:table
$ php artisan vendor:publish

Now we need to add user, groups etc tables to

database, to do so in your command prompt,


execute following code
$ php artisan migrate

Note: please check all files in database\migrations


to know what fields are being added.

Josh- Installation
setting up config to use our model
since we have different requirements (extra

fields in users table), we need to change sentinel


config to use our user Model,
to do that open config/cartalyst.sentinel.php
at line 56, find
'model' =>
'Cartalyst\Sentinel\Users\EloquentUser',
replace it with
'model' => 'App\User',

Josh- Installation
Add admin user:

As database tables have been setup, we need to


add admin user to be able to login into adminCP.

Run following command in your command


prompt
$ php artisan db:seed --class=AdminSeeder

A default admin user with user with username


[email protected] and password admin will be
created

Josh- Installation
user's profile pics will be uploaded into

public/uploads/users
So we need to provide write access for that
folder
to do so, please run following command in
your command prompt/terminal
$ chmod 775 public/uploads/users
$ chmod 775 public/uploads/blog
Finally,

Browse to http://localhost/josh_laravel51/public/

Go with Josh

Congratulations! You are ready to rock the world!!

For More Info Contact Us:


www.joshadmin.com

For More Info Visit :


www.joshadmin.com

shadmin.com

You might also like