doulin9679 2015-12-13 10:08
浏览 184
已采纳

Laravel在Resource :: Controller中使用自定义函数

i want to use custom function in Route::resource() controller like with public function check(), public function login() or public function laogout(), but my code doesnt work, how to use custom functions?

For Example:

Route:

Route::resource('auth', 'AuthenticationController');

View:

Controller:

public function check()
{
    //
}
public function login()
{
    //
}
public function logout()
{
    //
}

I get this error:

NotFoundHttpException in RouteCollection.php line 161:
  • 写回答

2条回答 默认 最新

  • doujingjiao0015 2015-12-13 10:25
    关注

    Firstly, resource controllers should be used to generate Restful API that provides CRUD interface to your application - not for logging users in and out.

    Secondly, you can't add additional controller methods with Route::resource() - this method is used to define the prefixed set of methods - see http://laravel.com/docs/5.1/controllers#restful-resource-controllers for more information.

    If you want to add those custom actions to your routing, you'll need to define them separately before your resource routes, e.g.:

    Route::get('auth/check', 'AuthenticationController@check');
    

    You can read more about defining custom routes here: http://laravel.com/docs/5.1/routing

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加