<?php

namespace App\Models;


use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;


class Professeur extends Model
{  
    //
    use HasFactory;
    protected $fillable = ['id','nomar','nomfr','matricule','nni','date_naissance','lieu_naissance_ar','lieu_naissance_fr','discipline_origine','contact','statut_id','cycle_id','photo','date_recritement'];

    public function statut(): BelongsTo
    {
        return $this->belongsTo(Statut::class);
    }

    public function cycle(): BelongsTo
    {
        return $this->belongsTo(Cycle::class);
    }

    public function etablissements()
    {
        return $this->belongsToMany(
            Etablissement::class,
            'etab_profs',
            'professeur_id',
            'etablissement_id'
        )
        ->withPivot(['date_affectation', 'date_fin'])
        ->withTimestamps();
    }

}
