Demo entry 3548974

php

   

Submitted by anonymous on Jan 20, 2016 at 14:59
Language: PHP. Code size: 1.2 kB.

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Carbon\Carbon;

class Training extends Model
{
    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'training';

    protected $primaryKey = 'idtraining';

    protected $dates = ['tgltraining'];

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'namatraining', 
        'lokasi', 
        'nomorsurat',
        'anggaran', 
        'tgltraining', 
        'keterangan',
        'penyelenggara',
    ];

    public function scopeFuture($query)
    {
        $query->where('tgltraining', '>=', Carbon::today());
    }

    public function setTgltrainingAttribute($date)
    {
        $this->attributes['tgltraining'] = Carbon::parse($date);
    }

    public function getTgltrainingAttribute($date)
    {
        return new Carbon($date);
    }

    public function pegawai()
    {
        return $this->belongsToMany('App\Pegawai');
    }

    public function getPegawaiListAttribute()
    {
        return $this->pegawai->lists('idpegawai')->all();
    }
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).