EmployersController.php
3.9 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\Answer;
use App\Models\Employer;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Validator;
class EmployersController 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', '0')->paginate(15);
if ($request->ajax()) {
return view('admin.employer.index_ajax', compact('users'));
} else {
return view('admin.employer.index', compact('users'));
}
}
public function form_update_employer(Employer $employer) {
return view('admin.employer.edit', compact('employer'));
}
public function update_employer(Employer $employer, Request $request)
{
$params = $request->all();
unset($params['logo']);
unset($params['telephone']);
unset($params['email']);
unset($params['address']);
unset($params['site']);
$rules = [
'name' => 'required|string|max:255',
];
$messages = [
'required' => 'Укажите обязательное поле «:attribute»',
'confirmed' => 'Пароли не совпадают',
'email' => 'Введите корректный email',
'min' => [
'string' => 'Поле «:attribute» должно быть не меньше :min символов',
'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт'
],
'max' => [
'string' => 'Поле «:attribute» должно быть не больше :max символов',
'file' => 'Файл «:attribute» должен быть не больше :max Кбайт'
],
];
$validator = Validator::make($params, $rules, $messages);
if ($validator->fails()) {
return back()->withErrors($validator)->withInput(); //->route('admin.register')
} else {
//$user = User::find($employer->user_id);
$user_id = $employer->user_id;
$employer->telephone = $request->telephone;
$employer->email = $request->email;
$employer->address = $request->address;
$employer->site = $request->site;
$employer->text = $request->text;
if ($request->has('logo')) {
if (!empty($employer->logo)) {
Storage::delete($employer->logo);
}
$employer->logo = $request->file('logo')->store("employer/$user_id", 'public');
}
$employer->save();
$user = User::find($user_id);
$user->update($params);
return redirect()->route('admin.employer-profile', ['employer' => $employer->id])
->with('success', 'Данные были успешно сохранены');
}
}
// кабинет - отзывы о работодателе для модерации
public function answers(Request $request) {
if ($request->ajax()) {
$user = Answer::find($request->id);
$request->offsetUnset('id');
$user->update($request->all());
}
$answers = Answer::query()->orderByDesc('id')->paginate(15);
if ($request->ajax()) {
return view('admin.answers.index_ajax', compact('answers'));
} else {
return view('admin.answers.index', compact('answers'));
}
}
// кабинет - статистика вакансий работодателя
public function static_ads() {
return;
}
}