Tuesday, 9 August 2022

Laravel get data by dependant columns ( multiple where conditions orwhere conditions)

My task is to create a form with access;
while creating form i added a radio buttons that is 
1-all team
2-individual dept
3-all dept
4-selected user
if admin selects 1 then the table data will show to all team with admin
if admin selects 2 then another dropdown popup from there we need select one dept
-then the table data will show to only selected dept users including admin


$data= CustomFormTable::query()
->where(function($query){
$query->where('access_to','=',1);
// ->Where('access_to_dept','=',$userDeptId);
})
->orWhere(function($query) use ($userDeptId){
$query->where('access_to','=',2)
->Where('access_to_dept','=',$userDeptId);
})
->orWhere(function($query) use ($userDeptId){
$query->where('access_to','=',3);
// ->Where('access_to_dept','=',$userDeptId);
})
->orWhere(function($query) use ($authUserId){
$query->where('access_to','=',4)
->Where('access_to_user','=',$authUserId);
})
->latest()->with('owner')->get();

No comments:

Post a Comment

Laravel Export data to csv

 use Illuminate\Http\Response; // Define a function to export data to CSV function exportToCSV($exportData, $columns) {     $filename = ...