如何显示带有已存储数据的选中复选框

时间:2019-06-03 02:50:44

标签: php laravel laravel-4.2

我在数据库中有此数据(表allow_upgrade_qualifi):

  1. id = 1,标题=طراحی
  2. id = 2,标题=نظارت
  3. id = 3,标题=اجرا

该数据在视图中随Foreach一起加载:

<div class="col-md-4">
    <div class="checkbox-list">
    @foreach($permit_permit_upgrade_qualifi as $ppuq)
        <label class="checkbox-inline" for="ppuq-label-{{$ppuq->id}}">
            <input type="checkbox" name="ppuq[]" id="ppuq-label-{{$ppuq->id}}" value="{{$ppuq->id}}" {{ $permit_upgrade_qualifi->permit_id = $permit->id  ? 'checked' : '' }}>{{$ppuq->title}}
        </label>
    @endforeach
    </div>
</div>

和我在Controller中的代码:

public function edit($id)
    {
        $idd = Sentry::getUser()->id;
        try {

            $permit = UpgradePermit::findOrFail($id);

            $base = Base::all();
            $permit_permit_upgrade_qualifi = PermitUpgradeQualifi::all();
            $permit_upgrade_qualifi = DB::table('permit_permit_upgrade_qualifi')->where('permit_id', $id)->get();

           // return $permit_upgrade_qualifi;

            $cites = DB::table('provinces')->get();
            $profile = User::find($idd);

            return View::make('manager.user_up_permit.edit', compact('permit','base','permit_permit_upgrade_qualifi','permit_upgrade_qualifi', 'cites', 'profile'));

        } catch (ModelNotFoundException $e) {
            return Redirect::route('dashboard.user.up-permit.index')->with('danger', 'درخواست معتبر نمیباشد.');
        }
    }

并将此数据存储在数据库中的复选框(表permit_permit_upgrade_qualifi):

  1. permit_id = 300 | permit_upgrade_qualifi_id = 1
  2. permit_id = 302 | permit_upgrade_qualifi_id = 1
  3. permit_id = 300 | permit_upgrade_qualifi_id = 2
  4. permit_id = 302 | permit_upgrade_qualifi_id = 2
  5. permit_id = 303 | permit_upgrade_qualifi_id = 2
  6. permit_id = 303 | permit_upgrade_qualifi_id = 3

现在,如何在视图中显示选中的复选框?

谢谢

0 个答案:

没有答案