oderfla oderfla - 6 months ago 47
PHP Question

Laravel routing failing for controller

Its Laravel 5.
When the route.php contains this:

Route::get('/foo', function () {
return 'Hello World';

then the page shows with the text "Hello World".

However, as soon as I add this new line in route.php:

Route::get('/foo2', 'IndexController');

then the page show this error:

UnexpectedValueException in Route.php line 567: Invalid route action: [App\Http\Controllers\IndexController]

I previously created a controller with artisan which now looks like this:

class IndexController extends Controller
public function index()
echo 'test';

what am I doing wrong?


You have to specify wich method will be executed:

Route::get('/foo2', 'IndexController@index');