Update function with Image Replace while updateLaravel 4 - Update Div Using AjaxError while running models in LumenLaravel user update problemsI want to delete the stored image while update new imagemove() function not working in laravel 5.2 while editing/updating picturesMethodNotAllowedHttpException (lumen) while making request with axiosHow update fields in LumenEloquent update and event observersNotifications for comments not working in laravelHaving a problem with a pivot table on Laravel

How to efficiently shred a lot of cabbage?

May a hotel provide accommodation for fewer people than booked?

Can I attune a Circlet of Human Perfection to my animated skeletons to allow them to blend in and speak?

Complaints from (junior) developers against solution architects: how can we show the benefits of our work and improve relationships?

Are all French verb conjugation tenses and moods practical and efficient?

Bouncing map back into its bounds, after user dragged it out

When encrypting twice with two separate keys, can a single key decrypt both steps?

How can flights operated by the same company have such different prices when marketed by another?

Why don't short runways use ramps for takeoff?

Security measures that could plausibly last 150+ years?

How to prevent a single-element caster from being useless against immune foes?

Avoiding Implicit Conversion in Constructor. Explicit keyword doesn't help here

My employer is refusing to give me the pay that was advertised after an internal job move

Why does the Rust compiler not optimize code assuming that two mutable references cannot alias?

How do discovery writers hibernate?

Do the books ever say oliphaunts aren’t elephants?

Why did I lose on time with 3 pawns vs Knight. Shouldn't it be a draw?

How would a lunar colony attack Earth?

What would the United Kingdom's "optimal" Brexit deal look like?

Correct word for a little toy that always stands up?

"Valet parking " or "parking valet"

Why are we moving in circles with a tandem kayak?

Why did some Apollo missions carry a grenade launcher?

Does Ubuntu reduce battery life?



Update function with Image Replace while update


Laravel 4 - Update Div Using AjaxError while running models in LumenLaravel user update problemsI want to delete the stored image while update new imagemove() function not working in laravel 5.2 while editing/updating picturesMethodNotAllowedHttpException (lumen) while making request with axiosHow update fields in LumenEloquent update and event observersNotifications for comments not working in laravelHaving a problem with a pivot table on Laravel






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I created a Lumen code to store data with 5 images (took the manual image method ) and that API is working fine. I have a doubt if I want to update the query I can update all the part of data but have no clue with images.



I tried update images names but the same problem is how do I replace images



 public function store(Request $request)

$post = new Post;
$post->setConnection('mysql1');
$user= User::where('token', $request->token)->first();

if ($user)
$a = Auth::user()->id;
$post = Auth::user()->posts()->create([
'post_id' => rand(),
'title' => $request->title,
'cooked_time' => $request->cooked_time,
'user_id' => Auth::id(),
]);

if (!function_exists('public_path'))

function public_path($path = null)
return rtrim(app()->basePath('public/' . $path) , '/');


$images = new PostImage;
$destination_path = public_path('/images');

if ($request->hasFile('image1'))

$image1 = $request->file('image1');
$image_size1 = $image1->getClientSize();
$image_ext1 = $image1->getClientOriginalExtension();
$new_image_name1 = rand(123456, 99999999) . "." . $image_ext1;
$image1->move($destination_path, $new_image_name1);
$images->image_name1 = $new_image_name1;

if ($request->hasFile('image2'))
$image2 = $request->file('image2');
$image_size2 = $image2->getClientSize();
$image_ext2 = $image2->getClientOriginalExtension();
$new_image_name2 = rand(123456, 99999999) . "." . $image_ext2;
$image2->move($destination_path, $new_image_name2);
$images->image_name2 = $new_image_name2;

if ($request->hasFile('image3'))

$image3 = $request->file('image3');
$image_size3 = $image3->getClientSize();
$image_ext3 = $image3->getClientOriginalExtension();
$new_image_name3 = rand(123456, 99999999) . "." . $image_ext3;
$image3->move($destination_path, $new_image_name3);
$images->image_name3 = $new_image_name3;

if ($request->hasFile('image4'))
$image4 = $request->file('image4');
$image_size4 = $image4->getClientSize();
$image_ext4 = $image4->getClientOriginalExtension();
$new_image_name4 = rand(123456, 99999999) . "." . $image_ext4;
$image4->move($destination_path, $new_image_name4);
$images->image_name4 = $new_image_name4;

if ($request->hasFile('image5'))
$image5 = $request->file('image5');
$image_size5 = $image5->getClientSize();
$image_ext5 = $image5->getClientOriginalExtension();
$new_image_name5 = rand(123456, 99999999) . "." . $image_ext5;
$image5->move($destination_path, $new_image_name5);
$images->image_name5 = $new_image_name5;


$images->post_id = $post->post_id;
$images->save();

return response()->json(['message' => 'success', 'user' => $user['name'], 'post' => $post, 'images' => $images,], 200);




I want the images that are stored to be replaced if I am updating the request and this is how i Updated my code



public function update(Request $request, $post_id)

$posts = Post::findorFail($post_id);
// dd($posts);
if (Auth::user()->id !== $posts->user_id)
return response()->json(['status'=> 'error', 'message' => 'unauthorized'], 401);

$post1=$request->all();

$posts->fill($post1)->save();

return response()->json(['status' => 'success', 'updated_post' => $posts,], 200);



How do i update my images and replace that are placed in Folder










share|improve this question






























    0















    I created a Lumen code to store data with 5 images (took the manual image method ) and that API is working fine. I have a doubt if I want to update the query I can update all the part of data but have no clue with images.



    I tried update images names but the same problem is how do I replace images



     public function store(Request $request)

    $post = new Post;
    $post->setConnection('mysql1');
    $user= User::where('token', $request->token)->first();

    if ($user)
    $a = Auth::user()->id;
    $post = Auth::user()->posts()->create([
    'post_id' => rand(),
    'title' => $request->title,
    'cooked_time' => $request->cooked_time,
    'user_id' => Auth::id(),
    ]);

    if (!function_exists('public_path'))

    function public_path($path = null)
    return rtrim(app()->basePath('public/' . $path) , '/');


    $images = new PostImage;
    $destination_path = public_path('/images');

    if ($request->hasFile('image1'))

    $image1 = $request->file('image1');
    $image_size1 = $image1->getClientSize();
    $image_ext1 = $image1->getClientOriginalExtension();
    $new_image_name1 = rand(123456, 99999999) . "." . $image_ext1;
    $image1->move($destination_path, $new_image_name1);
    $images->image_name1 = $new_image_name1;

    if ($request->hasFile('image2'))
    $image2 = $request->file('image2');
    $image_size2 = $image2->getClientSize();
    $image_ext2 = $image2->getClientOriginalExtension();
    $new_image_name2 = rand(123456, 99999999) . "." . $image_ext2;
    $image2->move($destination_path, $new_image_name2);
    $images->image_name2 = $new_image_name2;

    if ($request->hasFile('image3'))

    $image3 = $request->file('image3');
    $image_size3 = $image3->getClientSize();
    $image_ext3 = $image3->getClientOriginalExtension();
    $new_image_name3 = rand(123456, 99999999) . "." . $image_ext3;
    $image3->move($destination_path, $new_image_name3);
    $images->image_name3 = $new_image_name3;

    if ($request->hasFile('image4'))
    $image4 = $request->file('image4');
    $image_size4 = $image4->getClientSize();
    $image_ext4 = $image4->getClientOriginalExtension();
    $new_image_name4 = rand(123456, 99999999) . "." . $image_ext4;
    $image4->move($destination_path, $new_image_name4);
    $images->image_name4 = $new_image_name4;

    if ($request->hasFile('image5'))
    $image5 = $request->file('image5');
    $image_size5 = $image5->getClientSize();
    $image_ext5 = $image5->getClientOriginalExtension();
    $new_image_name5 = rand(123456, 99999999) . "." . $image_ext5;
    $image5->move($destination_path, $new_image_name5);
    $images->image_name5 = $new_image_name5;


    $images->post_id = $post->post_id;
    $images->save();

    return response()->json(['message' => 'success', 'user' => $user['name'], 'post' => $post, 'images' => $images,], 200);




    I want the images that are stored to be replaced if I am updating the request and this is how i Updated my code



    public function update(Request $request, $post_id)

    $posts = Post::findorFail($post_id);
    // dd($posts);
    if (Auth::user()->id !== $posts->user_id)
    return response()->json(['status'=> 'error', 'message' => 'unauthorized'], 401);

    $post1=$request->all();

    $posts->fill($post1)->save();

    return response()->json(['status' => 'success', 'updated_post' => $posts,], 200);



    How do i update my images and replace that are placed in Folder










    share|improve this question


























      0












      0








      0








      I created a Lumen code to store data with 5 images (took the manual image method ) and that API is working fine. I have a doubt if I want to update the query I can update all the part of data but have no clue with images.



      I tried update images names but the same problem is how do I replace images



       public function store(Request $request)

      $post = new Post;
      $post->setConnection('mysql1');
      $user= User::where('token', $request->token)->first();

      if ($user)
      $a = Auth::user()->id;
      $post = Auth::user()->posts()->create([
      'post_id' => rand(),
      'title' => $request->title,
      'cooked_time' => $request->cooked_time,
      'user_id' => Auth::id(),
      ]);

      if (!function_exists('public_path'))

      function public_path($path = null)
      return rtrim(app()->basePath('public/' . $path) , '/');


      $images = new PostImage;
      $destination_path = public_path('/images');

      if ($request->hasFile('image1'))

      $image1 = $request->file('image1');
      $image_size1 = $image1->getClientSize();
      $image_ext1 = $image1->getClientOriginalExtension();
      $new_image_name1 = rand(123456, 99999999) . "." . $image_ext1;
      $image1->move($destination_path, $new_image_name1);
      $images->image_name1 = $new_image_name1;

      if ($request->hasFile('image2'))
      $image2 = $request->file('image2');
      $image_size2 = $image2->getClientSize();
      $image_ext2 = $image2->getClientOriginalExtension();
      $new_image_name2 = rand(123456, 99999999) . "." . $image_ext2;
      $image2->move($destination_path, $new_image_name2);
      $images->image_name2 = $new_image_name2;

      if ($request->hasFile('image3'))

      $image3 = $request->file('image3');
      $image_size3 = $image3->getClientSize();
      $image_ext3 = $image3->getClientOriginalExtension();
      $new_image_name3 = rand(123456, 99999999) . "." . $image_ext3;
      $image3->move($destination_path, $new_image_name3);
      $images->image_name3 = $new_image_name3;

      if ($request->hasFile('image4'))
      $image4 = $request->file('image4');
      $image_size4 = $image4->getClientSize();
      $image_ext4 = $image4->getClientOriginalExtension();
      $new_image_name4 = rand(123456, 99999999) . "." . $image_ext4;
      $image4->move($destination_path, $new_image_name4);
      $images->image_name4 = $new_image_name4;

      if ($request->hasFile('image5'))
      $image5 = $request->file('image5');
      $image_size5 = $image5->getClientSize();
      $image_ext5 = $image5->getClientOriginalExtension();
      $new_image_name5 = rand(123456, 99999999) . "." . $image_ext5;
      $image5->move($destination_path, $new_image_name5);
      $images->image_name5 = $new_image_name5;


      $images->post_id = $post->post_id;
      $images->save();

      return response()->json(['message' => 'success', 'user' => $user['name'], 'post' => $post, 'images' => $images,], 200);




      I want the images that are stored to be replaced if I am updating the request and this is how i Updated my code



      public function update(Request $request, $post_id)

      $posts = Post::findorFail($post_id);
      // dd($posts);
      if (Auth::user()->id !== $posts->user_id)
      return response()->json(['status'=> 'error', 'message' => 'unauthorized'], 401);

      $post1=$request->all();

      $posts->fill($post1)->save();

      return response()->json(['status' => 'success', 'updated_post' => $posts,], 200);



      How do i update my images and replace that are placed in Folder










      share|improve this question














      I created a Lumen code to store data with 5 images (took the manual image method ) and that API is working fine. I have a doubt if I want to update the query I can update all the part of data but have no clue with images.



      I tried update images names but the same problem is how do I replace images



       public function store(Request $request)

      $post = new Post;
      $post->setConnection('mysql1');
      $user= User::where('token', $request->token)->first();

      if ($user)
      $a = Auth::user()->id;
      $post = Auth::user()->posts()->create([
      'post_id' => rand(),
      'title' => $request->title,
      'cooked_time' => $request->cooked_time,
      'user_id' => Auth::id(),
      ]);

      if (!function_exists('public_path'))

      function public_path($path = null)
      return rtrim(app()->basePath('public/' . $path) , '/');


      $images = new PostImage;
      $destination_path = public_path('/images');

      if ($request->hasFile('image1'))

      $image1 = $request->file('image1');
      $image_size1 = $image1->getClientSize();
      $image_ext1 = $image1->getClientOriginalExtension();
      $new_image_name1 = rand(123456, 99999999) . "." . $image_ext1;
      $image1->move($destination_path, $new_image_name1);
      $images->image_name1 = $new_image_name1;

      if ($request->hasFile('image2'))
      $image2 = $request->file('image2');
      $image_size2 = $image2->getClientSize();
      $image_ext2 = $image2->getClientOriginalExtension();
      $new_image_name2 = rand(123456, 99999999) . "." . $image_ext2;
      $image2->move($destination_path, $new_image_name2);
      $images->image_name2 = $new_image_name2;

      if ($request->hasFile('image3'))

      $image3 = $request->file('image3');
      $image_size3 = $image3->getClientSize();
      $image_ext3 = $image3->getClientOriginalExtension();
      $new_image_name3 = rand(123456, 99999999) . "." . $image_ext3;
      $image3->move($destination_path, $new_image_name3);
      $images->image_name3 = $new_image_name3;

      if ($request->hasFile('image4'))
      $image4 = $request->file('image4');
      $image_size4 = $image4->getClientSize();
      $image_ext4 = $image4->getClientOriginalExtension();
      $new_image_name4 = rand(123456, 99999999) . "." . $image_ext4;
      $image4->move($destination_path, $new_image_name4);
      $images->image_name4 = $new_image_name4;

      if ($request->hasFile('image5'))
      $image5 = $request->file('image5');
      $image_size5 = $image5->getClientSize();
      $image_ext5 = $image5->getClientOriginalExtension();
      $new_image_name5 = rand(123456, 99999999) . "." . $image_ext5;
      $image5->move($destination_path, $new_image_name5);
      $images->image_name5 = $new_image_name5;


      $images->post_id = $post->post_id;
      $images->save();

      return response()->json(['message' => 'success', 'user' => $user['name'], 'post' => $post, 'images' => $images,], 200);




      I want the images that are stored to be replaced if I am updating the request and this is how i Updated my code



      public function update(Request $request, $post_id)

      $posts = Post::findorFail($post_id);
      // dd($posts);
      if (Auth::user()->id !== $posts->user_id)
      return response()->json(['status'=> 'error', 'message' => 'unauthorized'], 401);

      $post1=$request->all();

      $posts->fill($post1)->save();

      return response()->json(['status' => 'success', 'updated_post' => $posts,], 200);



      How do i update my images and replace that are placed in Folder







      laravel laravel-5 lumen lumen-5.4






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 26 at 21:12









      Pushpendra PalPushpendra Pal

      237 bronze badges




      237 bronze badges

























          0






          active

          oldest

          votes










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55366262%2fupdate-function-with-image-replace-while-update%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes




          Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







          Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55366262%2fupdate-function-with-image-replace-while-update%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript