Thursday, October 22, 2015

Page redirection according role in laravel 5 . *>

In AuthController make a function and make a redirectPath function which will replace redirectPath function which in RedirectsUsers traits

//following custom function assign for redirection page according role
    public function redirect_to_desired_page_according_role(){
        $user = Auth::user();
        if ($user->isAdmin()) {
            return '/master';
        } elseif ($user->isTrainer()) {
            return '/public_trainings';

        } elseif ($user->isTrainee()) {
            return '/bardtrainer';

        } elseif ($user->isMonitor()) {
            return '/clients';
        }
    }


    //following function will replace the function which is in RedirectsUsers traits
    public function redirectPath()
    {
        if (property_exists($this, 'redirectPath')) {
            return $this->redirectPath;
        }

        return property_exists($this, 'redirectTo') ? $this->redirectTo : $this->redirect_to_desired_page_according_role();
    }

In RedirectIfAuthenticated.php change the handle function like following


public function handle($request, Closure $next)
    {
        if ($this->auth->check()) {
            return redirect((new AuthController())->redirect_to_desired_page_according_role());
        }

        return $next($request);
    }

Friday, October 2, 2015

laravel Oct-3

//to make a foreign key 
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
//to make a table unsigned
$table->integer('user_id')->unsigned();
//to make a table nullable()
$table->string('slug')->nullable();
//to give default value in laravel
$table->tinyInteger('status')->default(1);
//what is unsigned?
The table column which is unsigned you can't insert negetive value

//to create a relation with users and tickets table Put in to User MOdel
public function tickets(){
        return $this->hasMany('App\Ticket');
    }

//================Tinker tutorial
//==to insert
php artisan tinker
$user = new App\User;
$user->name = 'polo';
$user->email = 'polodev10@gmail.com';
$user->password = bcrypt('1234');
$user-> save();

//==to view();
$user = App\User::first();
$user = App\User::firstOrFail();
$user = App\User::all();
$user = App\User::where('id', 1)->get();
$user = App\User::whereId(1)->get();

css snippet for blogger code highlighting

code, .code {     display: block;     background: beige;     padding: 10px;     margin: 8px 15px; }