MateoG98
MateoG98

Reputation: 179

404 Not found Laravel8

I used to code with this framework in the oldest versions but now it been difficult for me to understand its documentation regarding routes and links in the blade so I need some help.

These are my routes web.php

use App\Http\Controllers\UsuarioController;
use App\Http\Controllers\PeliculaController;
use Illuminate\Support\Facades\Route;

Route::get('/pelicula', [PeliculaController::class, 'index'])->name('pelicula');
Route::get('/detalle', [PeliculaController::class, 'detalle'])->name('pelicula.detalle');

This is my PeliculaController with my methods:

namespace App\Http\Controllers;
use Illuminate\Http\Request;

class PeliculaController extends Controller {
    public function index() {
        $titulo = 'Listado de mis peliculas';
        return view('pelicula.index', [
            'titulo' => $titulo
        ]);
    }

    public function detalle() {
        return view('pelicula.detalle');
        die();
    }
}

detalle.blade.php:

<a href="{‌{ route('pelicula') }}">Ir al listado</a>

index.blade.php:

<a href="{‌{ route('detalle.pelicula') }}">Ir al detalle</a>

The issue is the following when I run my project and click on the hyperlink of detalle.blade.php the page is not found. I couldn´t shorten more my code due that I want to understand what I'm doing wrong because one link works and the other doesn´t it just shows de 404 Not Found error.

Upvotes: 0

Views: 53

Answers (2)

Hedayatullah Sarwary
Hedayatullah Sarwary

Reputation: 2834

First, you have called the wrong route name, try to use the below code:

web.php

Route::get('/detalle', [PeliculaController::class, 'detalle'])->name('pelicula.detalle');

Your blade file:

index.blade.php

<a href="{‌{ route('pelicula.detalle') }}">Ir al detalle</a>

If your problem is not solved, try to remove your route-cache using the below command:

php artisan route:cache

Note: This command removes your route caches.

Upvotes: 0

Kevin Yobeth
Kevin Yobeth

Reputation: 1017

Your route should be pelicula.detalle, not detalle.pelicula. You named it that way.

<a href="{‌{ route('pelicula.detalle') }}">Ir al detalle</a>

Upvotes: 2

Related Questions