Model: Record (id,user_id, status_id, date, note, timestamp) class Record extends Model { function status(){ return $this->belongsTo(‘App\SmokingStatus’,’status_id’); } } Model: Status(id,name) class Status extends Model { function record() { return $this->hasMany(‘App\Record’,’id’,’status_id’); } } If you try to access it directly like this {{$record->status->name }} it will return “Trying to get property of non-object”. You need to access…
View
-
Kadangkala kita perlu panggil beberapa model dalam satu page First kena panggil model sebelum class controller seperti berikut use App\Parcel; use App\Distributor; use App\Courier; class ParcelsController extends Controller { … Kemudian panggil seperti berikut dalam class controller. Disini kita pass lebih daripada satu variable (array). public function create() { // $distributors = Distributor::all(); $couriers = Courier::all(); return view(‘parcels.create’,compact(‘couriers’,’distributors’));…
-
Some function is created to make code easy to read and manageable. The Lookup function is so powerfull to simplified data storage. Usually we store Approve, Not Approved, Qualified, Not Qualified in words for each records, but with Lookup class, we can make it short to an integer for each properties. Table scheme “tbl_lookup” [php]…