CompanyController.php 2.01 KB
<?php

namespace App\Http\Controllers;

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

class CompanyController extends Controller
{
    public function shipping_companies(Request $request) {
        $emps = Employer::query()->with('ads');
        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;
            }
        }

        $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;

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