doudouwd2017 2013-11-17 07:31
浏览 102
已采纳

Laravel - 重定向到控制器

I keep getting: Unknown action [HomeController@showHome]

Route:

Route::get('/', ['before' => 'checkUserFilter'], 'HomeController@showHome');
Route::get('/createUser', 'UserController@createUser');

Filter:

Route::filter('checkUserFilter', function() 
{
    if (Auth::guest()) 
    {
        return Redirect::action('UserController@createUser');
    }  

});

Controller:

userController

public function createUser()
{
   // removed everything else, the return redirect action isn't working.

  return Redirect::action('HomeController@showHome');
}

homeController

public function showHome()
{
    return View::make('home');
}

When a user loads the webpage, the filter checks if he's a guest or not, if he is, go to the createUser method in UserController.php. It creates the user, but it doesn't redirect back to HomeController. How can I stop the above error so it redirect back to the HomeController?

I also have another question: What would be a better way to place the return redirection action, besides in the method? I would like it if I can use this same method for multiple things, for example create a user in the admin control panel.

  • 写回答

1条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 ubuntu18.04 tty报错&tty界面su/sudo命令无法执行,如何解决?
      • ¥20 关于c语言网络编程,实现传文件和即时聊天
      • ¥20 下面的压缩方法是否可行
      • ¥15 结构体数组读取文件信息失败,读取不了
      • ¥15 kaldi thchs30 训练遇到问题
      • ¥15 shellter无法使用,如何解决?(操作系统-kali)
      • ¥15 matlab动态模态分解程序
      • ¥60 关于渗透及远控的几个问题
      • ¥15 python文本词汇出现次数统计
      • ¥15 使用按键和串口,记录按键在不消抖的情况下触发的次数