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

vincent15000's avatar

Route not found

Hello,

I have defined these routes.

Route::post('users/invite', [UserController::class, 'invite'])->name('users.invite');
Route::post('users/{user}/invite', [UserController::class, 'invite'])->name('users.invite-one');
Route::post('users/{user}/send-reset-password-link', [UserController::class, 'sendResetPasswordLink'])->name('users.send-reset-password-link');
Route::post('users/synchronize', [UserController::class, 'synchronize'])->name('users.synchronize');
Route::get('users/{user}/team/edit', [TeamController::class, 'edit'])->name('users.team.edit');
Route::put('users/{user}/team', [TeamController::class, 'update'])->name('users.team.update');
Route::put('users/{user}/restore', [UserController::class, 'restore'])->name('users.restore');
Route::resource('users', UserController::class);

Why is this route not found ?

Route::put('users/{user}/restore', [UserController::class, 'restore'])->name('users.restore');

I have defined it before the resource ones and I don't think that there is a conflict with another route.

Furthermore it's found when displaying the submit button in the view, but not found when I click on the button to submit the form.

Any idea ?

Thanks for your help.

V

0 likes
4 replies
LaryAI's avatar

The issue is likely related to the way Laravel's resource routes work and how route model binding interacts with soft-deleted models.

Common Causes

  1. Resource Route Conflict
    Even though you defined your custom route before the Route::resource('users', UserController::class);, resource routes can still cause conflicts, especially if the {user} parameter is not matching as expected.

  2. Route Model Binding with Soft Deletes
    If your User model uses soft deletes (use SoftDeletes;), then by default, Laravel's route model binding will not retrieve soft-deleted models. So, if you're trying to restore a soft-deleted user, the {user} parameter will not resolve, and the route will not be found.

Solution

1. Explicitly Bind Soft Deleted Models

You need to tell Laravel to include soft-deleted models when binding the {user} parameter. You can do this in your RouteServiceProvider:

use App\Models\User;
use Illuminate\Support\Facades\Route;

public function boot()
{
    parent::boot();

    Route::bind('user', function ($value) {
        return User::withTrashed()->where('id', $value)->firstOrFail();
    });
}

2. Double-check the Form Method and Route Name

Make sure your form is using the correct HTTP method (PUT) and the correct route name:

<form method="POST" action="{{ route('users.restore', $user->id) }}">
    @csrf
    @method('PUT')
    <button type="submit">Restore</button>
</form>

3. Check for JavaScript or Frontend Issues

If the route is found when rendering the form but not when submitting, ensure that:

  • There are no JavaScript errors hijacking the form submission.
  • The form is not being submitted via AJAX to a different URL/method.

4. Verify Route List

Run php artisan route:list and check that your users/{user}/restore route is present and not shadowed by a resource route.

Summary

The most common cause in your scenario is soft-deleted users not being resolved by route model binding. Use withTrashed() in your route binding to fix this.

Let me know if you need more help!

JussiMannisto's avatar

It might be related to the PUT method. Can you show the form code?

1 like

Please or to participate in this conversation.