DolDurma
DolDurma

Reputation: 17289

laravel how to get single row and post to view

in MySql database i have systemSetting table and this have any data.

in this table i have this fields :

id  -  site_copyright -  date 

i want to fill form with this single row.

{{ 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() }}

UPDATE: in CONTROLLER of that i have this:

public function getIndex()
{
    $siteSettings = SystemSetting::all();
    return  View::make('back_end.layouts.manageHeaders')->with('siteSettings', $siteSettings);
}

in Result, form could not parse data to input fields.

i get error for this :

   $siteSettings->site_copyright

Upvotes: 0

Views: 8148

Answers (3)

ImBhavin95
ImBhavin95

Reputation: 1527

Query work on 5.1 or more

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

Upvotes: 0

revo
revo

Reputation: 48711

You're using form model binding, so change your controller to:

public function getIndex()
{
    $siteSettings = new SystemSetting;
    return  View::make('back_end.layouts.manageHeaders', compact('siteSettings'));
}

Upvotes: 0

Simo A.
Simo A.

Reputation: 1360

This is a duplicate of many questions, such as this: Laravel display table record using query

The short answer is: use first() method to get a single entry.

Upvotes: 2

Related Questions