WorkersController.php
2.52 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
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\Static_worker;
use App\Models\User;
use App\Models\Worker;
use Illuminate\Http\Request;
class WorkersController extends Controller
{
public function index(Request $request) {
if ($request->ajax()) {
$user = User::find($request->id);
$request->offsetUnset('id');
$user->update($request->all());
}
$users = User::where('is_worker', '1');
$find_key = "";
if (isset($request->find)) {
$find_key = $request->find;
$users = $users->where(function($query) use($find_key) {
$query->Where('name_man', 'LIKE', "%$find_key%")
->orWhere('email', 'LIKE', "%$find_key%")
->orWhere('telephone', 'LIKE', "%$find_key%");
});
}
$users = $users->paginate(15);
if ($request->ajax()) {
return view('admin.worker.index_ajax', compact('users'));
} else {
return view('admin.worker.index', compact('users', 'find_key'));
}
}
public function form_update_worker(Worker $worker) {
return view('admin.worker.edit');
}
// кабинет - статистика работников
public function static_workers(Request $request) {
$stat = Static_worker::with('users');
//->join('users', 'users.id', '=', 'static_workers.user_id');
$users = User::query()->active()->OrderBy('id')->get();
$periods = Static_worker::query()->distinct('year_month')->select('year_month')->get();
if ($request->ajax()) {
if (isset($request->user_id))
if (!$request->user_id == "0")
$stat = $stat->Where('user_id', '=', $request->user_id);
if (isset($request->year_month)) {
if (!$request->year_month == "0")
$stat = $stat->Where('year_month', '=', $request->year_month);
}
}
$stat = $stat->OrderByDesc('year_month');
//->OrderBy('users.name');
//OrderBy('users.name')->
/*$stat->implode() loadMissing(['users' => function (Builder $query) {
$query->orderBy('name', 'asc');
}]);*/
$stat = $stat->paginate(15);
if ($request->ajax())
return view('admin.static.index_workers_ajax', compact('stat'));
else
return view('admin.static.index_workers', compact('stat', 'users', 'periods'));
}
}