当我尝试向表中插入数据时
传递给Illuminate \ Database \ Grammar :: parameterize()的参数1必须为数组类型,给定字符串,在C:\ xampp \ htdocs \ Portal \ vendor \ laravel \ framew中调用...
class InitialWorker(ctx: Context, params: WorkerParameters) : Worker(ctx, params) {
override fun doWork(): Result {
// Do Something Useful
// Enqueue the periodic Worker
val dailyWorkRequest = PeriodicWorkRequestBuilder<DailyWorker>(1, TimeUnit.DAYS)
.addTag(TAG_OUTPUT)
.build()
WorkManager.getInstance(applicationContext).enqueue(dailyWorkRequest)
return Result.success()
}
}
<form method="post" action="{{ route('notice.store') }}">
{{ csrf_field() }}
<div class="form-group">
<label for="Select Group to Post Notice">Select Group to Post Notice </label>
<select class="bg-white text-danger form-control " name='GroupID[]' multiple>
@foreach ($users as $user)
<option value="{{ $user->GroupID }}">{{ $user->GroupID }}</option>
@endforeach
</select>
</div>
<div class="form-group">
<label for="Enter Notice">Enter Notice</label>
<input class="bg-white text-danger p-2 form-control form-control-sm" type="text" name="Notice" placeholder="Enter Notice">
</div>
<input class="btn btn-danger btn-lg px-5" type="submit" name="submit">
</form>
答案 0 :(得分:2)
我想您收到此错误的原因是:
$storeInfo->GroupID = $request->input('GroupID');
$request->input('GroupID')
将返回一个数组(name='GroupID[]'
),而不是单个ID。
由于您已经遍历了组ID,因此可以改用GroupId
的值:
public function store(Request $request)
{
foreach ($request->input('GroupID') as $groupId) {
$storeInfo = new notice();
$storeInfo->GroupID = $groupId; //<--here
$storeInfo->Notice = $request->input('Notice');
$storeInfo->save();
}
return redirect('notice');
}
答案 1 :(得分:-1)
尝试更改控制器逻辑
public function store(Request $request)
{
//
$member=$request->input('GroupID');
foreach($member as $value){
$storeInfo = new notice();
$storeInfo->GroupID = $value;
$storeInfo->Notice = $request->input('Notice');
$storeInfo->save();
}
return redirect('/notice');
}