Laravel 5 - SQLSTATE[22P02] - postgres 的文本表示无效
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32322743/
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
Laravel 5 - SQLSTATE[22P02] - invalid text representation with postgres
提问by Mr. Phil
Error:
错误:
SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: "dismissnotification" (SQL: select * from "users" where "id" = dismissnotification)
SQLSTATE[22P02]:无效的文本表示:7 错误:整数的无效输入语法:“dismissnotification”(SQL:从“users”中选择 * 其中“id”=dismissnotification)
In my routes.php file:
在我的 routes.php 文件中:
Route::get('user/dismissnotification/{notificationid}',array('as' => 'dismissnotification', 'uses' => 'NotificationController@dismiss'));
The link with the route on my view:
我认为路线的链接:
<a href="{{ URL::route('dismissnotification',$notification->id)}}"> <i class="fa fa-times"></i> </a>
When I click on this link the page is redirected correctly to (for example): http://mywebsite/user/dismissnotification/222222225
当我点击此链接时,页面被正确重定向到(例如): http://mywebsite/user/dismissnotification/222222225
And the function "dismiss" on my NotificationController is empty, but the error persists. I have no idea where the select * from "users"
in the original error comes from.
并且我的 NotificationController 上的函数“dismiss”为空,但错误仍然存在。我不知道select * from "users"
原始错误来自哪里。
public function dismiss($notificationid) {
//
}
Am I missing something obvious? What might be causing this error if there is no code at all in my function and the route is apparently correct?
我错过了一些明显的东西吗?如果我的函数中根本没有代码并且路由显然是正确的,那么可能导致此错误的原因是什么?
回答by Trip
The SQL query shows that Laravel is calling a different controller method on your route than you are expecting.
SQL 查询显示 Laravel 在您的路由上调用了与您预期不同的控制器方法。
select * from "users" where "id" = dismissnotification
That query is trying to find a user with the ID matching 'dismissnotification', so it looks like it's hitting something like UsersController@show or UsersController@edit or maybe even UsersController@222222225 depending on what other routes you have defined for /user.
该查询正在尝试查找 ID 与“dismissnotification”匹配的用户,因此它看起来像是 UsersController@show 或 UsersController@edit 甚至 UsersController@222222225 之类的内容,具体取决于您为 /user 定义的其他路由。
Since URL::route() rendered the path as you expected, your issue is probably the order in which you defined your routes; however, without seeing all of your /user routes and in the order you defined them, I can not be more specific.
由于 URL::route() 按照您的预期呈现路径,您的问题可能是您定义路由的顺序;但是,如果没有看到您的所有 /user 路由以及您定义它们的顺序,我就不能更具体了。