Features - Routing controllers. - Configuration management. - Testability. - Authentication and authorization of users. - Modularity. - ORM (Object Relational Mapper) features. - Provides a template engine. - Building schemas. - E-mailing facilities. Installation - Laravel implements a composer for managing dependencies within it. - so to install laravel you should first instll composer. - get composer and install it.
composer global require "laravel/installer"
When the installation is done, a new command of laravel will start a fresh installation in the directory you have provided.
laravel new nirectory_name
To create project
composer create-project laravel/laravel –-prefer-dist
To run laravel on http://localhost:8080
php artisan serve
BasicRouting - routing means to route your request to an appropriate controller. - The routes of the application can be defined in app/Http/routes.php file. Here is the general route syntax for each of the possible request.
Route::get('/', function () {
return 'Hello World';
});
Route::post('foo/bar', function () {
return 'Hello World';
});
Route::put('foo/bar', function () {
//
});
Route::delete('foo/bar', function () {
//
});
Example
app/Http/routes.php
< ?php
Route::get('/', function () {
return view('welcome');
});
parametric example:
Route::get('ID/{id}',function($id){
echo 'ID: '.$id;
});
Optional Parameters Example:
Route::get('/user/{name?}',function($name = 'Virat'){
echo "Name: ".$name;
});
Creatinbg controllers
php artisan make:controller --plain
The controller body will be:
< ?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class AdminController extends Controller
{
//
}
To call the controller:
Route::get('base URI','controller@method');
or
Route::get('profile', 'AdminController@show')->middleware('auth');
Views
for example:
< h1>Hello, !< /h1>
Rendering views
// in a Laravel controller
return view('greeting', ['name' => 'Alex']);
Using layouts(template) for example:
< html>
< head>
< title>App Name - @yield('title')
< /head>
< body>
@section('sidebar')
This is the master sidebar.
@show
< div class="container">
@yield('content')
< /div>
< /body>
< /html>
continue reading