Skip to content
Advertisement

Laravel select records with pivot table

I have a little problem with eloquent. I have 3 tables. Users, phrases, and phrase_user. phrase user contains columns: id, phrase_id, user_id I need to select phrases with pivot table for example. This action with SQL will be like this…

JavaScript

This is my index function in controller

JavaScript

I also have written these functions in models… Phrase model:

JavaScript

User model:

JavaScript

In this case, paginator is not working properly because $phrases = DB::table('phrases')->orderBy('id','desc')->Paginate(5); There is some problem..

In conclusion: I need to show only my phrases in phrases page. every user must have their phrases.

Advertisement

Answer

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement