-1

There is a 404 NOT FOUND at web.php for navbar.blade.php:

<li class="{{Request::is('home') ? 'active' : ''}}"><a href="{{ route('home')}}">Home</a></li>
<li class="{{Request::is('about') ? 'active' : ''}}"><a href="{{ route('about')}}">About</a></li>
<li class="{{Request::is('contact') ? 'active' : ''}}"><a href="{{ route('contact')}}">Contact</a></li>

web.php:

Route::get('/home', 'PagesController@getHome')->name('home');;
Route::get('/about', 'PagesController@getAbout')->name('about');;
Route::get('/contact', 'PagesController@getContact')->name('contact');

Route::get('/messages', 'MessagesController@getMessages')->name('messages');

Route::post('/contact/submit', 'MessagesController@submit')->name('submit');

PagesController.php:

class PagesController extends Controller
{
    public function getHome(){
        return view('home');
    }
    public function getAbout(){
        return view('about');
    }
    public function getContact(){
        return view('contact');
    }
}

Running commands like:

composer dumpautoload && php artisan view:clear && php artisan cache:clear && php artisan route:clear && php artisan config:clear

Even if is declare at web.php the routes can not be found.

1 Answers1

0

I just tested on a local Laravel instance and I can't get routes to work like you have them.

Also, looking in the Laravel 8 release notes You will see that:

In previous releases of Laravel, the RouteServiceProvider contained a $namespace property. This property's value would automatically be prefixed onto controller route definitions and calls to the action helper / URL::action method. In Laravel 8.x, this property is null by default. This means that no automatic namespace prefixing will be done by Laravel.

Even though:

This change only affects new Laravel 8.x applications. Applications upgrading from Laravel 7.x will still have the $namespace property in their RouteServiceProvider.

Just to cross this one off the list, your routes definition code should look like this.

Route::get('/home', [PagesController::class, 'getHome'])->name('home');
Route::get('/about', [PagesController::class, 'getAbout'])->name('about');
Route::get('/contact', [PagesController::class, 'getContact'])->name('contact');

Route::get('/messages', [MessagesController::class, 'getMessages'])->name('messages');

Route::post('/contact/submit', [MessagesController::class, 'submit'])->name('submit');

Also, the checks for the routes should be done with: Route::is('home') and not Request::is('home').

Cornel Raiu
  • 2,758
  • 3
  • 22
  • 31
  • Unfortunally and it is strange does not happen nothing. When I did that an error appears: In Container.php line 875: Target class [PagesController] does not exist. – konstantinosiakovou Jul 19 '21 at 14:50