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');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题