douxin8610 2014-04-13 17:00
浏览 50
已采纳

Laravel RESTful控制器包含'show'功能的子目录

I am building my Laravel app through the use of RESTful controllers.

Currently, an 'agent' can login, to view all of their 'notifications'.

The structure is:

/agents

When they chose a notification to view, instead of:

/agents/$id

I want it to be:

/agents/notifications/$id

Solely because it follows logically. If it was '/agents/$id' I would expect to see the agent's profile, for example.

Is there a way of including a subdirectory into the 'show' function? Or do I need to create a notification controller that somehow sites within the agent directory.

My route is:

Route::controller('agents', 'AgentsController');

With the show function:

public function show($id)
{
    $alerts = Alert::where('id', $id)->first();
    $this->layout->content = View::make('agents.notification.show', array('alerts' => $alerts));
}

Any help would be hugely appreciated.

  • 写回答

1条回答 默认 最新

  • douwen5924 2014-04-13 18:21
    关注

    if you want to use http://laravel.com/docs/controllers#restful-controllers then your controller's method should be named getShow(). Apart from that you can achieve what you want by defining another route like this:

    Route::get('agents/notifications/{id}', 'AgentsController@getShow');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?