0

I am getting this error when testing my code. I know it is a routing issue but I can't see anything wrong with my routes.

Here is the routes that are causing the problems:

Route::get('/messages', 'MessageController@create');
Route::get('/messages/show/{comment}', 'MessageController@show');

Here is the controller:

class MessageController extends BaseController
{

protected $messageForm;

public function __construct(MessageForm $messageForm, MessageRepository $messageRepository,
  MessageRecord $messageRecord)
{
    $this->messageForm = $messageForm;
    $this->messageRepository = $messageRepository;
    $this->messageRecord = $messageRecord;
}

/**
 * Display a listing of the resource.
 * GET /messages
 *
 * @return Response
 */
public function create()
{
    return View::make('message.create');
}



public function show($comment)
{
    $message_id = $this->messageRepository->find($comment);
    return View::make('message.show')->with('comment', $message_id);
}

/**
 * Store a newly created resource in storage.
 * POST /messaages
 *
 * @return Response
 */
public function store()
{
    $data = Input::all() ;
    $this->messageForm->validate($data);

    $messageRecord = new MessageRecord;
    $messageRecord->comment = $data['comment'];

    Return "Comment created";
}
}

composer.json

  {
"name": "Desk",
"description": "Control desk",
"keywords": ["desk"],
"require": {
    "laravel/framework": "4.2.*",
    "ornicar/gravatar-bundle": "1.1.*"
},
"require-dev": {
    "behat/behat": "3.0.*",
    "behat/mink-extension": "~2.0@dev",
    "behat/mink-goutte-driver": "~1.0",
    "phpunit/phpunit": "4.0.*",
    "mockery/mockery": "dev-master",
    "way/generators": "dev-master",
    "doctrine/dbal": "2.3.*"
},
"autoload": {
    "classmap": [
        "app/commands",
        "app/controllers",
        "app/controllers/parts",
        "app/controllers/cross",
        "app/database/migrations",
        "app/database/seeds",
        "app/database/seeds/parts",
        "app/tests/TestCase.php",
        "app/tests/FreshDatabase.php"
    ],
    "psr-4": {
        "Desk\\": "app/desk"
 }
},
"scripts": {
    "post-install-cmd": [
        "php artisan optimize"
    ],
    "post-update-cmd": [
        "php artisan clear-compiled",
        "php artisan optimize"
    ],
    "post-create-project-cmd": [
        "php artisan key:generate"
    ]
},
"config": {
    "preferred-install": "dist"
},
"minimum-stability": "dev",
"prefer-stable": true
}
  • Don't take this the wrong way but instead of posting multiple questions about the same problem it might be better to stick with one question and respond to requests for more information. It would be nice to know which route was generating the problem. – Cerad Sep 24 '14 at 13:33
  • currently neither route is working that is why I posted them – wadeCunningham Sep 24 '14 at 13:38
  • Can you post the complete composer.json file? I know you are using S2.4 but you are also using something on top of it to handle your REST stuff. It's not FOSRestBundle. – Cerad Sep 24 '14 at 13:43
  • The fog has lifted a bit. Are you aware that while Laravel uses some Symfony 2 components, Laravel and Symfony2 frameworks are completely different? Consider removing the symfony 2 tag and replacing it with the laravel tag. I suspect you may get a bit more help. – Cerad Sep 24 '14 at 13:51
  • You may want to consider using RESTful resource controllers...then you'd have just one route, `Route::resource('message', 'MessageController')`, and set up your controller methods [as detailed in the docs](http://laravel.com/docs/4.2/controllers#restful-resource-controllers). – damiani Sep 24 '14 at 15:28
  • that is what i had first and people told me to change it – wadeCunningham Sep 24 '14 at 18:16
  • Why? And, did the routes work properly then? – damiani Sep 24 '14 at 19:12
  • no they still do not work – wadeCunningham Sep 24 '14 at 19:35
  • 1) Have any routes worked, and have you tried a plain `index()` route with `Route::get('/', 'MessageController@index')`? 2) Could you post your entire **routes.php** file? 3) Are your controllers within `app`, or are they down a level in `app/desk`? 4) Have you run `composer dump-autoload`? 5) Does the default home controller work? – damiani Sep 25 '14 at 00:42

1 Answers1

0
  1. Your show route expects a $comment parameter. That route should be:

    Route::get('message/show/{comment}', 'MessageController@show');
    
  2. Are you running an auth filter on this route? If so, Try removing the before filter (or change it temporarily to ['before' => 'none']) and reload the route.

    If your AuthController is not set up, or is missing the login method, you will get a NotFoundHttpException when the auth filter in filter.php tries to redirect to your login page. (See similar question here).

Community
  • 1
  • 1
damiani
  • 7,071
  • 2
  • 23
  • 24
  • It seems like your `routes.php` file is not getting loaded; though you haven't verified if you have *any* routes that are working, I'm assuming *none* do. Try running `php artisan routes` in terminal and post your output. It could very likely be a Virtual Host config problem, [see the answer to this question](http://stackoverflow.com/questions/23593892/symfony-component-httpkernel-exception-notfoundhttpexception-laravel?rq=1). – damiani Sep 25 '14 at 14:36
  • @wadeCunningham I edited the answer above based on a similar question :)...see if it applies in your case. – damiani Sep 25 '14 at 17:55