I am stuck for 1 day on a problem. I have an error message, in my file edit.blade.php
"Undefined variable: marks (View: C:\wamp64\www\azerty\resources\views\admin\series\edit.blade.php)"
Small screenshot below
My problem is at the line 33, perhaps the loop ?
Here is my file edit.blade.php
form class="panel-body" action="{{route('series.update',$series->id)}}" method="POST">
<input name="_method" type="hidden" value="PATCH">
@csrf
<fieldset class="form-group">
<label for="form-group-input-1">Name</label>
<input type="text" name="name" class="form-control" id="form-group-input-1" value="{{$series->name}}">
</fieldset>
<div class="form-group">
<label for="company-content">Select Mark</label>
<select name="fk_mark" id="" class="form-control">
@foreach($marks as $mark)
<option value="{{$mark->id}}">{{$mark->name_mark}}
</option>
@endforeach
</select>
</div>
I also think my problem is in the SerieController?
public function edit($id)
{
$series = Serie::with('marks')->find($id);
return view('admin.series.edit', compact('series'));
}
public function update(Request $request, $id)
{
$request->validate([
'name' => 'required',
'fk_mark' => 'required'
]);
$series = Serie::with('marks')->find($id);
$series->name = $request->get('name');
$series->fk_mark = $request->get('fk_mark');
$series->save();
return redirect()->route('series.index')
->with('success', 'updated successfully');
}
For information, here is also my file index.blade.php
<table class="table">
<a class="btn btn-sm btn-success" href="{{ route('series.create') }}">Ajouter</a>
<thead>
<tr>
<th>Serie Car</th>
<th>Mark Car</th>
</tr>
</thead>
@foreach($series as $serie)
<tr>
<td> {{$serie->name}}</td>
<td> {{$serie->marks->name_mark}}</td>
<td>
<form method="POST" action="{{ route('series.destroy', $serie) }} ">
<a class="btn btn-sm btn-warning" href="{{route('series.edit',$serie->id)}}">Editer</a>
@csrf
@method('DELETE')
<button type="submit" class="btn btn-sm btn-danger">Deleter</button>
</form>
</td>
</tr>
@endforeach
</table>
Thank you for your help.