WorkerController.php 1.2 KB
<?php

namespace App\Http\Controllers;

use App\Models\Static_worker;
use App\Models\Worker;
use Illuminate\Http\Request;

class WorkerController extends Controller
{
    //главная
    public function index() {
        return;
    }

    //профиль
    public function profile(Worker $worker) {
        $get_date = date('Y.m');

        $c = Static_worker::query()->where('year_month', '=', $get_date)
            ->where('user_id', '=', $worker->users->id)
            ->get();

        if ($c->count() > 0) {
            $upd = Static_worker::find($c[0]->id);
            $upd->lookin = $upd->lookin + 1;
            $upd->save();
        } else {
            $crt = new Static_worker();
            $crt->lookin = 1;
            $crt->year_month = $get_date;
            $crt->user_id = $worker->user_id;
            $crt->save();
        }

        $stat = Static_worker::query()->where('year_month', '=', $get_date)
                            ->where('user_id', '=', $worker->users->id)
                            ->get();

        return view('public.workers.profile', compact('worker', 'stat'));
    }

    //публичная оферта
    public function public_offer() {
        return;
    }
}