有人可以帮我吗?
我正在尝试从表单获取数据并划分为几个模型。我从表格获取数组并将每个模型的数据添加到数据库时遇到问题。
代码:
<div class="form-check form-check-success">
<label class="form-check-label">
{!! Form::checkbox('certification_id[]', '1', false, ['class' => 'form-check-input']) !!}
Data
</label>
</div>
<div class="form-check form-check-success">
<label class="form-check-label">
{!! Form::checkbox('certification_id[]', '2', false, ['class' => 'form-check-input']) !!}
Data
</label>
</div>
控制器代码:
public function store(CreateWaybillRequest $request) {
$waybill = new Waybill($request->all());
$certifications = new WaybillCertification($request->$_POST['certification_id']);
//$id = Auth::user()->waybills()->save($waybill)->id;
return print_r($certifications);
请求类:
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class CreateWaybillRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'weight' => 'required',
'fromDate' => 'required|date',
'damage' => 'required',
'fuelUsed' => 'required',
'toDate' => 'required|date',
'length' => 'required'
];
}
}
答案 0 :(得分:0)
这是错误的-
$certifications = new WaybillCertification($request->$_POST['certification_id']);
您不会像这样访问请求数据。
改为执行此操作-
$request->certification_id
它将为您提供您的certificate_id请求的数组。
我也希望您阅读文档并首先学习基础知识-