Show the route please :)
Feb 14, 2023
9
Level 1
Update on click
Trying to update status for a specific record in my table when a button is clicked.
Controller function:
public function push(Request $request, Competition $competition)
{
$competition->update(['status' => 'to_push']);
$competition->save();
}
The new button:
<a class="btn btn-dark btn-sm me-1" href="{{ route('competitions.index',$competition->id) }}">Push</a>
It only refreshes the page and does not change the value. What am I doing wrong?
Level 102
But you probably want to use a POST or PUT route and a form instead of this, so you can have csrf
Route::put('competitions/push/{competition}', [CompetitionController::class, 'push'])->name('competitions.push');
//and
<form action="{{ route('competitions.push',$competition->id) }}" method="post">
<button class="btn btn-dark btn-sm me-1">Push</button>
@csrf
@method('put')
</form>
and you want to send the user back to the page afterwards
public function push(Request $request, Competition $competition)
{
$competition->update(['status' => 'to_push']);
$competition->save();
return back(); //go back
}
1 like
Please or to participate in this conversation.