i have 3 model User
, Blog
, Hotel
.
blog and hotel can have some comments , i used morph relation for comment section, i created new table named Comments
and it have commentable_id and commentable_type fields,
now im saving new comments for hotel like this :
```$hotelId = $request->get("hotel_id");
$hotel = Hotel::find($hotelId);
$comment = new Comment;
$comment->user_id = $request->user()->id;
$comment->body = $request->get('comment');
$hotel->comments()->save($comment);```
at this moment i want to show current user all comment about the hotels
according to Doc i tried this :
$comments = Comment::whereHasMorph(
'commentable',
['App\Hotel'],
function (Builder $query) {
$query->where('user_id', \Auth::id());
}
)->get();
but it give me this error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'has_morph' in 'where clause' (SQL: select * from `comments` where `has_morph` = commentable)
why and how can i fix this?
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2N9hKcy
via IFTTT
Aucun commentaire:
Enregistrer un commentaire