I have a resource controller Items
:
Route::resource('items', 'ItemsController');
And in action ItemsController@store
for creating new item i'm need to activate CSRF filter
(and maybe Auth filter
) before actions with form. But i can't write
$this->beforeFilter('csrf')
it doesn't works. It works when I put this calling in parent Controller's __construct()
.
What I need to do to call some filters directly for resource controller actions?
You should be able to use the filters for specific actions only by setting it in the __construct()
like this:
class ItemsController extends BaseController
{
public function __construct()
{
$this->beforeFilter('csrf', array('on' => 'store') );
}
//rest of controller...
}
Note - You can also use the keywords "only" and "except" and pass an array of action names to apply (or negate) the filter for more than one action.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With