where to put permission check #571
-
Hi guys, I'm having a question about where to put Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Hi @christmex , If what you want is to completely prevent the access of a CRUD page, the best place to put
Hope it helps. |
Beta Was this translation helpful? Give feedback.
-
Thanks, @tabacitu , another question is, I want to check before it inserts the data into the database to make sure everything is authorized, here's what I did, am I right to do this? //somewhere in entitiyCrudController
use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation { store as traitStore; }
public function store(){
if (!backpack_user()->can('something')) {
return redirect('/');
}
$response = $this->traitStore();
// do something after save
return $response;
} |
Beta Was this translation helpful? Give feedback.
-
Hey @christmex alternatively you can define it in a single place: The If you have in your controller: public function setupCreateOperation()
{
if (!backpack_user()->can('something')) {
CRUD::denyAccess('create');
}
} The user wouldn't be able to view the form, or submit the form. Yours do the same, but you need two overwrites, one for form display, another for form submission. Cheers |
Beta Was this translation helpful? Give feedback.
Hi @christmex ,
If what you want is to completely prevent the access of a CRUD page, the best place to put
backpack_user()->can()
is inside the CrudController. Since each Operation has its own setup method, that's the perfect place to do that:Hope it helps.
Cheers!