更新状态问题
Update status problems
我正在尝试更新状态。如果状态为 0,则在单击时必须将其更新为 1。但是如果在单击时状态为 1,则必须将其更新为 0。
我的控制器
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::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>
您好,请调试!
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!');
}
}
如果一切正常,请检查 Course
class 的 fillable
变量,status
可能在 fillable
数组
中丢失
我正在尝试更新状态。如果状态为 0,则在单击时必须将其更新为 1。但是如果在单击时状态为 1,则必须将其更新为 0。
我的控制器
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::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>
您好,请调试!
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!');
}
}
如果一切正常,请检查 Course
class 的 fillable
变量,status
可能在 fillable
数组