querying polymorphic relationship

125 views Asked by At

I'm not really expert in backend. I have here some columns of notifications table which has been used by a polymorphic relationship in Laravel.

+----+------------------+----------------+
| id | sendto_type      |   sendto_id    | 
+----+------------------+----------------+
|  1 | App\User         |              1 |  
|  2 | App\User         |              2 |   
|  3 | App\Station      |              1 | 
|  4 | App\Station      |              2 | 
+----+------------------+----------------+

I want to get column sendto_type that has attribute "App\User", It has been made using a Polymorphic Relationship in Laravel and derived from a table named users. Also I used sendto_id to have a relationship from users table. Is that even possible and if yes, how would I do that.

I tried querying SELECT * FROM notifications WHERE sendto_type = "App\User". It was successful but returns no result. Please help.

1

There are 1 answers

1
O. Jones On

You probably need to escape that \ in your query, because it generally works as a modifier. Also, use single quotes instead of double quotes.

WHERE sendto_type = 'App\\User'