php - Laravel join tables -


i have 2 tables , need join tables. need select id , name galleries, share gal.id = galleries.id , user_id = auth::id().

tables:

galleries: id, name share: gal_id, user_id 

please show me example in laravel. , need display it.

to achieve this, have relationship in eloquent orm. official website states :

of course, database tables related 1 another. example, blog post may have many comments, or order related user placed it. eloquent makes managing , working these relationships easy. laravel supports many types of relationships:

you can read eloquent relationship on here

if not want use relationship, following example on how join 2 tables :

     db::table('users')->select('users.id','users.name','profiles.photo')->join('profiles','profiles.id','=','users.id')->where(['something' => 'something', 'otherthing' => 'otherthing'])->get(); 

the above query join 2 tables namely users , profiles on basis of user.id = profile.id 2 different conditions, may or may not use where clause, totally depends on trying achieve.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -