laravel-update表上的值

guicsvcw  于 2021-06-17  发布在  Mysql
关注(0)|答案(1)|浏览(606)

喂,我怎样才能更新表上的数据?还使用foreach循环获取所有数据。帮帮忙谢谢
现在我的代码给了我一个错误这里是我的错误
函数app\http\controllers\admin\settingscontroller::index()的参数太少,传递了1个,实际需要2个
my 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'));
}
rwqw0loc

rwqw0loc1#

试试这个

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'));
}

相关问题