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

Sung's avatar
Level 1

Middleware or Validation on deleting?

Hi guys!

I have a question regarding when to use middleware or validation?

In my case I want to validate if a given user is allowed to DELETE a post. As far as I know, I could either setup a middleware on that specific DELETE-route or utilize the authorize()-function within a validation request class.

What is the right thing to do in my case?

0 likes
3 replies
helmerdavila's avatar

Use middleware can be fired before the request (and you can post code before that request).

sukonovs's avatar

You can use middleware on controller method or route. Validation is... validation, checking if input is valid and can be saved or manipulated.

larabala's avatar

my solution for this. ofc in form request.

public function authorize()
    {
        return (\App\Event::findOrFail($this->route()->parameter('events'))->user_id == \Auth::user()->id);
    }

Please or to participate in this conversation.