Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Alyve's avatar
Level 3

Authorization to update a few attributes only

Hello,

I'm looking for a way to set authorization to update only a selection on field. For example, a thread can't be updated by a user.

I tried to create a new rule and add it to a request like this:

The rule:

public function passes($attribute, $value)
    {
        return Auth::user()->isModeratorOrAdmin();
    }

The FormRequest:

public function rules()
    {
        return [
            'title' => 'required|min:3|max:140',
            'category_id' => 'required|exists:categories,id',
            'content' => [
                'required',
                Rule::requiredIf(function () {
                    dd($this->route('threads.store'));
                })
            ],
            'pinned' => [
                'optional',
                new OnlyStaffRule(),
            ]
        ];
    }

It doesn't work and I don't find any way to perform this operation. Maybe someone can help me, please ?

Thank you.

Alyve

0 likes
2 replies
Alyve's avatar
Level 3

Hello,

Thank you for your answer, it helps me a lot. :)

Please or to participate in this conversation.