Я настраиваю учетное веб-приложение, используя Laravel, и мне нужна форма, где можно ввести все поля и затем сохранить их в базе данных, все работает нормально, когда я использую тинкер или отправляю одну строку, нокогда я пытаюсь отправить всю форму, читается только последняя строка.
это rota.blade.php
файл
{!! Form::open(['action' => 'RotaController@store', 'method' => 'POST', 'enctype' => 'multipart/form-data']) !!}
<table class="table table-striped table-bordered">
<thead class="thead-dark">
<tr>
<th scope="row">Name</th>
<th scope="row">Sunday</th>
<th scope="row">Monday</th>
<th scope="row">Tuesday</th>
<th scope="row">Wednesday</th>
<th scope="row">Thursday</th>
<th scope="row">Friday</th>
<th scope="row">Saturday</th>
</tr>
</thead>
<tbody>
<!--
* create a loop to iterate through each instance in the weekly rota database
* and create a row for each one; in case the username coincides with the name in the rota
* add class="active" to each row, so it is easier for the user to identify its own row
-->
@csrf
@foreach ($users as $user)
<tr>
<th scope="row">
{{$user->first_name}}
<input name="user_id" type="hidden" value="{{$user->id}}">
<input name="week_no" type="hidden" value="{{$currWeek}}">
</th>
<th scope="row">
{{Form::text('sunday', '', ['class' => 'form-control'])}}
</th>
<th scope="row">
{{Form::text('monday', '', ['class' => 'form-control'])}}
</th>
<th scope="row">
{{Form::text('tuesday', '', ['class' => 'form-control'])}}
</th>
<th scope="row">
{{Form::text('wednesday', '', ['class' => 'form-control'])}}
</th>
<th scope="row">
{{Form::text('thursday', '', ['class' => 'form-control'])}}
</th>
<th scope="row">
{{Form::text('friday', '', ['class' => 'form-control'])}}
</th>
<th scope="row">
{{Form::text('saturday', '', ['class' => 'form-control'])}}
</th>
</tr>
@endforeach
{{Form::submit('Submit', ['class' => 'btn btn-primary'])}}
</tbody>
</table>
{!! Form::close() !!}
, а это RotaController@store
:
public function store(Request $request)
{
//validation
$this->validate($request,[
'user_id' => 'required',
'sunday' => 'required',
'monday'=> 'required',
'tuesday'=> 'required',
'wednesday'=> 'required',
'thursday'=> 'required',
'friday'=> 'required',
'saturday'=> 'required',
'week_no'=> 'required'
]);
//create a field
$rota = new Rota;
$rota->user_id = $request->input('user_id');
$rota->week_no = $request->input('week_no');
$rota->sunday = $request->input('sunday');
$rota->monday = $request->input('monday');
$rota->tuesday = $request->input('tuesday');
$rota->wednesday = $request->input('wednesday');
$rota->thursday = $request->input('thursday');
$rota->friday = $request->input('friday');
$rota->saturday = $request->input('saturday');
$rota->save();
$users = DB::table('users')->orderBy('first_name', 'asc')->get();
return view('admin.admin-rota')->with('users', $users);
}
Я попытался dd($request)
, и он на самом деле получает только последний набор полей ввода, я думаю, что я должен пройти через них, но я не знаю, как.У кого-нибудь есть предложения, что попробовать?Большое спасибо за любые отзывы, я все еще очень новичок в использовании этого фреймворка.