Reputation: 199
I have a small problem with my Controller action. I can't update my "link" in Database, bt dd
method work is correctly when I'm try to check data.
Form
<form class="col-lg-push-6" action="/admin/links/{{$link->id}}/update" method="POST">
@csrf
<div class="form-group bmd-form-group">
<label class="bmd-label-floating">New Link Value</label>
<input type="text" class="form-control" size="100" name="value">
<button class="btn btn-primary" type="submit">Update</button>
</div>
</form>
Controller
public function update(Request $request, $id)
{
$this->validate($request, [
'value' => 'required'
]);
$link=RedirectUrl::AllLinks()->where('id', $id);
$link->value = $request->input('value');
return redirect()->back()->with('message', 'Link Updated!');
}
Model
public function scopeAllLinks($query){
return $query->get();
}
Route
Route::prefix('admin')->middleware('auth')->group(function(){
Route::get('/', 'Admin\IndexController@index');
Route::get('dashboard', 'Admin\IndexController@index')->name('dashboard');
Route::get('links', 'Admin\LinkController@index')->name('links');
Route::get('links/{id}', 'Admin\LinkController@linkById');
Route::post('links/{id}/update', 'Admin\LinkController@update');
});
Upvotes: 1
Views: 170
Reputation: 18197
Few things here:
Your scopeAllLinks
scope is incorrect, you don't call get
inside a scope, instead you return the query builder instance.
You can use find
since you're passing in a record id:
$link = RedirectUrl::find($id);
You never call save or update on the record:
$link->value = $request->input('value');
$link->save(); // <--- add this
Upvotes: 1