laravel 调用未定义的方法 llluminate\support\facades\request::save()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24454020/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
call to undefined method llluminate\support\facades\request::save()
提问by user3758351
Trying to save an input into my database called requests
试图将输入保存到我的数据库中,称为请求
The error points to my requestController.php when the data is trying to be saved.This is the code to handle saving the data into the database called requests.
当尝试保存数据时,错误指向我的 requestController.php。这是处理将数据保存到名为 requests 的数据库中的代码。
$request = new Request;
These are the data trying to save:
这些是试图保存的数据:
$request->product_name = $posted['product_name'];
$request->product_description = $posted['product_description' ];
$request->email = $posted['email'];
$request->user_id = Auth::user()->I'd;
error reporting from this code:
此代码的错误报告:
$request->save();
Why do I get this error exception?
为什么我会收到此错误异常?
回答by Joel Hinz
Request
is the name of a facade in Laravel. That's why the error message says it's looking for the save()
method on the Illuminate\Support\Facades\Request
class. You'll want to either namespace your Request
class or rename it to something else. I would prefer the latter option, myself.
Request
是 Laravel 中的门面名称。这就是为什么错误消息说它正在寻找类save()
上的方法Illuminate\Support\Facades\Request
。您需要为您的Request
类命名或将其重命名为其他名称。我自己更喜欢后一种选择。
Besides that, this line looks like it should cause the script to crash: $request->user_id = Auth::user()->I'd;
- it should probably be ->id;
, I assume?
除此之外,这一行看起来应该会导致脚本崩溃:$request->user_id = Auth::user()->I'd;
-->id;
我想应该是这样?