0

Trying to run the following Laravel 4.1 route: http://myserver.dev/admin/import-items/1

When I do so, I get the following error:

Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException
Controller method not found.

Here are my routes for this:

Route::group(array('prefix' => 'admin', 'before' => 'auth'), function()
{
    Route::get('items/import-items/{after?}', array('as' => 'importItems', 'uses' => 'ItemsController@importItems'));

    Route::get('items/{id}/show', 'ItemsController@show');
    Route::resource('items', 'ItemsController');
});

I can look at the Items controller, and the method importItems is most definitely there:

class ItemsController extends \BaseController {

    /**
     * Item Model
     * @var Item
     */
    protected $item;

    /**
     * Inject the models.
     * @param Item $item
     */
    public function __construct(Item $item)
    {
        parent::__construct();

        $this->item = $item;
    }

    /**
     * Display a listing of items
     *
     * @return Response
     */
    public function index($items = [])
    {
        $title = Lang::get('admin/items/title.manage_items');

        if (empty($items))
            $items = $this->item;

        return View::make('admin/items/index', compact('items', 'title'));
    }

    /**
     * Imports Items after specified date.
     * @return array
     **/
    public function importItems($after = 7)
    {

        $results = Item::importItems($after);

        return $results;
    }
}

When I run php artisan routes the route clearly shows up as usable in the list:

GET|HEAD admin/items/import-items/{after?} | importItems   | ItemsController@importItems

The thing is, this exact code works just fine from another project I had it in. After I copied over the route settings and the controller and model, it decided not to work in this new project. I feel like I've missed some key step here because I can't see any differences in the code.

Any ideas?

5
  • Please post ItemsController Commented May 28, 2014 at 4:19
  • Have you run composer dump-autoload? Commented May 28, 2014 at 4:24
  • Yes, ran composer dump-autoload but did not fix. Added ItemsController to post. Commented May 28, 2014 at 4:49
  • Try \ItemsController@show Commented May 28, 2014 at 4:56
  • @AmitGarg Same result. Commented May 28, 2014 at 5:11

1 Answer 1

1

You are using the wrong url. This url:

http://myserver.dev/admin/import-items/1

should be this instead

http://myserver.dev/admin/items/import-items/1

OR

Route::get('items/import-items/{after?}', array('as' => 'importItems', 'uses' => 'ItemsController@importItems'));

should be

Route::get('import-items/{after?}', array('as' => 'importItems', 'uses' => 'ItemsController@importItems'));

...depends which url you want

Sign up to request clarification or add additional context in comments.

1 Comment

Absolutely amazing. And by amazing, I mean "face palm". It all boiled down to the link I had embedded in a view that was wrong in the new code and correct in the old. Thanks for catching this!! :)

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.