Php laravel如何获取单行和post以查看
在MySql数据库中,我有systemSetting表,这有任何数据 在此表中,我有以下字段:Php laravel如何获取单行和post以查看,php,laravel,laravel-4,Php,Laravel,Laravel 4,在MySql数据库中,我有systemSetting表,这有任何数据 在此表中,我有以下字段: id - site_copyright - date 我想用这一行填写表格 {{ Form::model($siteSettings) }} {{ Form::label('site_copyright' , 'copy right') }} {{ Form::text('site_copyright', null , array('id'=>'site_copyrigh
id - site_copyright - date
我想用这一行填写表格
{{ Form::model($siteSettings) }}
{{ Form::label('site_copyright' , 'copy right') }}
{{ Form::text('site_copyright', null , array('id'=>'site_copyright' )) }}
{{ Form::label('site_copyright' , 'copy right') }}
{{ Form::text('site_copyright', null , array('id'=>'site_copyright' )) }}
{{ Form::close() }}
更新:
在这方面,我有以下几点:
public function getIndex()
{
$siteSettings = SystemSetting::all();
return View::make('back_end.layouts.manageHeaders')->with('siteSettings', $siteSettings);
}
结果,表单无法将数据解析到输入
字段
我得到一个错误:
$siteSettings->site_copyright
这是许多问题的重复,例如:
简短的回答是:使用
first()
方法获取单个条目。您正在使用表单模型绑定,因此将控制器更改为:
public function getIndex()
{
$siteSettings = new SystemSetting;
return View::make('back_end.layouts.manageHeaders', compact('siteSettings'));
}
5.1或更高版本的查询工作
return DB::table('users')->where('id', $id)->value('field_name');
//if lower version of laravel like 4.2
DB::table('users')->where('id', $id)->pluck('field_name');
您正在调用模型上的视图?是这样吗@丹尼斯布拉加,对不起。不,这是控制器,请解释一下您遇到的错误。这个问题似乎已经得到了回答,因此您应该接受答案或提供更多信息。如果您要按主键查找一行,那么它可能会短一点Model::find(此处为id_)