Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Reusing a Controller method for multiple actions in Laravel - SimplestWeb (
<div class="modal" id="modalEditUser" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="mb-0">Edit User - {{ $edit->name }}</h5>
<div class="modal-body">
<form method="POST" action="{{ route('users.update', ['users' => $edit->id]) }}">
{{-- Your usual form to edit user's detail --}}
window.addEventListener('DOMContentLoaded', function (e) {
{{-- All your other markup to display users --}}
{{-- Below shows a way to add the parameter to the url --}}
<a href="{{ route('users.index', ['edit' => $user->id]) }}">Edit User</a>
{{-- The template the model is included only when the veriable is set --}}
@includeWhen($edit, 'modals.users.edit')
class UsersController
// ......
public function index(Request $request) {
$edit = null;
// We check if the edit parameter is set, if so we find the user with that ID
// This $edit variable can be used in our template
if ($request->has('edit')) $edit = User::where('id', $request->query('edit'))->first();
$users = User::all();
return view('users.index', compact('users', 'edit'));
// ......
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.