CompanyController.php
2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?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;
}
}
$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')->
OrderByDesc('id')->
where('employer_id', '=', $company[0]->id)->paginate(2);
return view('info_company_new', compact('company', 'user_id', 'title', 'ads'));
}
}