To view select elements in the Ravel admin form from DB

Asked 2 years ago, Updated 2 years ago, 61 views

I'm working on a form with Raveladmin.

to build select elements
$director=[
'John' = > 1,
'Smith' = > 2,
'Kate' = > 3,
];

$form->select('director', 'Director') ->options($director);

The value of select will be passed in an array as
If this value is maintained in DB, what is the best way to look at it?

Among me,

$director=DB::table('director')->get();

All I can think of is a way to convert the referenced value and give it to you...
If you leave it as it is, you will get an error, so
Must be converted to the form 'val' = > 'Option name'...

It may be elementary, but I appreciate your cooperation.

php laravel

2022-09-30 21:28

1 Answers

I solved myself.
I was able to refer to this writing method!

$form->select('director', 'Director') ->options(
    DB::table('oga_section') - > pluck('director_name', 'director_id')
);


2022-09-30 21:28

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.