saving($data); $model = $this->modelName::create($data); $this->saved($model); return true; } public function update($primaryKey, $data) { $this->saving($data, $primaryKey); $model = $this->query()->whereKey($primaryKey)->first(); $model->update($data); $this->saved($model, true); return true; } public function saving(&$data, $primaryKey = '') { $unique = Rule::unique('users', 'phone'); $createRules = [ 'phone' => ['required', $unique, 'phone'] ]; $updateRules = [ 'phone' => ['phone', $unique->ignore($primaryKey)] ]; $validator = Validator::make($data, $primaryKey ? $updateRules : $createRules); if ($validator->fails()) { throw new AdminValidationException($validator->errors()); } } public function sortable($query) { $query->orderByDesc('id'); } public function searchable($query) { $query->filter(request()->all()); } }