Ad_jobsController.php 3.31 KB
<?php

namespace App\Http\Controllers;

use App\Classes\RusDate;
use App\Classes\Tools;
use App\Http\Requests\FlotRequest;
use App\Http\Requests\MessagesRequiest;
use App\Http\Requests\VacancyRequestEdit;
use App\Http\Requests\VacansiaRequiest;
use App\Mail\MailSotrudnichestvo;
use App\Mail\SendAllMessages;
use App\Models\Ad_employer;
use App\Models\Ad_jobs;
use App\Models\ad_response;
use App\Models\Category;
use App\Models\Education;
use App\Models\Employer;
use App\Models\employers_main;
use App\Models\Flot;
use App\Models\Job_title;
use App\Models\Like_vacancy;
use App\Models\Like_worker;
use App\Models\Message;
use App\Models\Positions;
use App\Models\Worker;
use Carbon\Carbon;
use Illuminate\Auth\Events\Registered;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Auth\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Storage;
use App\Models\User as User_Model;
use Illuminate\Support\Facades\Validator;

class Ad_jobsController extends Controller
{

    public function add_job_in_vac(Request $request, Ad_employer $ad_employer) {
        $id = Auth()->user()->id;

        $Positions = Positions::query()->get();
        if ($Positions->count()) {
            $jobs = Job_title::query()->OrderBy('name')->where('position_id', $Positions[0]->id)->get();
        } else {
            $jobs = Job_title::query()->OrderBy('name')->where('position_id', 0)->get();
        }
        $categories = Category::query()->get();
        $Employer = Employer::query()->with('users')->with('ads')->with('flots')->
        where('user_id', $id)->first();

        return view('employers.add_ad_jobs', compact('ad_employer',
                                                'Positions', 'categories', 'jobs',
                                                          'Employer'));
    }

    public function add_job_in_vac_save(Request $request) {
        $params = $request->all();

        Ad_jobs::create($params);
        return redirect()->route('employer.vacancy_list');
    }

    public function edit_job_in_vac(Ad_jobs $ad_job, Ad_employer $ad_employer) {
        $id = Auth()->user()->id;

        $Positions = Positions::query()->get();
        if ($Positions->count()) {
            $jobs = Job_title::query()->OrderBy('name')->where('position_id', $Positions[0]->id)->get();
        } else {
            $jobs = Job_title::query()->OrderBy('name')->where('position_id', 0)->get();
        }
        $categories = Category::query()->get();
        $Employer = Employer::query()->with('users')->with('ads')->with('flots')->
        where('user_id', $id)->first();

        return view('employers.edit_ad_jobs', compact('ad_job',
                                                        'Positions', 'categories',
                                                                  'Employer','jobs', 'ad_employer'));
    }

    public function edit_job_in_vac_save(Request $request, Ad_jobs $ad_job) {
        $params = $request->all();

        $ad_job->update($params);

        return redirect()->route('employer.vacancy_list');
    }

    public function delete_job_in_vac(Ad_jobs $ad_job) {
        $ad_job->delete();
        return redirect()->route('employer.vacancy_list');
    }
}