Hi there,
As the title suggests, I am trying to create a select box in a form, the options of which are populated from a database table.
After some looking around, I found [this post on Stack Overflow] (https://stackoverflow.com/questions/35421804/laravel-5-2-populate-select-options-from-database) and have edited my code as follows.
The view, which is found at:
/laravel/resources/views/vendor/spark/settings/mystuff/list-stuff.blade.php
contains this:
<select name="stuff_type">
@foreach($stuff_types as $stuff_type)
<option value="{{ $stuff_type->id }}">{{ $stuff_type->name}}</option>
@endforeach
</select>
The Controller contains this, amongst other things:
...
use Illuminate\Support\Facades\DB;
...
public function index()
{
$stuff_types = DB::table('stuff_type')->get();
return view('settings.mystuff.list-stuff', ['stuff_type' => $stuff_type]);
}
So, as far as I can see, I've done all that was asked in the answer on the Stack Overflow post. But, on visiting the page that uses the view, I get an error:
Undefined variable: stuff_types
I am BOUND to have missed a step somewhere, but don't know what it is. Do I need to edit routes.php or the appropriate js file?
I am using Laravel Spark version 3.0 with Laravel version 5.3
Any help that anyone can provide would be most appreciated.
With kind regards,
Mark