So this is what I've got so far. But as you'd expect, it's only filling the array with the first subject from each category. How can I get all subjects into the array?
public static function listSubjects()
{
$subjects = Subject::orderBy('name')->get();
foreach ($subjects as $subject){
$dropdown[$subject->category->name] = [$subject->id => $subject->name];
}
$subject = ['' => '-- Select Subject --'] + $dropdown;
return $subject;
}
For anyone interested.
$dropdown[$subject->category->name][$subject->id] = $subject->name;
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community