0
I am with an application where users can see or not certain system module according to their permissions. These permissions are saved to the database in a way N:N and managed in UserPolicy
, as an example:
Userpolicy.php
public function viewReports(User $user)
{
foreach($user->module as $m){
if($m->id === 3)
return true;
}
}
Userpolicytest.php
public function testCanViewReports()
{
$user = factory(User::class)->make();
$user->module()->sync([3]);
$this->assertTrue($user->can('viewReports', User::class));
}
The test passes, only the data recorded with $user->module()->Sync([3]); are recorded in the database (in the table user_module
).
How do I make sure that records are deleted, or don’t need to be created in the database?
For me it was not clear, user_module is the link tablet enter the module and the user. Your question is: how to NO use this table and still have the link between user and module? Or got it wrong.
– Ricardo Lucas