尝试获取非对象的属性(视图:C:\ xampp \ htdocs \ MyP \ resources \ views \ pekerja \ index.blade.php)

时间:2019-05-23 00:55:06

标签: sql laravel model-view-controller relationship

我在此代码上遇到“试图获取非对象属性”的问题。请有人检查此代码以使我清楚。 TQ

index.blade.php

<div class="form-group">
    <label for="idUnit" class="control-label col-sm-3">Unit :</label>
    <div class="col-sm-9">
        <select name="idUnit" class="form-control input-sm" id="idUnit" disabled="disabled">
            <option value="">Sila Pilih...</option> ---> error on this code!
            @foreach ($KodUnit as $unit)
                <option value="{{ $unit->id }}"
                    @if(isset(request()->idUnit) && request()->idUnit == $unit->id)
                        selected="selected"
                    @endif
                >{{ $unit->nama }}</option>
            @endforeach
        </select>
    </div>
</div>```
kodUnit model:
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class KodUnit extends Model
{
    protected $table = 'kod_unit';

    protected $primaryKey = 'id';

    protected $fillable = ['id', 'kod', 'nama'];

    public $timestamps = false;

}

0 个答案:

没有答案