Permissions: how to set (leave untouched) default value of field

Hi - I want a Publisher Role to be able to edit everything of given record, but not the title field (and the slug field too - those 2 which are standard opening in a Modal for editing). In my Controller:
protected $fieldsPermissions = [
'title' => 'manage_settings',
];
protected $fieldsPermissions = [
'title' => 'manage_settings',
];
results that the Admin is able to save the record, a Publisher not. Even if the Publisher is only editing the description field, which is intended to do so. Basically I want to leave the title field untouched on save - or a complete different approach to handle that ? - support appreciated! Emil
1 Reply
emil
emilOP7d ago
sometimes I cannot find the one tree in the wood - just figured out that I have set a required validation rule on the FormRequest Class. So, ending up with this solution makes the thing working:
public function rulesForUpdate()
{
$titleRules = [
Rule::unique('pages', 'title')->ignore($this->route('category')),
Rule::unique('categories', 'title')->ignore($this->route('category')),
];

if (auth()->user()->can('manage_settings')) {
$titleRules[] = 'required';
}

return [
'title' => $titleRules,
'intro' => 'nullable|max:1200',
];
}
public function rulesForUpdate()
{
$titleRules = [
Rule::unique('pages', 'title')->ignore($this->route('category')),
Rule::unique('categories', 'title')->ignore($this->route('category')),
];

if (auth()->user()->can('manage_settings')) {
$titleRules[] = 'required';
}

return [
'title' => $titleRules,
'intro' => 'nullable|max:1200',
];
}

Did you find this page helpful?