Reputation: 397
SELECT school_courses.*, schools.school_name, schools.country, schools.city FROM
school_courses JOIN schools ON school_courses.school_id = schools.id
Hello there,
I want to convert the above SQL query to laravel. And also I want to learn joins in laravel query please share any easy step by step tutorial link if you have one.
Upvotes: 0
Views: 59
Reputation: 5270
My suggestion is to use better Eloquent: Relationships
Your converted query is given below
use Illuminate\Support\Facades\DB;
$users = DB::table('school_courses')
->join('schools', 'us schools ers.id', '=', 'contacts.user_id')
->select('school_courses.*','schools.school_name', 'schools.country', 'schools.city')
->get();
Upvotes: 1
Reputation: 2292
This is Query Builder way of doing it.
$result = DB::table('school_courses')
->join('schools','schools.id','=','school_courses.school_id')
->select('school_courses.*','schools.school_name', 'schools.country', 'schools.city')
->get();
Refer this link https://laravel.com/docs/8.x/queries#joins
Upvotes: 1