Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 404 page not found, route exists

Tags:

php

laravel

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.

like image 812
slekniws Avatar asked Dec 10 '18 09:12

slekniws


People also ask

How to fix error 404 not found in Laravel?

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.

How do I change to 404 in laravel?

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.

What is 404 not found nginx?

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.

How to solve 404 Page Not Found error in Laravel?

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

How do I register a route in Laravel?

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.

Why are my Laravel routes not working?

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.

What to do if a URL does not exist in WordPress?

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.


Video Answer


2 Answers

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.

like image 90
Dearwolves Avatar answered Sep 18 '22 12:09

Dearwolves


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

like image 32
Inzamam Idrees Avatar answered Sep 19 '22 12:09

Inzamam Idrees