I have 2 tables and I need to join those tables.
I need to select
id
and nam
e from galleries
, where share gal.id = galleries.id
and user_id = auth::id()
.
Tables:
Galleries: id, name
Share: gal_id, user_id
Please show me example in laravel. And I need to display it.
Best Answer
To achieve this, you have Relationship in Eloquent ORM. The official website states :
You can read all about eloquent relationship over here
If you do not want to use relationship, following is an example on how to join two tables :
The above query will join two tables namely
users
andprofiles
on the basis of user.id = profile.id with two different conditions, you may or may not usewhere
clause, that totally depends on what you are trying to achieve.