I have some problems with my auth middleware. I want to protect my routes with it, but in some controllers it dosent work really. If I check the routes as logout user, I got different error messasges instead of blocking the access and redirect to the login page. I use the middleware always over the __construct() in the controllers.
An example.
Controller
public function show(Dialog $dialog)
{
return $this->template($dialog, self::DISPLAY_MODE_DIALOG);
}
protected function template(Dialog $dialog, $displayMode, $messageLimit = 10)
{
$user = Auth::user();
// Check if the profile is currently controlled by the current user
$isControlled = $dialog->moderator()->appProfile()->isControlledBy($user->id);
$messageList = $dialog->latestMessages($messageLimit);
return view('dialog.chat.template')
->with(compact('dialog', 'messageList', 'isControlled', 'displayMode'));
}
Model
public function isAccessibleBy(User $user)
{
$profile = $this->moderator()->appProfile();
return $profile->isOwner($user->id)
|| $profile->isControlledBy($user->id);
}
Error
Argument 1 passed to App\Model\Dialog\Dialog::isAccessibleBy() must be an instance of App\Model\Account\User, null given, called in C:\projekte\php\newchat\app\Model\Dialog\Dialog.php on line 332 and defined
Now I realize why this happens, but i think the middleware should dont show this messages an protecte the route.
http://laravel.com/docs/5.0/middleware
"However, if the user is authenticated, the middleware will allow the request to proceed further into the application."
code
public function __construct() { $this->middleware('auth); }code
– ToyRoboticisAccessibleBy(User $user = null)
... Thenif($user) ...
set accessible, return false if the user is null – Iamzozo