Level 56
When I need something similar I usually move the checks inside the policy, something like this:
class ReplyPolicy
{
public function delete(User $user, Reply $reply)
{
if ($reply->isForThread()) {
return ...;
}
if ($reply->isForComment()) {
return ...;
}
if ($reply->isForMessage()) {
return ...;
}
return false;
}
}
Where the isForThread(), isForComment(), and isForMessage() are helper methods in the Reply class which let you check the related model, ssomething like this:
public function isForThread() {
return $this->model_type === Thread::class;
}
Then you don't need to worry about the related class when authorizing actions on a Reply instance
$this->authorize('delete', $reply);
Hope this helps.