sepehr
1/20/2016 - 9:05 PM

Laravel 5 setup

Laravel 5 setup

Laravel 5 recipe

Install Laravel

composer create-project laravel/laravel --prefer-dist app.dev

# Or with laravel installer:
laravel new app.dev

# Setup write permissions
a2mkw storage/
a2mkw bootstrap/cache/

# Then, setup .env configurations
vim .env

# Rename the app
artisan app:name MyApp

# Update composer.json with project specific info
vim composer.json

# Install node dependencies
npm install

Add third-party packages

composer require --dev filp/whoops barryvdh/laravel-ide-helper

composer require \
  laravelcollective/html \
  kris/laravel-form-builder \
  graham-campbell/exceptions \
  prettus/l5-repository \
  prettus/laravel-validator \
  lukebro/flash \
  doctrine/dbal \
  laravelista/ekko \
  lavary/laravel-menu

Setup third-party packages

Update providers and aliases

'providers' => [
  // ...
  
  /*
   * Contrib Service Providers...
   */
  Lavary\Menu\ServiceProvider::class,
  Lukebro\Flash\FlashServiceProvider::class,
  Collective\Html\HtmlServiceProvider::class,
  Laravelista\Ekko\EkkoServiceProvider::class,
  Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,
  Kris\LaravelFormBuilder\FormBuilderServiceProvider::class,
  GrahamCampbell\Exceptions\ExceptionsServiceProvider::class,
  Prettus\Repository\Providers\RepositoryServiceProvider::class,
]

'aliases' => [
  // ...
  
  /*
   * Contrib Aliases...
   */
  'Menu'  => Lavary\Menu\Facade::class,
  'Flash' => Lukebro\Flash\FlashFacade::class,
  'Form'  => Collective\Html\FormFacade::class,
  'Html'  => Collective\Html\HtmlFacade::class,
  'ActiveTrail' => Laravelista\Ekko\Facades\Ekko::class,
  'FormBuilder' => Kris\LaravelFormBuilder\Facades\FormBuilder::class,
]

Publish vendor configs

artisan vendor:publish

Setup exceptions package

Change your App\Exceptions\Handler class to extend GrahamCampbell\Exceptions\ExceptionHandler rather than extending Illuminate\Foundation\Exceptions\Handler class.

vim app/Exceptions/Handler.php

# And make sure you have this:
# class Handler extends GrahamCampbell\Exceptions\ExceptionHandler

Setup IDE helper package

# First, configure the package:
vim config/ide-helper.php

# Generate phpdocs for Laravel facades
artisan clear-compiled
artisan ide-helper:generate

# Generate phpdocs for models
artisan ide-helper:models --dir="app/Entities"

# Generate IDE metadata
artisan ide-helper:meta

Setup Bower

bower init 

# Setup .bowerrc
mkdir -p resources/assets/bower

# {
#   "directory": "resources/assets/bower"
# }
vim .bowerrc

# Add bower directory to .gitignore
echo "resources/assets/bower" >> .gitignore

# Install third-party libraries
bower install --save timcreative/get-shit-done && \
bower install --save vue && \
bower install --save jquery && \
bower install --save bootstrap && \
bower install --save fontawesome && \
bower install --save webicon && \
bower install --save animateCSS && \
bower install --save sweetalert && \
bower install --save growl && \
bower install --save restive && \
bower install --save moment && \
bower install --save ajax-helper

Setup Elixir

mkdir -p resources/assets/js resources/assets/css resources/assets/img public/assets/packages
vim gulpfile.js
elixir(function(mix) {

    //
    // Local assets
    //
    mix.sass('resources/assets/sass/*.scss', 'public/assets/css');
    
    mix.copy('resources/assets/js', 'public/assets/js');
    mix.copy('resources/assets/css', 'public/assets/css');
    mix.copy('resources/assets/img', 'public/assets/img');

    //
    // Vuejs
    //
    mix.copy(
        'resources/assets/bower/vue/dist',
        'public/assets/packages/vue'
    );
    
    //
    // Gsdk
    //
    mix.copy(
        'resources/assets/bower/get-shit-done/assets',
        'public/assets/packages/gsdk'
    );

    //
    // Bootstrap
    //
    mix.copy(
        'resources/assets/bower/bootstrap/dist',
        'public/assets/packages/bootstrap'
    );

    //
    // Fontawesome
    //
    mix.copy(
        'resources/assets/bower/font-awesome/css',
        'public/assets/packages/font-awesome/css'
    );

    mix.copy(
        'resources/assets/bower/font-awesome/fonts',
        'public/assets/packages/font-awesome/fonts'
    );
    
    //
    // jQuery
    //
    mix.copy(
        'resources/assets/bower/jquery/dist',
        'public/assets/packages/jquery'
    );

    //
    // Webicon
    //
    mix.copy(
        'resources/assets/bower/webicon',
        'public/assets/packages/webicon'
    );

    //
    // AnimateCSS
    //
    mix.copy(
        'resources/assets/bower/animate.css/*.css',
        'public/assets/packages/animatecss'
    );

    mix.copy(
        'resources/assets/bower/animateCSS/dist/jquery.animateCSS.min.js',
        'public/assets/packages/animatecss/jquery-animatecss.min.js'
    );

    //
    // SweetAlert
    //
    mix.copy(
        'resources/assets/bower/sweetalert/dist',
        'public/assets/packages/sweetalert'
    );

    //
    // Growl
    //
    mix.copy(
        [
            'resources/assets/bower/growl/javascripts/jquery.growl.js',
            'resources/assets/bower/growl/stylesheets/jquery.growl.css'
        ],
        'public/assets/packages/growl'
    );

    //
    // Restive
    //
    mix.copy(
        'resources/assets/bower/restive/*.js',
        'public/assets/packages/restive'
    );

    //
    // AjaxHelper
    //
    mix.copy(
        'resources/assets/bower/ajax-helper/ajax-helper.js',
        'public/assets/packages/ajax-helper'
    );

    //
    // Moment
    //
    mix.copy(
        'resources/assets/bower/moment/min/*.js',
        'public/assets/packages/moment'
    );
    
});

Extend the structure

mkdir -p \
  app/Support \
  app/Entities \
  app/Services \
  app/Criterias \
  app/Validators \
  app/Presenters \
  app/Transformers \
  app/Repositories \
  app/Http/Forms
  
touch \
  app/Support/.gitkeep \
  app/Entities/.gitkeep \
  app/Services/.gitkeep \
  app/Criterias/.gitkeep \
  app/Validators/.gitkeep \
  app/Presenters/.gitkeep \
  app/Transformers/.gitkeep \
  app/Repositories/.gitkeep \
  app/Http/Forms/.gitkeep

Setup app helpers and constants

touch app/Support/helpers.php
touch app/Support/constants.php

vim composer.json
"autoload": {
  // ...
  "files": [
    "app/Support/helpers.php",
    "app/Support/constants.php"
  ]
},