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

Ain's avatar
Level 1

Error 404 Not found

Im trying to reach the edit page of sales, but it display 404 not found. But the rest of the routes are working so well, except for this one.

route

Route::resource('/sales', 'SaleController');

index.blade.php

{{--Display name--}}
<td><a href="{{route('sales.edit', $sale)}}">{{$sale->name}}</a></td>

controller

public function edit(Sale $sales)
   {
       $id = $sales->id;

       $sales = Sale::findOrFail($id);

       return view ('sales.edit', compact ('sales'));
   }

this is the position of the blade https://imgur.com/a/dy6y7xv

0 likes
3 replies
ftiersch's avatar
$id = $sales->id;

$sales = Sale::findOrFail($id);

Not quite sure why you are getting the sale from the database again if you got the id from a Sale object right before that :D

I don't usually use resource controllers but maybe the / in '/sales' is the problem?

The view isn't the problem. With a 404 it's one of the following:

  1. Your URL cannot be found
  2. The ID of the sale is not in the database (like you are calling /sales/10 but ID 10 doesn't exist)
  3. Again the ID of the sale is not in the database when you use findOrFail. Both do the same thing so you don't need that.
janosk's avatar

One more tip regarding the resource controller. In your controller's edit function you pass through the model with route-model binding (Sale $sales) but i think it should be $sale (singular). That is the way or pattern Laravel generates the routes. But just to be sure, check your routes with the

php artisan route:list

command and look for that edit route, similar to this:

GET|HEAD  | sales/{sale}/edit  | sales.edit | App\Http\Controllers\SaleController@edit

The value between the {} chars has to be the same you pass in the controller.

Snapey's avatar
Snapey
Best Answer
Level 122

change the controller:

public function edit(Sale $sale)
{
    return view ('sales.edit', compact ('sale'));
}

and then set the view up to expect $sale not $sales

Please or to participate in this conversation.