2
votes

I got confuse and I got an error, why does my routing process not work, The error gives me Route [index] not defined, but on other hand I already defined the index to HomeController, take a look at my process that I did,

Note: I used laravel version: 5.8*

  1. I create a index.blade.php
  2. Add the routes to the web.php and I used this code
`Route::get('/index', 'HomeController@index');
  1. I add the public function index to the HomeController

Web.php

    Route::get('/index', 'HomeController@index');

HomeController

    public function index()
    {

        return view('index');

    }

My URL:

My URL

Error:

enter image description here

5
share your URL that you called foit - Bhargav Chudasama
Does this answer your question? InvalidArgumentException Route not defined - Shibon
Remove / in route. write route like this: Route::get('index', 'HomeController@index')->name('homeIndex');. and give route in your blade file like this : {{ route('homeIndex') }}. - Bhoomi Patel

5 Answers

1
votes

The problem might be in your index view.

Looks like you are trying to access route using route name and you have not defined the route name for index route.

So in web.php add ->name('index')

Route::get('/index', 'HomeController@index')->name('index');

1
votes

You have to provide name of the route in your routes.

Route::get('/index', 'HomeController@index')->name('index');

You can also use the below syntax

Route::get('/index', [
'as' => 'index',
'uses' => 'HomeController@index'
]);

for more information please have a look at the docs

https://laravel.com/docs/5.7/routing#named-routes

0
votes

Try This

if you use route this way

Route::get('/index', 'HomeController@index');
//then your url will be
URL/index

OR use this way

Route::get('/', 'HomeController@index');
//then your url will be
URL
0
votes

Try with localhost/folder_name/public/index if this works for you then probably problem is with virtual host creation.

0
votes

Somewhere in your view you are using {{route('index')}}.

Add ->name('index') in the end of your route.

Route::get('/index', 'HomeController@index')->name('index');

Hope this will help.