I am trying to navigate to my "productdetail" page but it givdes me a 404. The route to productdetail does exists. I am trying to give product information from shop to productdetail
My controller:
<?php
namespace App\Http\Controllers;
use DB;
use Illuminate\Http\Request;
use App\Product;
class ProductsController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function shopindex()
{
$productsOTs = DB::select(DB::raw("SELECT * FROM wiz.productimages WHERE Afkorting = 'PPI' LIMIT 83, 3"));
return view('shop', compact('productsOTs'));
}
public function productdetail(Product $Product)
{
return view('Products.productdetail', compact('productsOT'));
}
}
My shop page link to productdetail:
@foreach ($productsOTs as $productsOT)
<div class="card ot-product" id="heightwidthfix">
<img class="card-img-top cardstop" src="{{$productsOT->imagelink}}" alt="Card image cap" id="myshopmodal1" height="400px" width="300px">
<div class="card-body">
<h5 class="card-title">{{$productsOT->Productomschrijving}}</h5>
<p class="card-text">Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p>
</div>
<div class="card-body">
<a href="/shop/productdetail/{{ $productsOT->Productcode }}" class="card-link">Bekijk hier het product</a>
</div>
</div>
@endforeach
My routes:
Route::get('/shop', ['middleware' => 'auth', 'uses' => 'ProductsController@shopindex']);
Route::get('/shop/productdetail/{product}', ['middleware' => 'auth', 'uses' => 'ProductsController@productdetail']);
I have been struggling with this problem for a while now, i hope someone can help me.
By adding the . htaccess file at the same folder location of the index. php it solves the 404 page not found error in my laravel Project.
Create Custom 404 Error Page You need to create blade views for error pages, move to this path resources/views/ inside here create errors folder and within the directory create 404. blade. php file. It will redirect you to the 404 page if you don't find the associated URL.
Essentially, the “404 error” indicates that your or your visitor's web browser was connected successfully to the website server or the host. However, it was unable to locate the requested resource, such as filename or any specific URL.
By adding the .htaccess file at the same folder location of the index.php it solves the 404 page not found error in my laravel Project. make sure, the url passed is equal in your route. check the parameters and action in the form. To get clear answer post your mvc
The first thing I suggest trying is running php artisan route:list from the command line (from your project root directory). This will list all the routes that Laravel can register and if there are any errors, usually they will show up here. The second thing I suggest is to ensure that the URL matches route.
Your Laravel application is currently using an out-dated routes cached file located in app/bootstrap/routes-x.php file instead of your routes files located in app/routes directory. manualy delete app/bootstrap/routes-x.php file.
If for some reason your users landed on a URL that does not exist, you should have a well-designed 404 page so visitors can easily navigate to the other pages. On this 404 error page, you can display the site logo, search form, other page links, etc.
Why don't you try to put a name for your route
Route::get('/shop/productdetail/{product}', ['middleware' => 'auth', 'uses' => 'ProductsController@productdetail'])->name('show-product');
then call it through it's name:
<a href="{{route('show-product',$productsOT->Productcode) }}" class="card-link">Bekijk hier het product</a>
This will might solve your problem otherwise the problem is not on the route.
Change this line:
<a href="/shop/productdetail/{{ $productsOT->Productcode }}" class="card-link">Bekijk hier het product</a>
into
<a href="{{ url('shop/productdetail/'.$productsOT->Productcode) }}" class="card-link">Bekijk hier het product</a>
This is the minor mistake. Change this, I hope it is helpful. Thanks
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With