Support the ongoing development of Laravel.io →
Database Eloquent Forms

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;
}
Last updated 3 years ago.
0

For anyone interested.

$dropdown[$subject->category->name][$subject->id] =  $subject->name;
0

Sign in to participate in this thread!

Eventy

Your banner here too?

iforwms iforwms Joined 12 Aug 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.