您好,如何更新表格上的数据?还使用一个foreach循环来获取所有数据。帮助谢谢
现在我的代码给我一个错误,这是我的错误
函数App \ Http \ Controllers \ Admin \ SettingsController :: index()的参数太少,传递了1个参数,而恰好是2个参数
我的 index.php,表
{!! Form::open(['action' => ['Admin\SettingsController@update', $setting->id], 'method' => 'POST']) !!}
<tbody>
@foreach ($settings as $setting)
<tr>
<td> {{Form::text('settings_code', $setting->settings_code, ['class' => 'form-control', 'placeholder' => 'Enter a Flight Number'])}}</td>
<td>{{ $setting->subject }}</td>
<td>{{ $setting->description }}</td>
<td>
{{Form::hidden('_method', 'PUT')}}
{{Form::submit('Update', ['class'=>'btn btn-primary',
'name'=>'submit'])}} <br><br>
</td>
</tr>
@endforeach
</tbody>
{!! Form::close() !!}
我的 控制器
public function index()
{
$settings = Setting::where('settings_code', '<>', 'SESSION_VALIDITY')->get();
$setting = Setting::find($id);
$setting->settings_code = $request->input('settings_code');
$setting->save();
return view('admin.settings.index', compact('settings'));
}
答案 0 :(得分:0)
尝试一下
public function index(Request $request,$id)
{
$settings = Setting::where('settings_code', '<>', 'SESSION_VALIDITY')->get();
$setting = Setting::find($id);
$setting->settings_code = $request->input('settings_code');
$setting->save();
return view('admin.settings.index', compact('settings'));
}