404 NOT FOUND in Laravel 8

Viewed 27452

I am creating a simple website in Laravel while running a web site ran into the problem with 404 NOT FOUND Laravel 8. index page working when I click on about us and contact us page getting error of 404 NOT FOUND I don't know why is that. what I tried so far I attached below.

Folder structure

enter image description here

Controller

class SmsController extends Controller
{
    public function index()
    {
        return view('index');
    }  


    public function aboutus()
    {
        return view('aboutus');
    }  

    public function contactus()
    {
        return view('contactus');
    }  


}

Index.blade.php I made the links

<ul class="nav navbar-nav">
        <li class="active"><a href="#">Home</a></li>
        <li><a href="{{url('aboutus')}}">Aboutus</a></li>
        <li><a href="{{url('contactus')}}">Contactus</a></li>
      </ul>

routes

Route::get('/', 'App\Http\Controllers\SmsController@Index');
Route::get('Aboutus', 'App\Http\Controllers\SmsController@aboutus');
Route::get('Contactus', 'App\Http\Controllers\SmsController@contactus');
7 Answers

I think you got error here

Route::get('Aboutus', 'App\Http\Controllers\SmsController@aboutus');
Route::get('Contactus', 'App\Http\Controllers\SmsController@contactus');

instead

Route::get('/aboutus', 'App\Http\Controllers\SmsController@aboutus');
Route::get('/contactus', 'App\Http\Controllers\SmsController@contactus');

I use this command:

php artisan route:cache

then

php artisan serve

After that, copy the IP address after second command.

In laravel 8 you can try this way:

Route::get('/', [App\Http\Controllers\SmsController::class, 'index']);
Route::get('/about-us', [App\Http\Controllers\SmsController::class, 'aboutus']);
Route::get('/contact-us', [App\Http\Controllers\SmsController::class, 'contactus']);

I had to use php artisan route:cach command in terminal.

try to write a route like this

Route::get('/aboutus', 'App\Http\Controllers\SmsController@aboutus');

Thank you guys, I have been on this for close to two days, this is what helped me

php artisan route:cache

using v9

The problem is with the route address since the Laravel route are case sensitive.

the correct form of route

Route::get('/aboutus', 'App\Http\Controllers\SmsController@aboutus');
Route::get('/contactus', 'App\Http\Controllers\SmsController@contactus')'

and also it is worth mentioning that the updated accepted way to write routes in the Laravel 8.x to-class method is

Route::get('/aboutus', [App\Http\Controllers\SmsController::class, 'aboutus']);
Route::get('/contactus', [App\Http\Controllers\SmsController::class, 'contactus']);

but the old method is still accessible on the newer version of Laravel

Related