|
@@ -7,6 +7,7 @@ use App\Models\RemarkDetail;
|
|
use App\Models\Teacher;
|
|
use App\Models\Teacher;
|
|
use App\Models\TeacherCourse;
|
|
use App\Models\TeacherCourse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Request;
|
|
|
|
+use Illuminate\Support\Facades\Validator;
|
|
|
|
|
|
class TeacherController extends Controller
|
|
class TeacherController extends Controller
|
|
{
|
|
{
|
|
@@ -64,7 +65,23 @@ class TeacherController extends Controller
|
|
return $this->showWarning('数据错误');
|
|
return $this->showWarning('数据错误');
|
|
}
|
|
}
|
|
|
|
|
|
- $res = $this->model->create($request->input('data'));
|
|
|
|
|
|
+ $validator = Validator::make($request->input('data'), [
|
|
|
|
+ 'phone' => 'required|unique:teachers',
|
|
|
|
+ 'password' => 'required|min:6',
|
|
|
|
+ ], [
|
|
|
|
+ 'phone.required' => '手机必填',
|
|
|
|
+ 'phone.unique' => '手机已存在',
|
|
|
|
+ 'password.required' => '密码必填',
|
|
|
|
+ 'password.min' => '密码不少于6位',
|
|
|
|
+ ]);
|
|
|
|
+ if($validator->fails()) {
|
|
|
|
+ return back()->withErrors($validator)->withInput();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $data = $request->input('data');
|
|
|
|
+ $data['password'] = bcrypt($data['password']);
|
|
|
|
+
|
|
|
|
+ $res = $this->model->create($data);
|
|
if(!$res) {
|
|
if(!$res) {
|
|
return $this->showWarning('数据库保存失败!');
|
|
return $this->showWarning('数据库保存失败!');
|
|
}
|
|
}
|
|
@@ -105,6 +122,27 @@ class TeacherController extends Controller
|
|
return $this->showWarning('数据错误');
|
|
return $this->showWarning('数据错误');
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ $validator = Validator::make($request->input('data'), [
|
|
|
|
+ 'phone' => 'required'
|
|
|
|
+ ], [
|
|
|
|
+ 'phone.required' => '手机必填'
|
|
|
|
+ ]);
|
|
|
|
+
|
|
|
|
+ if($validator->fails()) {
|
|
|
|
+ return back()->withErrors($validator)->withInput();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $data = $request->input('data');
|
|
|
|
+
|
|
|
|
+ $tmp = $this->where([
|
|
|
|
+ ['phone', '=', $data['phone']],
|
|
|
|
+ ['id', '<>', $request->input('id')],
|
|
|
|
+ ])->first();
|
|
|
|
+ if(!empty($tmp)) {
|
|
|
|
+ $validator->errors()->add('phone', '手机号已存在');
|
|
|
|
+ return back()->withErrors($validator)->withInput();
|
|
|
|
+ }
|
|
|
|
+
|
|
$res = $this->model->where('id', $request->input('id'))->update($request->input('data'));
|
|
$res = $this->model->where('id', $request->input('id'))->update($request->input('data'));
|
|
if(!$res) {
|
|
if(!$res) {
|
|
return $this->showWarning('数据库保存失败!');
|
|
return $this->showWarning('数据库保存失败!');
|