Я пытаюсь обновить или создать записи.Если у пользователя есть записи в базе данных, просто обновите записи, а если у пользователя нет записей в базе данных, просто создайте записи по входам.Ошибка:
Ошибка типа: слишком мало аргументов для функции App \ Http \ Controllers \ ChoicesController :: store (), 1 пройдено и ожидается ровно 2
public function store(Request $request,$id){
$time = $request->input('time');
$user = Choice::where('user_id','=',Auth::id())->first();
if ($user === null) {
foreach ($request->input('number') as $key => $value) {
Choice::create([
'user_id' => Auth::id(),
'time' => $time,
'topic_id' => $key,
'question_number' => $value,
]);
}
}
else {
$result = Choice::find($id);
foreach ($request->input('number') as $key => $value) {
$result->user_id = Auth::id();
$result->time = $request->$time;
$result->question_number = $request->$value;
$result->topic_id = $request->$key;
}
$result->save();
}
return redirect()->route('choices.index');
}
Это мои маршруты.
Route::group(['middleware' => 'auth'], function () {
Route::get('/home', 'HomeController@index')->name('views.home');
Route::post('tests/custom', 'TestsController@custom')->name('tests.custom');
Route::post('exams/custom', 'ExamsController@custom')->name('exams.custom');
Route::post('laws.store',['as'=>'add.category','uses'=>'LawsController@store']);
Route::resource('laws', 'LawsController');
Route::resource('choices', 'ChoicesController');
Route::resource('legals', 'LegalsController');
Route::resource('faqs', 'FAQsController');
Route::resource('guides', 'GuidesController');
Route::resource('materials', 'MaterialsController');
Route::resource('tests', 'TestsController');
Route::resource('exams_results', 'ExamsResultController');
Route::resource('roles', 'RolesController');
Route::resource('videos', 'VideosController');
Route::resource('exams', 'ExamsController');
Route::resource('users', 'UsersController');
Route::resource('user_actions', 'UserActionsController');
Route::resource('topics', 'TopicsController');
Route::resource('questions', 'QuestionsController');
Route::resource('questions_options', 'QuestionsOptionsController');
Route::resource('results', 'ResultsController');
Route::post('users_mass_destroy', ['uses' => 'UsersController@massDestroy', 'as' => 'users.mass_destroy']);
Route::post('roles_mass_destroy', ['uses' => 'RolesController@massDestroy', 'as' => 'roles.mass_destroy']);
Route::post('topics_mass_destroy', ['uses' => 'TopicsController@massDestroy', 'as' => 'topics.mass_destroy']);
Route::post('questions_mass_destroy', ['uses' => 'QuestionsController@massDestroy', 'as' => 'questions.mass_destroy']);
Route::post('questions_options_mass_destroy', ['uses' => 'QuestionsOptionsController@massDestroy', 'as' => 'questions_options.mass_destroy']);
Route::post('results_mass_destroy', ['uses' => 'ResultsController@massDestroy', 'as' => 'results.mass_destroy']);
Route::delete('/delete/law/{id}','LawsController@destroy');
});