How to Custom Url After Login Laravel 5.6
Assalamualaikum wr wb
Hello guys, i have problem when i create autenthicate system with laravel 5.6. I create with php artisan make:auth. After a few days, i want to create custom url after login my project. But my code is error and i searching in stackoverflow then i find this thread.
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
// protected $redirectTo = '/home';
// protected $redirectTo = '/mahasiswa';
protected function authenticated(Request $request, $user)
{
if ( $request->user()->role =='admin' ) {// do your margic here
return redirect('/admin');
}
return redirect('/mahasiswa');
}
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
}
Hello guys, i have problem when i create autenthicate system with laravel 5.6. I create with php artisan make:auth. After a few days, i want to create custom url after login my project. But my code is error and i searching in stackoverflow then i find this thread.
[Laravel 5.6] How to Fix SQLSTATE[42000]: Syntax error or access violation: 1055You can solved your problem with this code.
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
// protected $redirectTo = '/home';
// protected $redirectTo = '/mahasiswa';
protected function authenticated(Request $request, $user)
{
if ( $request->user()->role =='admin' ) {// do your margic here
return redirect('/admin');
}
return redirect('/mahasiswa');
}
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
}
If you solved your problem, please comment.
Free Templates Blogger
Thanks for reading How to custom url after login laravel, see you in the next articles.
0 Response to "How to Custom Url After Login Laravel 5.6"
Post a Comment
1. Berikan Komentar yang Relevan
2. Tidak Mengandung SARA
3. Berkomentar yang Sopan