Laravel Query/Model ***
Copy Below Code
View As A Text File
Show Text Only
Show API
Edit Code
$data = User::where('id', $request->event_id)
->with(['company' => function ($query) {
return $query->select('id', 'company_name', 'logo');
}])
->first();
//Print Query
DB::table('users')->toSql()
// JOIN
DB::table('users')
->leftJoin('posts', 'users.id', '=', 'posts.user_id')
->get();
You may also specify more advanced join clauses:
DB::table('users')
->join('contacts', function($join)
{
$join->on('users.id', '=', 'contacts.user_id')->orOn(...);
})
->get();
////////////////////////////
User::select('users.*')
->join('posts', 'posts.user_id', '=', 'users.id')
->join('comments', 'comments.post_id', '=', 'posts.id');
////////////////////////////////////////
$from_date = '2024-04-20';
$to_date = '2024-04-27';
Data::dateRange($from_date, $to_date)->get();
/////////////////////////////
//Continent
//Country
//Province
//City
$obj = Continent::with('country.province.city')->find(1);
foreach($obj->country as $kk=> $country){
foreach($country->province as $kk2=>$province){
foreach($province->city as $kk3=>$city){
echo $country->country.':::'.$province->province.'->'. $city->city . '<br/>';
}
}
}
Sub Condition
$searchData=CmsModuleData::
where('sts', 'active')
->where('content_type', 'page')
->whereNotIn('id', ['145'])
->where(function ($query) use ($s) {
$query->where('heading','like','%'.$s.'%');
$query->orWhere('content', 'like', '%' . $s . '%');
})
->get();
$contact->where('id',10)->exists();
$contact->where('id',10)->doesntExist();