I'm studying CURD with Laravel8
I use a sample index.blade.php This work really fine. so I'm trying to add new page which I made that is simple.blade.php.
I wrote below code but when I open http://127.0.0.1:8000/products/simple I got 404 NOT found error. Could you teach me right code please?
Controller
public function index()
{
$products = Product::latest()->paginate(5);
return view('products.index',compact('products'))
->with('i', (request()->input('page', 1) - 1) * 5);
}
public function simple()
{
$products = Product::latest()->paginate(15);
return view('products.simple',compact('products'))
->with('i', (request()->input('page', 1) - 1) * 5);
}
WEB.php
// This is index.blade.php
Route::resource('products', ProductController::class);
// This is my page which I added
Route::get('products.simple', [ProductController::class, 'simple']);
UPDATE I use this gentleman's awesome code
https://github.com/savanihd/Laravel-8-CRUD/blob/master/app/Http/Controllers/ProductController.php
UPDATE 2 error log
404
Not Found
No query results for model [App\Models\Product]
simpleC:\xampp\htdocs\lara\lara-test\vendor\laravel\framework\src\Illuminate\Routing\ImplicitRouteBinding.php#47Illuminate\Database\Eloquent\ModelNotFoundException
throw (new ModelNotFoundException)->setModel(get_class($instance), [$parameterValue]);
}
} elseif (! $model = $instance->resolveRouteBinding($parameterValue, $route->bindingFieldFor($parameterName))) {
throw (new ModelNotFoundException)->setModel(get_class($instance), [$parameterValue]);
}
$route->setParameter($parameterName, $model);