2

I'm new to Laravel and I'm just following some tutorial blogs but I'm stuck at early stage.

Here is my Route

Route::resource('ip', 'IpController');
Route::get("index","IpController@view");

and here is my controller

<?php

class IpController extends BaseController {


    public function index()
    {
        return View::make('hello');
    }

}

here is how I access the page

<a href="{{ URL() }}/ip/index">IP</a>

I do what the tutorials says but I'm confused why I've got this error when accessing the page.

Class IpController does not exist

May i know what i've done wrong and how can i fix it? TIA!

2
  • Whenever you createa a new class, run composer dump-autoload (if you're not following psr-4, ofcourse). Commented Mar 20, 2015 at 12:45
  • @Dave solve this problem or not because i am also face this problem and not found any solution. :-( Commented Apr 8, 2015 at 5:54

4 Answers 4

2

I came across this issue when using Lumen, not Laravel. So I thought answering here would be helpful to others who stumble onto this page as well. I apologize in advance if that is not in keeping with the SO rules.

Here's the error I got in Lumen:

lumen.ERROR: exception 'ReflectionException' with message 'Class Controller does not exist' 

The solution is: when defining the route, use the full path to the controller:

$app->get('/someRoute/', 'App\Http\Controllers\Controller@index');
Sign up to request clarification or add additional context in comments.

Comments

1

Run the following in CLI:

composer dump autoload

and remove the second route because it isn't necessary because it's already declared in your Resource route. and change

class IpController extends BaseController into

class IpController extends eController if you are using Laravel 5.0.

Comments

0
Route::resource('ip', 'IpController');

will automatically create the

Route::get("ip","IpController@index");

for you, along with many more helpful routes.

Then you can make the link to it like that:

<a href="{{ URL('ip') }}">IP</a>

(Because the auto-generated route made be Route::resource uses just the www.mysite.com/ip for "index page" for the "ip"s.

Also, in laravel 5, make sure that your controller lies in: yourapp/app/Http/Controllers/ directory.

5 Comments

Hi, I follow all of this and this what ive got BadMethodCallException Method [show] does not exist.
Can you give the list of your routes? You can do this by using the command-line command: php artisan route:list<br/>
edit: I think I got your problem: you are accessing the page with url like: www.yoursite.com/ip/something then laravel thinks that you want to show one of the ip, which handled (when using the benefits of Route::resource) by the method show in your Controller, which indeed doesn't exist...
Hi but i also try using this route Route::get("index","IpController@index"); but still same problem
What is the URL of the page which is giving you that problem?
0

Add a namespace.

<?php namespace App\Http\Controllers;

class IpController extends BaseController {


    public function index()
    {
        return View::make('hello');
    }

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.