<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Volum extends Model
{
    use HasFactory;

    protected $fillable = ['title', 'number', 'law_id'];

    protected $hidden = ['created_at', 'updated_at'];

    public function law()
    {
        return  $this->belongsTo(Law::class);
    }
    public function book()
    {
        return $this->hasMany(Book::class);
    }
    public function sections()
    {
        return $this->hasMany(Section::class);
    }

    public function gates()
    {
        return $this->hasMany(Gate::class);
    }

    public function parts()
    {
        return $this->hasMany(Part::class);
    }

    public function chapters()
    {
        return $this->hasMany(Chapter::class);
    }

    public function divisions()
    {
        return $this->hasMany(Division::class);
    }

    public function branchs()
    {
        return $this->hasMany(Branch::class);
    }

    public function art()
    {
        return $this->hasMany(Art::class);
    }

    public static function search($searchTerm)
    {
        return self::where('title', 'LIKE', "%{$searchTerm}%")->get();
    }

    public static function searchLimit($searchTerm)
    {
        return self::where('title', 'LIKE', "%{$searchTerm}%")->limit(3)->get();
    }
}
