Home » Php » php – Laravel 5 – SQLSTATE[22P02] – invalid text representation with postgres

php – Laravel 5 – SQLSTATE[22P02] – invalid text representation with postgres

Posted by: admin July 12, 2020 Leave a comment

Questions:

Error:

SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input
syntax for integer: “dismissnotification” (SQL: select * from “users”
where “id” = dismissnotification)

In my routes.php file:

Route::get('user/dismissnotification/{notificationid}',array('as' => 'dismissnotification', 'uses' => '[email protected]'));

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

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.

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?

How to&Answers:

The SQL query shows that Laravel is calling a different controller method on your route than you are expecting.

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 [email protected] or [email protected] or maybe even [email protected] depending on what other routes you have defined for /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.