I have an Eloquent scope search query like this that takes in input parameters like this:
"ECEC 301 Advanced Programming for Engineers Lab",
"ECEC 301 Advanced Programming for Engineers Lecture",
"ECEC 302 Digital Systems Projects Lab",
"ECEC 471 Introduction to VLSI Design Lab"
Using this Model:
public function scopeSearchWithType($query, $searchTerm) {
return $query->where(
DB::raw("subject_code || ' ' || course_no || ' ' || course_title || ' ' || instr_type"),
'like',
'%' . $searchTerm . '%'
)->select(
$searchTerm,
'day',
'time',
'crn'
);
}
As you can see, each input string is actually the combination of four different columns.
Anyways. When I run this query, this is the following result:
"ECEC 471 Introduction to VLSI Design Lab": "ECEC 471 Introduction to VLSI Design Lab",
day: "W",
time: "09:00 am - 10:50 am",
crn: "12506"
}
As you can see, the key of $searchQuery
is the name of the value
. I would like to assign a custom name such as course_name
to the key.
I've tried everything from class => $searchTerm
to class as $searchTerm
, but they did not work.
Aucun commentaire:
Enregistrer un commentaire