Jensej Jensej - 1 year ago 159
PHP Question

Laravel join tables

I have 2 tables and I need to join those tables.
I need to

e from
, where share =
user_id = auth::id()


Galleries: id, name
Share: gal_id, user_id

Please show me example in laravel. And I need to display it.

Answer Source

To achieve this, you have Relationship in Eloquent ORM. The official website states :

Of course, your database tables are probably related to one another. For example, a blog post may have many comments, or an order could be related to the user who placed it. Eloquent makes managing and working with these relationships easy. Laravel supports many types of relationships:

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 :

     DB::table('users')->select('','','')->join('profiles','','=','')->where(['something' => 'something', 'otherThing' => 'otherThing'])->get();

The above query will join two tables namely users and profiles on the basis of = with two different conditions, you may or may not use where clause, that totally depends on what you are trying to achieve.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download