Issue
I'm trying to update status. if status is 0 then on click it must update it to 1. but if status is 1 on click it must update it to 0.
my controller
public function status(Course $course)
{
if ($course->status == 0) {
$course->update(['status' => '1']);
return redirect('/profile')->with('statusOn', 'status on!');
} else {
$course->update(['status' => '0']);
return redirect('/profile')->with('statusOff', 'status off!');
}
}
route
Route::post('/course/status/{course}', [CourseManagementController::class, 'status']);
blade
<form method="POST" action="/course/status/{{$c->id}}">
@csrf
@if($c->status == 0)
<button type="submit" class="btn btn-success">active</button>
@else
<button type="submit" class="btn btn-danger">deactive</button>
@endif
</form>
Solution
Hi there please debug !
public function status(Course $course)
{
dump($course); // the data is okay or not
if ($course->status == 0) {
$status = $course->update(['status' => '1']);
dd($status); // check the update status
// return redirect('/profile')->with('statusOn', 'status on!');
} else {
$status = $course->update(['status' => '0']);
dd($status); // check the update status
// return redirect('/profile')->with('statusOff', 'status off!');
}
}
If everything looks okay, please check fillable
variable of your Course
class, status
might missing in fillable
array
Answered By - abSiddique
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.