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

oyazigi's avatar

Pass data gotten from a view to another view

I'm building on laravel, a userlist, so far i could list all the users of the website, and i also have a delete and an edit button, i'm using this view:

which gets data from this controller:

<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\User;
use App\Models\Cargo;
use Illuminate\Support\Facades\Auth;
class UserController extends Controller
{
    public function show(Request $request){
        $users = User::all();
        $roles = Cargo::all()->keyBy('id');
        $user = Auth::user();
        if(isAdmin($user)){
            return view('userlist', compact('users', 'roles'));
        }           
        return response('Unauthorized.', 401);
    }
}

but now i'm wondering how will i proceed to program these two buttons for editing or removing a user, i know i'd maybe need to redirect the user to another route, which would communicate to a controller and render a view, but that view should have the context of which user i choosed to edit or delete, what is the best approach for me?

0 likes
1 reply

Please or to participate in this conversation.