I have a form to edit the administrators of a post.
This form has some radio buttons. Each radio button corresponds to a administrator of a a post, so the id of each radio button is the id of the admin in the administrators table.
When the submit button is clicked I want to update just the administrator with the id of the checked administrator/radio button.
For that it should be necessary to pass to the update method the id of the post and the id of the checked radio button (administrator) and then update only that administrator id.
Im passing the id of the post with success but the admin id not. It appears syntax error, unexpected '{'.
Edit admins form:
<form method="post" class="clearfix" action="{{route('admins.update', ['id' => $post->id], ['adminID' => $admin->id])}}" enctype="multipart/form-data">
{{csrf_field()}}
@foreach($administrators $admin)
<div class="form-check">
<input class="form-check-input" type="radio" name="radiobutton" id="{{$admin->id}}" value="">
<label class="form-check-label" for="">
{{$admin->first_name}}
</label>
</div>
@endforeach
<!-- below I have form fields like administrator name, email, etc -->
</form>
// update admins routes
Route::get('post/edit/{id}/admins', [ 'uses' => 'AdminController@edit', 'as'=>'admins.edit']);
Route::post('post/update/{id}/admins', [ 'uses' => 'AdminController@update', 'as'=>'admins.update']);
// Admin controller
class AdministratorController extends Controller
{
public function edit($id)
{
$post = Post::find($id);
$administrators = Administrator::where('post_id', $id)->get();
return view('administrators.edit')
->with('post', $post)
->with('administrators', $administrators));
}
public function update(Request $request, $id, $adminID){
$this->validate($request, [
'name' => 'required|string',
'email' => 'required|integer',
'...' => '...',
]);
$post = Post::find($id);
$admin = Administrator::find($post->id);
$administratorToUpdate = Administrator::find($adminID);
$administratorToUpdate->name = $request->name;
$administratorToUpdate->email = $request->email;
....
$administratorToUpdate->save();
}
// Admin model
class Administrator extends Model
{
protected $fillable = [
'first_name', 'email', 'password', 'description', 'post_id'
];
public function post(){
return $this->belongsTo('App\Post');
}
}