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

rudolfbruder's avatar

How to manage different form views based on access and column value

I am facing and problem that I would like to solve using laravel. I want to make items in the system with several columns. Once this item reaches specified status and is pending at specific user it can be edited. However there will be many edit views based on access rights and statuses. What is the best way to solve this via laravel?

I had these suggestions:

Solve this within middleware during calling the edit method Solve this within several @if @else commands in edit.blade.php file Solve this via many different routes and methods and many views What i would like to achieve is that if proper users opens the edit link proper view is loaded and if not then user is redirected to some kind of "no acces" page or simple display view.

0 likes
1 reply
bobbybouwmann's avatar

I would probably do most of this stuff in the controller. So in your controller, you check what kind of user you have. Based on that you collect the data and then return a specific view for that.

public function edit(Model $model)
{
    if (can('editAsAdmin', $mode)) {
        return view('models.edit', compact('model'));
    }

    if (can('setName', $model)) {
        $name = $model->name;

        return view('models.edit.name', compact('name'));
    }
}

Well you get the idea. What you can do is split this in to separate methods and so on to keep it clean.

You can reuse the same view, but then you have a lot of if statements in both your controllers and views. On the other side, you will have a lot of small views which you need to maintain as well.

I would just play around with it and see whatever works best for you ;)

Please or to participate in this conversation.