LikesClass.php 1.38 KB
<?php


namespace App\Classes;


use App\Models\Ad_employer;
use App\Models\Like_vacancy;
use App\Models\Like_worker;
use App\Models\Worker;
use Illuminate\Support\Facades\Auth;

class LikesClass
{
    public static function ListVacancy(Ad_employer $ad_employer) {
        $ListVacancy = Like_vacancy::query()
            ->where('code_record', '=', $ad_employer->id)
            ->where('user_id', Auth::user()?->id)
            ->get();

        return $ListVacancy;
    }

    public static function ListWorkers(Worker $worker) {
        $ListWorker = Like_worker::query()
            ->where('code_record', '=', $worker->id)
            ->where('user_id', Auth::user()?->id)
            ->get();

        return $ListWorker;
    }

    public static function get_status_vacancy(Ad_employer $ad_employer) {
        $isVacancyLiked = Like_worker::query()
            ->where('code_record', $ad_employer->id)
            ->where('user_id', Auth::user()?->id)
            ->exists();

        if ($isVacancyLiked) {
            return 'active';
        }

        return '';
    }

    public static function get_status_worker(Worker $worker) {
        $isWorkerLiked = Like_worker::query()
            ->where('code_record', $worker->id)
            ->where('user_id', Auth::user()?->id)
            ->exists();

        if ($isWorkerLiked) {
            return 'active';
        }

        return '';
    }
}