Policies controls

Hello 😊 I have a page named "TeamVehicle" and before showing it, I wanted to check if there is any package related to "TeamPackage". I checked if a package was created below. What I want to know is whether the code I wrote below is correct or not. And actually this works without any problems. I wanted to learn this so I could write cleaner and smoother code.
// TeamVehiclePolicy.php

public function create(User $user): bool
{
$teamPackage = TeamPackage::query()
->where('is_active', true)
->where('team_id', filament()->getTenant()->id)
->get();

if ($teamPackage->count() > 0) {
return true;
}

return false;
}
// TeamVehiclePolicy.php

public function create(User $user): bool
{
$teamPackage = TeamPackage::query()
->where('is_active', true)
->where('team_id', filament()->getTenant()->id)
->get();

if ($teamPackage->count() > 0) {
return true;
}

return false;
}
2 Replies
tuto1902
tuto1902β€’3w ago
Looks OK to me. Does it throw any errors or does it actually do what you expect?
Eno7x
Eno7xOPβ€’3w ago
Thank you for reviewing. Oh yes it works flawlessly.
Want results from more Discord servers?
Add your server