Hello (I'm just learning),
I need in the value to assign the value of the id. Example: <option value="{{$idcategoriacuenta}}">{{$categoria}}</option>
The problem is in the array () I do not know how to send the value of the category and the idcategoriacuenta
I have the following code:
In the Model :
class Cuentasconcategoria extends Model
{
protected $table='view_cuentasconcategoria';
public $timestamps=false;
protected $fillable =[
'idcategoriacuenta',
'cuenta',
'categoria',
];
}
In the driver
public function create(){
$categoriacuenta=Cuentasconcategoria::all();
$attributes = array();
foreach ( $categoriacuenta as $v ) {
if ( !isset($attributes[$v->cuenta]) ) {
$attributes[$v->cuenta] = array();
}
$attributes[$v->cuenta][$v->categoria] = $v->categoria;
}
return view ('inventario.articulo.create',
["attributes"=>$attributes]);
}
In the view:
<select>
@foreach ( $attributes as $key => $cuenta)
<optgroup label="{{$key}}">
@foreach ( $cuenta as $categoria )
<option value="{{$categoria}}">{{$categoria}}</option>
@endforeach
</optgroup>
@endforeach
</select>
If the previous code works I just need to assign the value with the id