Start laravel 5 framework Reviewed by Momizat on . Install composer create-project --prefer-dist laravel/laravel projectname Database connection projectname/config/database.php if not connected please check this Install composer create-project --prefer-dist laravel/laravel projectname Database connection projectname/config/database.php if not connected please check this Rating: 0

Start laravel 5 framework

  • Install

    composer create-project –prefer-dist laravel/laravel projectname

  • Database connection

    projectname/config/database.php

    if not connected please check this file for environment. projectname/.env

    then Run command to clear cache :- php artisan config:clear

    mysql' => [
                'driver'    => 'mysql',
                'host'      => env('DB_HOST', 'localhost'),
                'database'  => env('DB_DATABASE', 'forge'),
                'username'  => env('DB_USERNAME', 'forge'),
                'password'  => env('DB_PASSWORD', 'forge'),
                'charset'   => 'utf8',
                'collation' => 'utf8_unicode_ci',
                'prefix'    => '',
                'strict'    => false,
            ],                            
                            

  • Check Permission of projactname/storage folder

    if not display “Laravel 5″ then use this command
    chmod 777 -R storage/

  • Change default message
    • Goto check view file from routes.php:-projectname/app/Http/routes.php
    • Goto view folder to change default message:-projectname/resources/views/welcome.blade.php
  • Create controller
    • Simple Controller
      • Goto Controllers folder from Users.php:-projectname/app/Http/Controllers
      • Goto write route for this controller from routes.php:-projectname/app/Http/routes.php
                                                Route::get('user/{id}', 'Users@show');
                                                
      • Create a controller
         
        
        
        namespace App\Http\Controllers;
        
        use App\User;
        use App\Http\Controllers\Controller;
        
        class Users extends Controller
        {
            /**
             * Show the profile for the given user.
             *
             * @param  int  $id
             * @return Response
             */
            public function show($id)
            {
                return view('welcome');
            }
        }                                                                                      
                                                    
                                                
    • Moduler Controller
      • Goto Controllers folder from Users.php:-projectname/app/Http/Controllers/Admin/
      • Goto write route for this controller from routes.php:-projectname/app/Http/routes.php
                                                Route::get('users', 'Admin\Users@show');
                                                
      • Create a controller
                                                   
        
                                                    
        
        namespace App\Http\Controllers\Admin;
        
        use App\User;
        use App\Http\Controllers\Controller;
        
        class Users extends Controller
        {
            /**
             * Show the profile for the given user.
             *
             * @param  int  $id
             * @return Response
             */
            public function show()
            {
                return view('manish');
            }
        }                                         
                                                    
                                                
  • Print Query String
            \DB::enableQueryLog();
            $flights = \DB::table('album')
                    ->rightJoin('tbl_admin', function ($join) {
                        $join->on('tbl_admin.id', '=', 'album.id')
    //                            ->orOn('tbl_admin.name', '=', 'album.title')
    //                            ->where('album.id', '>', 2)
    //                            ->whereNull('album.title')
    
                        ;
                    })
    //                ->whereRaw('tbl_admin.name = album.title')
                    ->groupBy('tbl_admin.id')
                    ->orderBy('tbl_admin.name', 'desc')
                    ->get();
    
            $query = \DB::getQueryLog();
            
            print_r($query);
            die;                            
                            

  • Routes

    Laravel provide many types of routes Like group,get,post,put,patch,match,any,resource,controller,domain,where,name etc.

    Route::get('user/{id}/{name?}', function ($id, $name) {
        //
    })
    ->where(['id' => '[0-9]+', 'name' => '[a-z]+']);
    
    Route::get('/', function () {
        return view('default/manish');
    });
    Route::group(['domain' => 'admin.localhost'], function () {
        Route::get('/', function () {
            return "This will respond to requests for 'admin.localhost/'";
        });
    });
    
    Route::get('/ip', ['middleware' => 'ad', function() {
        return "IP";
    }]);
    
    //Route::get('/', function () {
    //    $res = \App\Admin\Users::all();
    //    if ($res) {
    //        $res = $res->toArray();
    //    } else {
    //        $res = array();
    //    }
    //    return Response::json($res);
    //
    //});
    Route::resource('usee', 'Admin\Users');
    //Route::controller('usse', 'Admin\Users');
    $view = View::make('welcome')->with('name', 'Steve');
    View::share('name', 'Manish');
    Route::get('/kk', 'Admin\Users@show');
    Route::get('/manish', function () {
    //    return Redirect::intended();
    //    return View::make('welcome')->nest('name', 'default.manish');
    });
    Route::get('users', 'Admin\Users@show');
    Route::match(['get', 'post'], 'users/add', 'Admin\Users@add');
    //Route::get('users/add', 'Admin\Users@add');
    //Route::post('users/edit/{id}', 'Admin\Users@edit');
    Route::match(['get', 'post'], 'users/edit/{id}', 'Admin\Users@edit');
    Route::get('users/delete/{id}', 'Admin\Users@delete');
    Route::get('user/{id}', 'Users@show'); 
    
    Route::group(['namespace' => 'Admin'], function()
    {
        // Controllers Within The "App\Http\Controllers\Admin" Namespace
    
        Route::group(['namespace' => 'User'], function()
        {
            // Controllers Within The "App\Http\Controllers\Admin\User" Namespace
        });
    });                
                            

  • Middleware

    create a middleware using this command :- php artisan make:middleware middlewareNAme;

    • To register your middleware in kernal then goto :- projectname/app/Http/Kernel.php
    • add your created middleware
      protected $middleware = [
              \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
              \App\Http\Middleware\EncryptCookies::class,
              \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
              \Illuminate\Session\Middleware\StartSession::class,
              \Illuminate\View\Middleware\ShareErrorsFromSession::class,
              \App\Http\Middleware\VerifyCsrfToken::class,
              \App\Http\Middleware\middlewareNAme::class,//here add this line
          ];
       protected $routeMiddleware = [
              'auth' => \App\Http\Middleware\Authenticate::class,
              'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
              'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
              'ad' => \App\Http\Middleware\middlewareNAme::class,//here add this line
          ];                                
                                      
    • call middleware in routes.php as your requirement
      Route::get('/test', ['middleware' => 'ad', function() {
          return "test";
      }]);                                    
                                          
    • set conditions as your requirement

      Goto:-\App\Http\Middleware\middlewareNAme.php

      public function handle($request, Closure $next)
          {
              echo "<pre>";print_r($next);die;
              echo "<pre>";print_r($request->server());die;
              return $next($request);
          }                                        
                                              

Leave a Comment

© 2014 Powered By