Domanda

I'm not sure of the terminology I should be using so please bear with me, hopefully if I haven't got this right, someone might be able to tease the right question out!

ok.. so I have

 Route::resource('gameworlds', 'GameworldsController');

This is fine. There are views for create, edit, index and show as you would expect and they all work fine. What I would like to do is only allow access to the "create" part when a user is logged in.

For example.. I have another route in my routes.php file:

Route::get('dashboard', array('before' => 'auth', function()
    return View::make('dashboard/index');
 }));

This works as expected, but I don't really understand how I can put similar code in the resource route for the "create" part only. Can someone explain that part to me please?

Many thanks.

DS

È stato utile?

Soluzione

Well you don't need a filter, but instead you can use the Auth check method to check if user is logged in or not:

if (Auth::check()) { //Logged in }

In your controller method to make sure the user is logged in, and if he isn't you can do a redirect, like:

return Redirect::to('user/login');

However if you want to use a filter you could use the beforeFilter method in the __construct of your controller, like this:

public function __construct()
    {
        $this->beforeFilter('auth', array('on' => array('create')));
    }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top