我正在尝试使用复选框更新数据库表,代码没有给出任何错误,但是数据库表没有更新。我的刀片代码,表格是:
<body>
<h2>Reported Posts </h2>
<a href="{{route('moderator.index')}}">Back</a>
<table>
@foreach($post_reports as $post_report)
<tr>
<td>Report NO:</td>
<td>{{$post_report->report_id }}</td>
<td>{{$post_report->status}}</td>
<form method="post">
@csrf
<td><input type="checkbox" name="statusyes[]" value={{$post_report->report_id }} >report to admin <input type="checkbox" name="statusno[]" value={{$post_report->report_id}} >wrong report </td>
</tr>
@endforeach
<td><input type="submit" name="submit" value="Submit" /></td>
</form>
</table>
我的控制器代码是:
我正在使用状态更新发布功能
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Post_report;
use Illuminate\Support\Facades\DB;
class moderatorController extends Controller
{
public function index(Request $request){
return view('moderator.index');
}
public function reported_post(Request $request){
$post_reports=DB::table('Post_reports')
->where('status','moderator')->get();
return view('moderator.reported_post')-> with('post_reports',$post_reports);
}
public function status_update_reported_post(Request $request){
$statusadmin[]=$request['statusyes'];
$statuswrong[]=$request['statusno'];
$r='admin';
$wr='wrong';
foreach($statusadmin as $report_id){
DB::table('post_reports')
->where('report_id','$report_id')
->update(['status' => 'admin']);
}
foreach($statuswrong as $report_id){
DB::table('post_reports')
->where('report_id','$report_id')
->update(['status' => 'wrong']);
}
}
}
代码运行良好,但表中没有更新我不知道问题出在哪里,对我来说一切似乎都很好。
1条答案
按热度按时间utugiqy61#
这条线
应该是
单引号表示字符串
$report_id
不是变量的值$report_id