1

I already have a working application and there is a PhoneController.php in controllers folder.

Now I want to add an api for my application so I added api\v1\PhoneController.php

But when I use routing this doesnt work as I want to:

Route::group(array('prefix' => 'api/v1'), function()
{
    Route::get('test', 'PhoneController@index');
});

I tried adding 'namespace' => 'api\v1' or api\v1\PhoneController@index but this always picks the wrong PhoneController.

Are there anyways to get it work? I could rename the PhoneController.php but this could confuse me in future, so I am trying to avoid this solution

5
  • 1
    daylerees.com/codebright/controllers in Controller Routing he speaks about namespacing controllers Commented Jul 5, 2014 at 19:42
  • A quick question: when I always use this way I have to add a lot of these use XYZ; over and over again, are there ways to automate this? Commented Jul 5, 2014 at 20:06
  • put \ before classname ex: \View Commented Jul 5, 2014 at 20:10
  • Works perfectly now, thanks! Can I mark your answer as correct answer? Commented Jul 5, 2014 at 20:12
  • I added an answer, happy to help Commented Jul 5, 2014 at 20:15

1 Answer 1

1

As described here http://daylerees.com/codebright/controllers

namespace Blog\Controller;

class Article extends \BaseController
{
    public function showIndex()
    {
        return \View::make('index');
    }
}

Then add route

Route::post('index', 'Blog\Controller\Article@showIndex');
Sign up to request clarification or add additional context in comments.

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.