Solution 1 :

After looking at your controller code, I see a problem in edit function. It should be like this:

public function edit($id)
{
    $settings = Setting::find($id);

    return view('pages.settings.edit', ['settings' => compact('settings')]);

}

And now, the option tag in your view will be

<option value="{{$settings->domain_url}}"  {{ $settings->domain_url != "" ? 'selected' : '' }}>{{$settings->domain_url}}</option>

Problem :

I have a simple form in which the user has options to selected desired input field so in pages.create selection option looks like this

        <div class="row">
              <label class="col-sm-2 col-form-label">{{ __('Ads Type') }}</label>
              <div class="col-sm-7">
                  <div class="form-group">
                      <select id="inputStatus" class="form-control" name="ad_type">
                          <option selected>Please select ad type </option>
                          <option>InView video Ads</option>
                          <option>InPage video ads</option>
                          <option>Sticky video Ads</option>
                          <option>InPage video ads</option>
                          <option>InApp video ads</option>
                          <option>Ad-Enabled Video Player</option>

                      </select> 
                  </div>
              </div>
          </div>

Now, after the user submits the data, I am displaying them in pages.index, now I would like the user to be able to edit those options

Here is my controller

<?php

namespace AppHttpControllers;

use IlluminateHttpRequest;
use AppSetting;

class SettingController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return IlluminateHttpResponse
     */
    public function index()
    {
        $settings = Setting::all();

        return view('pages.settings.index', compact('settings'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return IlluminateHttpResponse
     */
    public function create()
    {
        $setting = Setting::all();
        return view('pages.settings.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  IlluminateHttpRequest  $request
     * @return IlluminateHttpResponse
     */
    public function store(Request $request)
    {
        $setting = Setting::create([
            'domain_url' => $request->get('domain_url'),
            'tag_url' => $request->get('tag_url'),
            'ad_type' => $request->get('ad_type'),
            'video_format' => $request->get('video_format'),
        ]);

          //  dd($request);

          $setting->save();
          return redirect("/settings")->with("sucess", "data saved");
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return IlluminateHttpResponse
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return IlluminateHttpResponse
     */
    public function edit($id)
    {
        $settings = Setting::find($id);

        return view('pages.settings.edit', compact('settings'));

    }

    /**
     * Update the specified resource in storage.
     *
     * @param  IlluminateHttpRequest  $request
     * @param  int  $id
     * @return IlluminateHttpResponse
     */
    public function update(Request $request, $id)
    {
        $settings = Setting::find($id);
        $settings->domain_url = $request->get('domain_url');
        $settings->tag_url = $request->get('tag_url');
        $settings->ad_type = $request->get('ad_type');
        $settings->video_format = $request->get('video_format');
        $settings->save();

        return redirect("/settings")->with("success", "Data updated");
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return IlluminateHttpResponse
     */
    public function destroy($id)
    {
        $settings = Setting::find($id);

        $settings->delete();

        return redirect("/settings")->with("sucess", "data updated");
    }
}

Now in my pages.edit I have this

        <div class="row">
                  <label class="col-sm-2 col-form-label">{{ __('Ads Type') }}</label>
                  <div class="col-sm-7">
                      <div class="form-group">
                          <select id="inputStatus" class="form-control" name="ad_type">
                              <option value="{{$settings->domain_url}}"  {{ old('domain_url') == 1 ? 'selected' : '' }}>
                              <option value="{{$settings->tag_url}}"  {{ old('tag_url') == 1 ? 'selected' : '' }}>
                              <option value="{{$settings->ad_type}}" {{ old('ad_type') == 1 ? 'selected' : '' }}>
                              <option value="{{$settings->video_format}}" {{ old('video_format') == 1 ? 'selected' : '' }}>
                          </select> 
                      </div>
                  </div>
              </div>

Now when I click edit it shows empty input , what am I doing wrong with my code?

Comments

Comment posted by Foued MOUSSI

Could you add full controller / blade code ?

Comment posted by The Dead Man

@FouedMOUSSI check update

Comment posted by AH.Pooladvand

Are you sure that

Comment posted by AH.Pooladvand

Please consider to be more strict and change

Comment posted by sac2811

I have updated my answer based on your controller code..please check now

By