0
我有幾個表單用不同的驗證規則創建不同的記錄。Laravel創建新記錄錯誤
我的路線(web.php)文件:
Route::group(['middleware' => ['auth']], function() {
Route::get('/home', '[email protected]')->name('home');
Route::get('/home/info/create/{id}', '[email protected]');
Route::post('/home', '[email protected]')->name('home');
Route::get('/home/info/delete/{id}', '[email protected]');
Route::get('/home/odbor/create/{id}', '[email protected]');
Route::post('/home', '[email protected]')->name('home');
Route::get('/home/odbor/delete/{id}', '[email protected]');
Route::get('/home/zamestnanec/create/{id}', '[email protected]');
Route::post('/home', '[email protected]')->name('home');
Route::get('/home/zamestnanec/delete/{id}', '[email protected]');
Route::get('/home/program/create/{id}', '[email protected]');
Route::post('/home', '[email protected]')->name('home');
Route::get('/home/program/delete/{id}', '[email protected]');
});
科瑞,存儲,刪除功能: (功能呈三角在所有控制器)
public function create(Fakulta $id)
{
return view('create.info', compact('id'));
}
public function store(CreateInfoRequest $request)
{
Info::create($request->all());
return redirect('home');
}
public function delete($id)
{
Info::where('id',$id)->delete();
return redirect('home');
}
而且問題是,當我想創建新的例如觸摸submite按鈕後,信息(/ home/info/create)出現驗證錯誤。驗證是使用中間件組(ProgramController @ store)的上一個控制器中指定的文件,我不知道爲什麼。但是當我移動Route :: post('/ home','InfoController @ store') - > name('home');在組的最後一行或創建新程序(/ home/program/create)一切正常。
更簡單:
提交按鈕觸摸後不使用這個文件
CreateInfoRequest.php文件:
public function rules()
{
return [
'title' => 'required',
'description' => 'required',
'event_date' => 'required|date|after:today'
];
}
但是這一個: CreateProgramRequest.php
public function rules()
{
return [
'title' => 'required',
'titul' => 'required',
'length' => 'required',
'forma' => 'required',
'typ'=> 'required',
'description' => 'required',
'fakulta_id' => 'required',
];
}
謝謝,我在Form :: open中編輯所有Route :: post和所有'url'。它正在運行 – Bando
@Bando很高興幫助! –
@Bando如果我的答案是你的解決方案,那麼請upvote到我的答案 –