You should use relations if you don't want to use joins. If you need joins, then this is the correct way.
Documentation: http://laravel.com/docs/5.1/eloquent-relationships
I want to convert my raw database query into more secure eloquent how do I achieved this? Here is my code:
$results = CrimeReport::query()
->leftjoin('crime_types as ct','ct.id', '=', 'crime_reports.crime_type_id')
->leftjoin('crime_name as cn','cn.id', '=', 'crime_reports.crime_name_id')
->leftjoin('suspect_profile as s','s.id', '=', 'crime_reports.suspect_id')
->leftjoin('victim_profile as v','v.id', '=', 'crime_reports.victim_id')
->get([
'crime_reports.*', //to get ids and timestamps
'ct.crime_type as crime_type',
'cn.crime_description as crime_name',
's.firstname as suspect_name',
'v.firstname as victim_name'
]);
Please or to participate in this conversation.