It should still be safe. But personally I would not auto append it as you might not want it in every single query that uses the project model. Just append it when you need it
$path->projects->append('can_delete');
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello,
I have read the documentation for the authorizations.
https://inertiajs.com/authorization
I have tried to do that.
$path->load('level', 'projects.level');
$path->projects->each(function ($project, $key) {
$project->can_delete = auth()->user()->can('delete', $project);
});
return Inertia::render('Paths/Show', compact('path'));
But what about simplifying this and adding an appended property to the model ?
protected $appends = ['can_delete'];
...
public function getCanDeleteAttribute()
{
return auth()->user()->can('delete', $this);
}
Is it a good idea and does it remain secure ?
Thanks for your answer ;).
V
It amounts to the same thing really, there will be a can_delete property available on the model instance. But the downside of this approach is you are mixing the HTTP layer with the model logic. You should be able to interact with the model without an authenticated user; but this approach bakes it in.
Personally I prefer Eloquent API resources for this because it represents the Model instance(s) but stays in the HTTP layer of the application.
Please or to participate in this conversation.