Show Menu

Laravel 5 Cheat Sheet (DRAFT) by

This is a draft cheat sheet. It is a work in progress and is not finished yet.


php artisan serv //lance un serveur de test
php artisan down //Met l'appl­ication en mainte­nance
php artisan up //enleve l'appl­ication de la mainte­nance
php artisan env //affiche les variables d'envi­ron­ement
php artisan help //affiche l'aide de la commande
php artisan list //list les commandes
php artisan optimize //optimise l'appl­ication
php artisan clear-­com­piled //efface du cache les fichiers compilés
php artisan tinker // lance l'appl­ication en mode console


php artisan make:c­ont­roller MonCon­troller
php artisan make:c­ommand MaCommande
php artisan make:event Moneve­nement
php artisan make:job MonJob
php artisan make:l­istener MonLis­tener
php artisan make:m­idd­leware MonMid­dleWare
php artisan make:m­igr­ation MaMigr­ation
php artisan make:model MonModel
php artisan make:p­rovider MonPro­vider
php artisan make:r­equest MaRequest
php artisan make:s­eeder MonSeeder

Blade Layout

//if condition

@foreach($foo as $bar)

// Resources/views/folder/page.blade.php




//Model en base de donnees
class Post extend Model{
  protected $primaryKey = "IDPost"
  protected $table = "post"

//Recuperation par cle primaire
//Recuperation par where
Post::where('titre', '=', 'valeur')->get();
//Faire un join
Post::join('table', 'post.idTable', 'table.IDTable')->get();

//Insertion en base
$post = new Post();
$post->titre = "hello";

$post = Post::find(1);
$post->titre = "modif"



php artisan route:­cache //Met les routes en cache
php artisan route:­clear //Supprime le cache des routes
php artisan route:list //affiche la liste des routes


//Route Simple
Route::get('/',function (){
    return view('hello');

//Route avec parametre
Route::get('/post/{id}', function($id){
    return view('post', ["id"=>$id]);

//Route avec controller et methode
Route::get('/add', 'MusiqueController@formAdd');

//Route nommé
Route::get('/add', 'MusiqueController@formAdd')->name('showAddForm');

//Route validation regex
Route::get('/post/{id}', "MusiqueController@detail")->where('id', '[0-9]+');

//Methode http
Route::get('/', "controller@example");
Route::post('/', "controller@example");
Route::put('/', "controller@example");
Route::patch('/', "controller@example");
Route::delete('/', "controller@example");

Route::prefix('api', function (){
    Route::get('/', function (){
        return view('api');
    Route::get('/test', function (){
        return view('api');

//utilisation d'un middleware
//sur plusieurs routes
Route::middleware(['first', 'second'])->group(function () {
    Route::get('/', function () {
        // utilise first & second Middleware

    Route::get('user/profile', function () {
        // utilise first & second Middleware


php artisan migrate --seed


class DatabaseSeeder extends Seeder
     * Run the database seeds.
     * @return void
    public function run()


php artisan migrate
php artisan migrat­e:i­nstall
php artisan migrat­e:r­ollback
php artisan migrat­e:r­efresh
php artisan migrat­e:reset
php artisan migrat­e:s­tatus


class CreateMusiquesTable extends Migration
     * Run the migrations.
     * @return void
    public function up()
        Schema::create('musiques', function (Blueprint $table) {

     * Reverse the migrations.
     * @return void
    public function down()