<?php

namespace App\Models;

use Auth;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\Tags\HasTags;

class Article extends Model
{
    use HasTags, HasFactory;

    protected $table = "articles";
    protected $guarded = [];

    protected $attributes = [
        "is_visible" => 1,
    ];

    protected $casts = [
        "published_at" => "datetime",
    ];

    public static function boot()
    {
        parent::boot();
        static::creating(function ($model) {
            $user = Auth::user();
            $model->created_by = $user->name ?? "";
            $model->updated_by = $user->name ?? "";
        });
        static::updating(function ($model) {
            $user = Auth::user();
            $model->updated_by = $user->name ?? "";
        });
    }
}
