我在laravel helper类中创建了一个函数来检查
p> 在我的控制器中 p>
如果没有记录,我希望它重定向到登录路由,但它加载 如何使用此消息重定向到登录路线? p> \ n div> app / lib / Auth.php中的身份验证 代码> p>
类自动扩展\ BaseController {
公共静态函数记录(){
if(Auth: :check()){
return true;
} else {
$ message = array('type'=>'error','message'=>'您必须登录才能查看此页面! ');
返回Redirect :: to('login') - > with('notification',$ message);
}
}
}
code> pre>
类DashboardController extends \ BaseController {\ n
/ **
*显示资源列表。
*
* @return响应
* /
公共函数索引()
{
Not :: logged();
返回View :: make('dashboard.index');
}
code> pre>
dashboard.index code>视图,其中包含“您必须登录才能查看此页面!”。 p>
I have created function in laravel helper class to check Authentication in app/lib/Auth.php
class Auto extends \BaseController {
public static function logged() {
if(Auth::check()) {
return true;
} else {
$message = array('type'=>'error','message'=>'You must be logged in to view this page!');
return Redirect::to('login')->with('notification',$message);
}
}
}
In my controller
class DashboardController extends \BaseController {
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
Auto::logged();
return View::make('dashboard.index');
}
I expect it redirect to login route if not logged, but it load dashboard.index
view with message 'You must be logged in to view this page!'.
How can I redirect to login route with this message?