/** * Boot package * * @return void */ public function boot(Events $events) { $this->loadPublic(); $this->loadView(); $this->loadTranslation(); $this->loadConfiguration(); $this->loadMigration(); User::Observe(new ModelObservers\UserObserver()); Role::Observe(new ModelObservers\RoleObserver($events)); $this->app['navigation']->register(require __DIR__ . '/../Http/navigations.php'); }
public function restoring($model) { $name = str_replace($model->id . '-', '', $model->name); $slug = str_replace($model->id . '-', '', $model->slug); $existing = Role::where(function ($query) use($name, $slug) { $query->where('name', $name); $query->orWhere('slug', $slug); })->first(); if ($existing) { $model->name = $name != $existing->name ? $name : $model->name; $model->slug = $slug != $existing->slug ? $slug : $model->slug; } else { $model->name = $name; $model->slug = $slug; } $model->save(); }
public function store(Request $request, Bus $bus, UserRepository $userRepository) { $this->validate($request, ['reg_no' => 'required|max:255|unique:lecturers', 'local_reg_no' => 'required|max:255|unique:lecturers', 'name' => 'required|max:255', 'id_number' => 'unique:lecturers', 'country_id' => 'exists:countries,id']); $lecturer = new Lecturer(); $lecturer->reg_no = $request->reg_no; $lecturer->local_reg_no = $request->local_reg_no; $lecturer->name = $request->name; $lecturer->status = $request->status; $lecturer->id_number = $request->id_number; $lecturer->mother_maiden_name = $request->mother_maiden_name; $lecturer->country_id = $request->country_id; $lecturer->avatar = $request->avatar; $user = $userRepository->findByUsername($request->reg_no); if (!$user) { $role = Role::where('name', 'Lecturer')->first(); $roles = $role ? [$role->id] : []; $desc = ['password' => bcrypt($request->reg_no), 'name' => $request->name, 'active' => true]; $bus->dispatch(new RegisterNewUser($request->reg_no, $request->reg_no . '@email.com', $roles, $desc)); $user = $userRepository->findByUsername($request->reg_no); } $lecturer->user_id = $user->id()->value(); $lecturer->save(); return $this->formSuccess(route('admin.employee.lecturer.index', ['id' => $lecturer->id]), ['message' => 'Dosen berhasil disimpan', 'lecturer' => $lecturer]); }
/** * Mark the end of life of entity * * @param Inoplate\Account\Domain\Models\Role $entity * @return void */ public function remove(AccountDomainModels\Role $entity) { $id = $entity->id()->value(); $this->model->destroy($id); }
public function store(Request $request, Bus $bus, UserRepository $userRepository) { $this->validate($request, ['reg_no' => 'required|max:255|unique:students', 'name' => 'required|max:255', 'entry_year' => 'required', 'program_id' => 'required|exists:programs,id', 'id_number' => 'unique:students', 'country_id' => 'exists:countries,id']); $student = new Student(); $student->reg_no = $request->reg_no; $student->name = $request->name; $student->entry_year = $request->entry_year; $student->program_id = $request->program_id; $student->id_number = $request->id_number; $student->mother_maiden_name = $request->mother_maiden_name; $student->country_id = $request->country_id; $student->avatar = $request->avatar; $user = $userRepository->findByUsername($request->reg_no); if (!$user) { $role = Role::where('name', 'Student')->first(); $roles = $role ? [$role->id] : []; $desc = ['password' => bcrypt($request->reg_no), 'name' => $request->name, 'active' => true]; $bus->dispatch(new RegisterNewUser($request->reg_no, $request->reg_no . '@email.com', $roles, $desc)); $user = $userRepository->findByUsername($request->reg_no); } $student->user_id = $user->id()->value(); $student->save(); return $this->formSuccess(route('admin.student.student.index', ['id' => $student->id]), ['message' => 'Mahasiswa berhasil disimpan', 'student' => $student]); }