Laravel-更新表上的值 [英] Laravel - Update values on Table
本文介绍了Laravel-更新表上的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,如何更新表格上的数据?还使用一个foreach循环来获取所有数据.帮助谢谢
Hello how could i update my data on a table? using also a foreach loop to get all data. help thanks
现在我的代码给我一个错误,这是我的错误
right now my code is giving me an error here is my error
函数App \ Http \ Controllers \ Admin \ SettingsController :: index()的参数太少,已传递1个,恰好期望2个
Too few arguments to function App\Http\Controllers\Admin\SettingsController::index(), 1 passed and exactly 2 expected
我的 index.php,表
my index.php , table
{!! 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() !!}
我的 控制器
my Controller
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'));
}
推荐答案
尝试一下
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'));
}
这篇关于Laravel-更新表上的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文