Ejemplo n.º 1
0
 /**
  * Update post
  * @param  Request $request 
  * @param  int  $id      
  * @return void
  */
 public function updatePost(Request $request, $id)
 {
     DB::beginTransaction();
     try {
         $post = Post::findOrFail($id);
         $oldImage = "";
         $inputs = $request->all();
         if ($request->hasFile('images')) {
             $oldImage = public_path() . config('model.posts.path_folder_photo_post') . $post->images;
             $imageFile = $request->file('images');
             $inputs['images'] = $this->__storeImagePost($imageFile);
         } else {
             unset($inputs['images']);
         }
         if ($inputs['type'] == 2) {
             $this->__changeStickyPost($id);
         }
         $post->fill($inputs);
         $post->save();
         if (strlen($oldImage) != 0) {
             if (File::exists($oldImage)) {
                 File::delete($oldImage);
             }
         }
     } catch (Exception $e) {
         DB::rollback();
         throw new Exception("Error Processing Request", 1);
     }
     DB::commit();
 }
Ejemplo n.º 2
0
 /**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     if (Request::hasFile('file')) {
         return ['data' => 'required', 'file' => 'required'];
     }
     if (Request::has('id_download')) {
         return ['judul_file' => 'required'];
     }
     return ['judul_file' => 'required', 'file' => 'required'];
 }
Ejemplo n.º 3
0
 public function storeUserRegister(Request $request)
 {
     DB::beginTransaction();
     try {
         $inputs = $request->all();
         if ($request->hasFile('photo')) {
             $photoFile = $request->file('photo');
             $inputs['photo'] = $this->__storeImageUser($photoFile);
         } else {
             unset($inputs['photo']);
         }
         $role = Role::where('slug', 'user')->first();
         $inputs['role_id'] = $role->id;
         $inputs['register_token'] = str_random(30);
         $inputs['password'] = bcrypt($inputs['password']);
         $user = User::create($inputs);
         $inputs['user_id'] = $user->id;
         UserInfo::create($inputs);
     } catch (Exception $e) {
         DB::rollback();
     }
     DB::commit();
     return $user;
 }