In this case, it would be best to use an Accessor in the Model to determine whether or not the edit button should be displayed. The Accessor can take in any necessary parameters (such as the current user) and return a boolean value based on the conditions outlined in the question.
Here's an example of what the Accessor could look like:
public function getCanEditAttribute()
{
$currentUser = auth()->user();
$postAge = Carbon::parse($this->created_at)->diffInDays();
if ($postAge <= config('app.edit_post_age_limit') && $this->editor_id === $currentUser->id && ($this->category === 'X' || $this->category === 'Y') && $this->another_condition && $this->yet_another_condition) {
return true;
}
return false;
}
This Accessor checks if the post is not older than a certain number of days (as defined in the app config), if the current user is the editor, if the post belongs to category X or Y, and if there are additional conditions that are met. If all of these conditions are true, the Accessor returns true, indicating that the edit button should be displayed. Otherwise, it returns false.
In the Blade view, you can then use the Accessor like this:
@if ($post->canEdit)
<button>Edit</button>
@endif
This will only display the edit button if the Accessor returns true.