CompanyController.php 2.46 KB
<?php

namespace App\Http\Controllers;

use App\Models\Ad_employer;
use App\Models\Employer;
use Illuminate\Http\Request;

class CompanyController extends Controller
{
    public function shipping_companies(Request $request) {
        $emps = Employer::query()->with('ads')->where('status_hidden', '=', '0');
        if (($request->has('search')) && (!empty($request->get('search')))) {
            $search = $request->get('search');
            $emps = $emps->where('name_company', 'LIKE', "%$search%");
        }

        $count_emps = $emps->count();

        if ($request->get('sort')) {
            $sort = $request->get('sort');
            switch ($sort) {
                case 'name_up': $emps = $emps->orderBy('name_company')->orderBy('id'); break;
                case 'name_down': $emps = $emps->orderByDesc('name_company')->orderby('id'); break;
                case 'created_at_up': $emps = $emps->OrderBy('created_at')->orderBy('id'); break;
                case 'created_at_down': $emps = $emps->orderByDesc('created_at')->orderBy('id'); break;
                case 'default': $emps = $emps->orderBy('id')->orderby('updated_at'); break;
                default: $emps = $emps->orderBy('id')->orderby('updated_at'); break;
            }
        }
       if (is_null($request->get('sort'))){

        $emps = $emps->orderByDesc('created_at')->orderBy('id');

      }

        $emps = $emps->paginate(4);

        if ($request->ajax()) {
            if ($request->get('block') == '1')
                return view('ajax.companies', compact('emps', 'count_emps'));
            else
                return view('ajax.companies2', compact('emps', 'count_emps'));
        } else {
            return view('companies', compact('emps', 'count_emps'));
        }
    }

    public function info_company(Employer $company) {
        if (isset(Auth()->user()->id)) {
            $user_id = Auth()->user()->id;
        } else {
            $user_id = 0;
        }

        $company = Employer::with('ads')->with('flots')->with('users')
                            ->where('id', '=', $company->id)->get();

        $title = $company[0]->name_company;

        $ads = Ad_employer::query()->with('jobs')->with('jobs_code')
            ->where('employer_id', '=', $company[0]->id)
            ->where('is_remove', '=', '0')
            ->where('active_is', 1)
            ->OrderByDesc('id')
            ->paginate(50)
        ;

        return view('info_company_new', compact('company', 'user_id', 'title', 'ads'));
    }
}