1

I am passing a variable with form view to get values from database in form.

public function getGeneralSettings()
    {

        $generalsetting = DB::table('generalsettings')
                ->where('id', '=', 1)
                ->get();
        return view('backend.generalsettings.add-general')->with('general', $generalsetting);
    }

What i am getting is :

[{"id":1,"sitename":"eqwe","tagline":"ewqewq","logo":"1492084338.jpg","firstemail":"qwewq","secondemail":"ewqewq","firstphone":21321,"secondphone":32132,"address":"
dassa<\/p>","facebook":"dqw","twitter":"q","linkedin":"q","google":"q","youtube":"q","instagram":null,"reddit":"q","rss":"q","created_at":"2017-04-13 11:52:18","updated_at":"2017-04-13 11:52:18"}]

I wana show these values in my form fields.

<div class="form-group">
                        <label for="sitename">Site Name</label>
                        <input type="text" id="sitename" name="sitename" class="form-control" value="" placeholder="Site name">
                    </div>

                    <div class="form-group">
                        <label for="tagline">Tagline</label>
                        <input type="text" id="tagline" name="tagline" placeholder="Tagline" value="" class="form-control">
                    </div>

How to call them in particular value field. Please help

2 Answers 2

1

simply use {{}}

<div class="form-group">
    <label for="sitename">Site Name</label>
    <input type="text" id="sitename" name="sitename" class="form-control" value="{{$general->sitename}}" placeholder="Site name">
</div>

<div class="form-group">
    <label for="tagline">Tagline</label>
    <input type="text" id="tagline" name="tagline" placeholder="Tagline" value="{{$general->tagline}}" class="form-control">
</div>

Also use first() instead of get() to get single object

Sign up to request clarification or add additional context in comments.

1 Comment

Thank u.. I tried the value="{{$general->sitename}}" before.. bt i was getting error. Main issue was first(); Thank you! :)
1

Change your controller code to

public function getGeneralSettings()
{

    $generalsetting = DB::table('generalsettings')
            ->where('id', '=', 1)
            ->first();
    return view('backend.generalsettings.add-general')->with('general', $generalsetting);
}

Whenever you want to retrieve a single row result, use first() instead of get(), get() is used for getting multiple records.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.