CompanyController.php
1.81 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
<?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->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) {
$company = Employer::with('ads')->with('flots')
->where('id', '=', $company->id)->get();
$title = $company[0]->name_company;
return view('info_company', compact('company', 'title'));
}
}