vendredi 10 juillet 2020

Search Array values in comma Separated Column in Laravel

I have two tables (Assessments, Unit_Assigned). In Assessments table I store Multiple Unit Assigned Ids with comma-separated Format like below

id | title | assignedids
-------------------------
2  | NTitl | 15,25,6
-------------------------
3  | Ctitl | 25,6,38

Unit_Assigned Table display below

id | staffid | unit_id | batchid
---------------------------------
15 | 10      |  25     |  31
---------------------------------
38 | 12      |  18     |  42
---------------------------------

I need to get an assessment list based on staff ID (available in Unit_Assigned table)

I got assigned ids list using below query

  $assignedunits=Unitassigning::Where('staffid',$staffid)->get()->pluck('id')->toArray();

try to fetch assessment using below query

$stringconverted=implode(",",$assignedunits); $completedAssessments=Assessments::whereRaw("find_in_set('$stringconverted',assignedids)")->get();



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2ZQlLr2
via IFTTT

Aucun commentaire:

Enregistrer un commentaire