【发布时间】:2019-09-04 00:23:01
【问题描述】:
R : 我如何将 (id) url 插入数据库 Laravel
我有这个网址:
http://127.0.0.1:8000/admin/question/1
我需要将 id 保存到数据库中
路线
Route::get('/question/{id}', 'questionController@choseType');
Route::post('/question/createone', 'questionController@storeData');
控制器
public function storeData(Request $request)
{
$this->validate($request,[
'name'=>'required',
'department_id'=>'required',
'nameChoose.*'=>'required',
],[],[
'name'=>'question',
'department_id'=>'department name',
'nameChoose'=>'nameChoose',
]);
//here i want to save the id of this table to the question table
// which exist in URL
$question_type = question_types::pluck('id')->first();
$question = new questions();
$question->name = $request->input("name");
$question->department_id = $request->input("department_id");
$question->question_type_id = $question_type;
$question->save();
}
有什么帮助吗?
【问题讨论】: