laravel 传递$request参数报错?

我在控制器方法的最上面:

namespace App\Http\AdminControllers;
public function signIn(Request $request) {
    return redirect()->intended('Am/Index/index', $request);
}

这将跳转到Index控制器的index方法,但是现在问题来了,并没有进行跳转,而是程序报错:

Object of class Illuminate\Http\Request could not be converted to int

可是之前我一直都是这样写的...不知道为什么会报错呢,我只是将请求转发的目的.
请各位大大给点意见,谢谢各位啦.

阅读 5.2k
2 个回答

你这么当然不对
我们看看 intended 的定义
https://laravel.com/api/5.1/I...

RedirectResponse intended(string $default = '/', int $status = 302, array $headers = array(), bool $secure = null)
  • 第一个参数是跳转到的网址,默认 首页

  • 第二个参数是 http 状态码,默认 302,需要 int 类型,因为是重定向嘛

看你的使用方法,在第二个参数传递了 $request 对象,这个需要的参数不符合呀

所以报错 could not be converted to int 就是不能被转化成 int 类型

namespace App\Http\AdminControllers;
use Illuminate\Http\Request; // 加上这一行导入这个类即可
public function signIn(Request $request) {
    return redirect()->intended('Am/Index/index', $request);
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题