mardi 15 janvier 2019

How can i avoid image required in edit form if image exist in laravel?

I am adding and editing a user with same function (Store), when ever i add a user it asks me image is required but whenever i edit a user which have image it also ask me image is required and i want if a image is already present it wont ask me

                                 
  I am saving like this
                                 
 public function store(Request $request)
        {
           $rule=array(
                    'name' => 'required',

               'image' => 'required',
                                 );
                                 
              if(!empty($inputs['id'])){
                            $user = User::findOrFail($inputs['id']);
                        }else{
                            $user = new User;
                        }
   
        $user_image = $request->file('image');

       if($user_image){
       
            $tmpFilePath = 'uploads/candidates/';

            $hardPath =  str_slug($inputs['name'], '-').'-'.md5(time());
            $img = Image::make($user_image);
            $img->fit(300, 300)->save($tmpFilePath.$hardPath.'-b.jpg');
            $user->image = $tmpFilePath.$hardPath.'-b.jpg';

        }
                      $user->name = $inputs['name'];
                      $user->save();

        }


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire