﻿<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Schema;
use App\Scopes\OrganisationScope;
use Illuminate\Support\Facades\Auth;

class SeoField extends Model
{
protected $guarded  = [];
    use HasFactory;
    public $timestamps = false;

    protected $fillable = [
        'route',
        'name_route',
        'meta_title',
        'meta_keywords',
        'meta_description',
        'meta_robot',
        'canonical_url',
        'custom_url',
        'json_ld',
        'og_title',
        'og_description',
        'og_image',
        'organisation_id'
    ];

    /**
     * Get the column names of the table.
     *
     * @return array
     */
    public static function getColumnNames()
    {
        return Schema::getColumnListing((new self)->getTable());
    }


protected static function booted()
    {
        static::addGlobalScope(new OrganisationScope);

        // Automatically set the organisation_id before creating the model
        static::creating(function ($model) {
            if (Auth::check()) {
                $model->organisation_id = Auth::user()->organisation_id;
            }
        });
    }