secara otomatis membuat create_by dan update_by laravel
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Auth;
class Flight extends Model {
use SoftDeletes;
use Notifiable;
/**
* Table name
* @var variable
*/
public $table = 'flight';
/**
* For Soft delete
* @var array
*/
protected $dates = ['deleted_at'];
protected static function boot() {
parent::boot();
static::creating(function ($model) {
$model->created_by = is_object(Auth::guard(config('app.guards.web'))->user()) ? Auth::guard(config('app.guards.web'))->user()->id : 1;
$model->updated_by = NULL;
});
static::updating(function ($model) {
$model->updated_by = is_object(Auth::guard(config('app.guards.web'))->user()) ? Auth::guard(config('app.guards.web'))->user()->id : 1;
});
}
}
Irfan