Redirection in laravel without return statement

后端 未结 3 1719
伪装坚强ぢ
伪装坚强ぢ 2021-02-06 03:47

i have this blogsController, the create function is as follows.

public function create() {
  if($this->reqLogin()) return $this->reqLogin();
  return View:         


        
3条回答
  •  别那么骄傲
    2021-02-06 04:15

    You should put the check into a filter, then only let the user get to the controller if they are logged in in the first place.

    Filter

    Route::filter('auth', function($route, $request, $response)
    {
        if(!Auth::check()) {
           Session::flash('message', 'You need to login');
           return Redirect::to("login");
        }
    });
    

    Route

    Route::get('blogs/create', array('before' => 'auth', 'uses' => 'BlogsController@create'));
    

    Controller

    public function create() {
      return View::make('blogs.create');
     }
    

提交回复
热议问题