There are two modals attributes & its options
the problem now in options edit blade
This part of code was work correctly in create.blade
**but in edit.blade ** show this error.
Then I try to add this variable to the controller in several ways but still the same error appears
you can find my codes down, please help me
edit.blade
<div class="form-body">
<h4 class="form-section">
<i class="ft-home"></i> Option name
</h4>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="projectinput1"> Choose a feature
</label>
<select name="attribute_id" class="select2 form-control" >
<optgroup label="Choose a feature ">
@if($attributes && $attributes -> count() > 0)
@foreach($attributes as $attribute)
<option
value="{{$attributes -> id }}">{{$attributes -> name}}</option>
@endforeach
@endif
</optgroup>
</select>
@error('attribute_id')
<span class="text-danger"> {{$message}}</span>
@enderror
</div>
</div>
attribute model
public function options() {
return $this->hasMany(Option::class, 'attribute_id');
}
option model
public function attribute() {
return $this->belongsTo(Attribute::class, 'attribute_id');
}
controller
public function edit($id)
{
//get specific options and its translations
$option = Option::orderBy('id', 'DESC')->find($id);
if (!$option)
return redirect()->route('admin.options')->with(['error' => 'this option is not available']);
return view('dashboard.options.edit', compact('option'));
}
public function update($id, OptionsRequest $request)
{
try {
//validation
//update DB
$option = Option::find($id);
if (!$option)
return redirect()->route('admin.options')->with(['error' => 'this option is unavailable']);
if (!$request->has('is_active'))
$request->request->add(['is_active' => 0]);
else
$request->request->add(['is_active' => 1]);
$option->update($request->except('_token', 'id'));
//save translations
$option->name = $request->name;
$option->save();
DB::commit();
return redirect()->route('admin.options')->with(['success' => 'success']);
} catch (\Exception $ex) {
return redirect()->route('admin.options')->with(['error' => 'fail, try again later']);
}
}