Last active
April 7, 2019 05:29
-
-
Save mehedithedue/0e61b6bb21c816e6737c151b226e903c to your computer and use it in GitHub Desktop.
Logical conditional query in where clause in Laravel ORM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Model::leftJoin('dummy_table', 'dummy_table.id', '=', 'mock_table.foreign_key') | |
->where('dummy_table.status', 1) | |
->where(function ($query) { | |
$users = Auth::user()->id; | |
if ($users == '12') { | |
$query->where('dummy_table.created_by', '=', Auth::user()->id) | |
->where('dummy_table.user_group', 'user'); | |
} else if (in_array($users, [1, 4, 6])) { | |
$query->whereIn('dummy_table.created_by', [1, 4, 6]); | |
} else { | |
$query->where('dummy_table.created_by', Auth::user()->id) | |
->where('dummy_table.reg_created_at', Carbon::today()); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment