I try to obtain the text of a combobox from the controller, so I make a query to the database with the value of the combobox obtained, but when saving it does so with the following format ["Plant I"] (I don't know why it saves me with brackets and quotes I just want the text). The controller code is as follows
$idpiso=$request->get('pisoroom');
$nombrepiso=DB::table('levels')->where('id',$idpiso)
->pluck('nombre');
$rooms=Room::create([
'ubicacion'=>$nombrepiso
]);
The problem is given because the where function returns an array, so it saves it with the format [value] since you indicate that you are going to leave only the name of all the fields, when you call pluck ('name')
If you do the following you will realize what I mean:
So in order for you to get what you want, you only have to call the first function since it is understood that you only want 1 and if you search for the id, this being almost always the primary key, you will only find 1. Therefore, when doing this:
You can now save the name as expected. I hope you resolve this.