/** * Bootstrap any application services. * * @return void */ public function boot() { User::created(function (User $user) { Folder::create(['name' => '/', 'user_id' => $user->id]); Activity::create(['type' => 'user_created', 'user_id' => $user->id]); }); Folder::deleting(function (Folder $folder) { foreach ($folder->folders as $_folder) { $_folder->_delete(); } foreach ($folder->files as $file) { $file->delete(); } }); File::deleting(function (File $file) { $file = updateFile($file, fileInfo($file)); $filenames = []; if ($file->type == 'image') { $altImages = ['opt', 'xs']; foreach ($altImages as $suffix) { $name = explode('.', $file->filename)[0]; $extension = explode('.', $file->filename)[1]; array_push($filenames, "{$name}.{$suffix}.{$extension}"); } } Storage::delete($file->filename); if (!empty($filenames)) { foreach ($filenames as $filename) { Storage::delete($filename); } } }); }
public function passwordUpdate(Request $request) { $validationRules = AuthController::validationData($this->user->id); unset($validationRules['name']); unset($validationRules['email']); unset($validationRules['gender']); $validator = Validator::make($request->all(), $validationRules); $validator->after(function ($validator) use($request) { if (!Hash::check($request->current, $this->user->password)) { $validator->errors()->add('current', 'Your current password is incorrect'); } }); if ($validator->fails()) { return redirect()->back()->withErrors($validator)->withInput(); } $dataRequest = $request->all(); $dataRequest['name'] = ''; $dataRequest['email'] = ''; $dataRequest['gender'] = ''; $data = AuthController::userData($dataRequest); unset($data['name']); unset($data['email']); unset($data['gender']); User::where('id', $this->user->id)->update($data); fmsgs(['title' => 'Password Updated', 'type' => 'success', 'text' => "Successfully updating your password"]); return redirect('profile'); }
public function userCreate(Request $request) { $this->validate($request, AuthController::validationData()); $data = AuthController::userData($request->all()); // dd($data); User::create($data); fmsgs(['title' => 'User Created', 'type' => 'success', 'text' => "Successfully adding new user, check the list!"]); return redirect()->back(); }
/** * Run the database seeds. * * @return void */ public function run() { User::create(['name' => 'Dwi Prabowo', 'email' => '*****@*****.**', 'password' => bcrypt('asdfasdf'), 'remember_token' => str_random(10), 'gender' => 1]); Role::create(['name' => 'admin', 'label' => 'The admin of the system']); Permission::create(['name' => 'dashboard', 'label' => 'User has right to access admin dashboard']); Role::whereName('admin')->first()->assign(Permission::whereName('dashboard')->first()); User::whereEmail('*****@*****.**')->first()->assign(Role::whereName('admin')->first()); User::create(['name' => 'Owl Jpr', 'email' => '*****@*****.**', 'password' => bcrypt('asdfasdf'), 'remember_token' => str_random(10), 'gender' => 1]); for ($i = 0; $i < 10; $i++) { factory(User::class)->create(); } }
public function index() { $activities = Activity::orderBy('updated_at', 'desc')->get(); $activities = $activities->unique(function ($item) { return $item->user_id . $item->type . $item->item_id; }); $users = User::all(); $userIds = array_map(function ($user) { return $user['id']; }, $users->toArray()); foreach ($activities as $index => $activity) { if (!in_array($activity->user_id, $userIds)) { unset($activities[$index]); } if ($activity->item_id) { $file = FileModel::find($activity->item_id); if (!$file || !$file->shared) { unset($activities[$index]); } } } return view('home', ['activities' => $activities]); }
/** * Create a new user instance after a valid registration. * * @param array $data * @return User */ public function create(array $data) { $user = User::create(AuthController::userData($data)); return $user; }