@mehmetanbaki Where is role() defined? If you are following the Eloquent example, are you sure you didn't define it as roles()?
Roles issue
BadMethodCallException Method Illuminate\Auth\SessionGuard::role does not exist. http://127.0.0.1:8000/login
This appear to me when I try to logged in with role
this is the code :
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller; use App\Providers\RouteServiceProvider; use Illuminate\Foundation\Auth\AuthenticatesUsers; use Illuminate\Support\Facades\Auth; use App\Role;
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 = RouteServiceProvider::HOME;
protected function redirectTo(){
if (Auth::role()->role_name == 'admin') {
return route('dashboard');
} elseif (Auth::role()->role_name == 'accountant') {
return route('main');
} elseif (Auth::role()->role_name == 'customer') {
return route('index');
} else {
return redirect('/login')->with('status', 'يرجى إدخال إسم المستخدم وكلمة المرور');
}
}
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
}
Please or to participate in this conversation.