How to redirect back to edit page from a called function?How to manage a redirect request after a jQuery Ajax callHow do I redirect to another webpage?How do I make a redirect in PHP?How can I redirect and append both stdout and stderr to a file with Bash?How do I get a YouTube video thumbnail from the YouTube API?How do I redirect with JavaScript?StackOverflow Style Routes with Smart RedirectsHow discard empty HTML form inputs from $_FILES arrayWhen I route my controller it can't workLaravel redirect back and refresh.

How do professional electronic musicians/sound engineers combat listening fatigue?

Grid/table with lots of buttons

Is it normal practice to screen share with a client?

What is a reasonable time for modern human society to adapt to dungeons?

This message is flooding my syslog, how to find were it comes from?

Sextortion with actual password not found in leaks

How were the LM astronauts supported during the moon landing and ascent? What were the max G's on them during these phases?

401(k) investment after being fired. Do I own it?

What is the purpose of the fuel shutoff valve?

How can I receive packages while in France?

What was the rationale behind 36 bit computer architectures?

What is "ass door"?

Would it be a good idea to memorize relative interval positions on guitar?

What to do when you reach a conclusion and find out later on that someone else already did?

Can GPL and BSD licensed applications be used for government work?

How do I run a game when my PCs have different approaches to combat?

Who has jurisdiction for a crime committed in an embassy?

Where to place an artificial gland in the human body?

Can two figures have the same area, perimeter, and same number of segments have different shape?

Monty Hall Problem with a Fallible Monty

The seven story archetypes. Are they truly all of them?

Spacing setting of math mode

How can I make sure my players' decisions have consequences?

If my business card says 〇〇さん, does that mean I'm referring to myself with an honourific?



How to redirect back to edit page from a called function?


How to manage a redirect request after a jQuery Ajax callHow do I redirect to another webpage?How do I make a redirect in PHP?How can I redirect and append both stdout and stderr to a file with Bash?How do I get a YouTube video thumbnail from the YouTube API?How do I redirect with JavaScript?StackOverflow Style Routes with Smart RedirectsHow discard empty HTML form inputs from $_FILES arrayWhen I route my controller it can't workLaravel redirect back and refresh.






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








1















On edit.blade.page there is a button for file deleting which leads to the update method in a controller. The update method calls private deleteImage method from which I want to redirect a user back to edit.blade.page, but it redirects me somewhere else.
I have tried all approach from the documentation



Controller



public function update(Request $request, $id)
($request['method']==true) ? $this->imageDelete($request, $id) : null;


private function imageDelete (Request $request, $id)
if($request['method']=='destroy')
$file = public_path().'/storage'.$request['old_image'];

$validatedData = $request->validate(['images'=> 'string',]);

$old_images = explode(',', $request['images']);
$paths = array();
foreach ($old_images as $old)
($old != $request['old_image']) ? $paths[] = $old : null ;

(File::exists($file)) ? File::delete($file) : null;

Announcement::where('slug', $id)->update(array_merge($validatedData,array('images'=>implode(",",$paths),)));
return redirect()->route('announcements.edit',[$id])->with('status',1);

return redirect()->route('announcements.edit',[$id])->with('status', 0);



Route



Route::resource('announcements', 'AnnouncementController', ['names' => [
'index' => 'announcements',
'store' => 'announcements.store',
'show' => 'announcements.show',
'destroy'=>'announcements.destroy',
'update' => 'announcements.update',

]])









share|improve this question






























    1















    On edit.blade.page there is a button for file deleting which leads to the update method in a controller. The update method calls private deleteImage method from which I want to redirect a user back to edit.blade.page, but it redirects me somewhere else.
    I have tried all approach from the documentation



    Controller



    public function update(Request $request, $id)
    ($request['method']==true) ? $this->imageDelete($request, $id) : null;


    private function imageDelete (Request $request, $id)
    if($request['method']=='destroy')
    $file = public_path().'/storage'.$request['old_image'];

    $validatedData = $request->validate(['images'=> 'string',]);

    $old_images = explode(',', $request['images']);
    $paths = array();
    foreach ($old_images as $old)
    ($old != $request['old_image']) ? $paths[] = $old : null ;

    (File::exists($file)) ? File::delete($file) : null;

    Announcement::where('slug', $id)->update(array_merge($validatedData,array('images'=>implode(",",$paths),)));
    return redirect()->route('announcements.edit',[$id])->with('status',1);

    return redirect()->route('announcements.edit',[$id])->with('status', 0);



    Route



    Route::resource('announcements', 'AnnouncementController', ['names' => [
    'index' => 'announcements',
    'store' => 'announcements.store',
    'show' => 'announcements.show',
    'destroy'=>'announcements.destroy',
    'update' => 'announcements.update',

    ]])









    share|improve this question


























      1












      1








      1








      On edit.blade.page there is a button for file deleting which leads to the update method in a controller. The update method calls private deleteImage method from which I want to redirect a user back to edit.blade.page, but it redirects me somewhere else.
      I have tried all approach from the documentation



      Controller



      public function update(Request $request, $id)
      ($request['method']==true) ? $this->imageDelete($request, $id) : null;


      private function imageDelete (Request $request, $id)
      if($request['method']=='destroy')
      $file = public_path().'/storage'.$request['old_image'];

      $validatedData = $request->validate(['images'=> 'string',]);

      $old_images = explode(',', $request['images']);
      $paths = array();
      foreach ($old_images as $old)
      ($old != $request['old_image']) ? $paths[] = $old : null ;

      (File::exists($file)) ? File::delete($file) : null;

      Announcement::where('slug', $id)->update(array_merge($validatedData,array('images'=>implode(",",$paths),)));
      return redirect()->route('announcements.edit',[$id])->with('status',1);

      return redirect()->route('announcements.edit',[$id])->with('status', 0);



      Route



      Route::resource('announcements', 'AnnouncementController', ['names' => [
      'index' => 'announcements',
      'store' => 'announcements.store',
      'show' => 'announcements.show',
      'destroy'=>'announcements.destroy',
      'update' => 'announcements.update',

      ]])









      share|improve this question
















      On edit.blade.page there is a button for file deleting which leads to the update method in a controller. The update method calls private deleteImage method from which I want to redirect a user back to edit.blade.page, but it redirects me somewhere else.
      I have tried all approach from the documentation



      Controller



      public function update(Request $request, $id)
      ($request['method']==true) ? $this->imageDelete($request, $id) : null;


      private function imageDelete (Request $request, $id)
      if($request['method']=='destroy')
      $file = public_path().'/storage'.$request['old_image'];

      $validatedData = $request->validate(['images'=> 'string',]);

      $old_images = explode(',', $request['images']);
      $paths = array();
      foreach ($old_images as $old)
      ($old != $request['old_image']) ? $paths[] = $old : null ;

      (File::exists($file)) ? File::delete($file) : null;

      Announcement::where('slug', $id)->update(array_merge($validatedData,array('images'=>implode(",",$paths),)));
      return redirect()->route('announcements.edit',[$id])->with('status',1);

      return redirect()->route('announcements.edit',[$id])->with('status', 0);



      Route



      Route::resource('announcements', 'AnnouncementController', ['names' => [
      'index' => 'announcements',
      'store' => 'announcements.store',
      'show' => 'announcements.show',
      'destroy'=>'announcements.destroy',
      'update' => 'announcements.update',

      ]])






      php laravel redirect routes






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 26 at 16:35







      Virtual Device

















      asked Mar 26 at 16:12









      Virtual DeviceVirtual Device

      791 silver badge9 bronze badges




      791 silver badge9 bronze badges






















          3 Answers
          3






          active

          oldest

          votes


















          0














          Just use the route helper with the redirect helper to specify the route name you wish to go to:



          return redirect()->route('your.route.name');


          Note: This requires you to have named your route e.g.



          Route::get('/test', 'SomeController@index')->name('test')


          or you can pass the URL directly to redirect.



          I've generally found that being explicit in what I want my code to do prevents mistakes / unintended side-effects down the line.






          share|improve this answer























          • Although in the first place, I posted with back() method, I usually use this approach in my routing. Unfortunately, it doesn't work. I added my route code maybe you can take a look once again?

            – Virtual Device
            Mar 26 at 16:31


















          0














          You have 2 good options:



          return redirect('/edit');

          return view('your.view');


          Either should be able to accomplish what you're trying to do.






          share|improve this answer























          • Actually, you have one realistic option because, IIRC, just calling view won't fire the corresponding controller, it'll just show the view.

            – Script47
            Mar 26 at 16:16











          • Return view seems like a good idea but still doesn't work.

            – Virtual Device
            Mar 26 at 16:32


















          0














          Alright! It seems like laravel doesn't see the return from other functions rather than predefined by itself.
          So the solution, in that case, would be making the return from within the update method



          public function update(Request $request, $id)
          return ($request['method']==true) ? $this->imageDelete($request, $id) : null;






          share|improve this answer

























            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%2f55361671%2fhow-to-redirect-back-to-edit-page-from-a-called-function%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Just use the route helper with the redirect helper to specify the route name you wish to go to:



            return redirect()->route('your.route.name');


            Note: This requires you to have named your route e.g.



            Route::get('/test', 'SomeController@index')->name('test')


            or you can pass the URL directly to redirect.



            I've generally found that being explicit in what I want my code to do prevents mistakes / unintended side-effects down the line.






            share|improve this answer























            • Although in the first place, I posted with back() method, I usually use this approach in my routing. Unfortunately, it doesn't work. I added my route code maybe you can take a look once again?

              – Virtual Device
              Mar 26 at 16:31















            0














            Just use the route helper with the redirect helper to specify the route name you wish to go to:



            return redirect()->route('your.route.name');


            Note: This requires you to have named your route e.g.



            Route::get('/test', 'SomeController@index')->name('test')


            or you can pass the URL directly to redirect.



            I've generally found that being explicit in what I want my code to do prevents mistakes / unintended side-effects down the line.






            share|improve this answer























            • Although in the first place, I posted with back() method, I usually use this approach in my routing. Unfortunately, it doesn't work. I added my route code maybe you can take a look once again?

              – Virtual Device
              Mar 26 at 16:31













            0












            0








            0







            Just use the route helper with the redirect helper to specify the route name you wish to go to:



            return redirect()->route('your.route.name');


            Note: This requires you to have named your route e.g.



            Route::get('/test', 'SomeController@index')->name('test')


            or you can pass the URL directly to redirect.



            I've generally found that being explicit in what I want my code to do prevents mistakes / unintended side-effects down the line.






            share|improve this answer













            Just use the route helper with the redirect helper to specify the route name you wish to go to:



            return redirect()->route('your.route.name');


            Note: This requires you to have named your route e.g.



            Route::get('/test', 'SomeController@index')->name('test')


            or you can pass the URL directly to redirect.



            I've generally found that being explicit in what I want my code to do prevents mistakes / unintended side-effects down the line.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 26 at 16:13









            Script47Script47

            10.4k4 gold badges27 silver badges50 bronze badges




            10.4k4 gold badges27 silver badges50 bronze badges












            • Although in the first place, I posted with back() method, I usually use this approach in my routing. Unfortunately, it doesn't work. I added my route code maybe you can take a look once again?

              – Virtual Device
              Mar 26 at 16:31

















            • Although in the first place, I posted with back() method, I usually use this approach in my routing. Unfortunately, it doesn't work. I added my route code maybe you can take a look once again?

              – Virtual Device
              Mar 26 at 16:31
















            Although in the first place, I posted with back() method, I usually use this approach in my routing. Unfortunately, it doesn't work. I added my route code maybe you can take a look once again?

            – Virtual Device
            Mar 26 at 16:31





            Although in the first place, I posted with back() method, I usually use this approach in my routing. Unfortunately, it doesn't work. I added my route code maybe you can take a look once again?

            – Virtual Device
            Mar 26 at 16:31













            0














            You have 2 good options:



            return redirect('/edit');

            return view('your.view');


            Either should be able to accomplish what you're trying to do.






            share|improve this answer























            • Actually, you have one realistic option because, IIRC, just calling view won't fire the corresponding controller, it'll just show the view.

              – Script47
              Mar 26 at 16:16











            • Return view seems like a good idea but still doesn't work.

              – Virtual Device
              Mar 26 at 16:32















            0














            You have 2 good options:



            return redirect('/edit');

            return view('your.view');


            Either should be able to accomplish what you're trying to do.






            share|improve this answer























            • Actually, you have one realistic option because, IIRC, just calling view won't fire the corresponding controller, it'll just show the view.

              – Script47
              Mar 26 at 16:16











            • Return view seems like a good idea but still doesn't work.

              – Virtual Device
              Mar 26 at 16:32













            0












            0








            0







            You have 2 good options:



            return redirect('/edit');

            return view('your.view');


            Either should be able to accomplish what you're trying to do.






            share|improve this answer













            You have 2 good options:



            return redirect('/edit');

            return view('your.view');


            Either should be able to accomplish what you're trying to do.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 26 at 16:15









            LulceltechLulceltech

            1,2913 silver badges14 bronze badges




            1,2913 silver badges14 bronze badges












            • Actually, you have one realistic option because, IIRC, just calling view won't fire the corresponding controller, it'll just show the view.

              – Script47
              Mar 26 at 16:16











            • Return view seems like a good idea but still doesn't work.

              – Virtual Device
              Mar 26 at 16:32

















            • Actually, you have one realistic option because, IIRC, just calling view won't fire the corresponding controller, it'll just show the view.

              – Script47
              Mar 26 at 16:16











            • Return view seems like a good idea but still doesn't work.

              – Virtual Device
              Mar 26 at 16:32
















            Actually, you have one realistic option because, IIRC, just calling view won't fire the corresponding controller, it'll just show the view.

            – Script47
            Mar 26 at 16:16





            Actually, you have one realistic option because, IIRC, just calling view won't fire the corresponding controller, it'll just show the view.

            – Script47
            Mar 26 at 16:16













            Return view seems like a good idea but still doesn't work.

            – Virtual Device
            Mar 26 at 16:32





            Return view seems like a good idea but still doesn't work.

            – Virtual Device
            Mar 26 at 16:32











            0














            Alright! It seems like laravel doesn't see the return from other functions rather than predefined by itself.
            So the solution, in that case, would be making the return from within the update method



            public function update(Request $request, $id)
            return ($request['method']==true) ? $this->imageDelete($request, $id) : null;






            share|improve this answer



























              0














              Alright! It seems like laravel doesn't see the return from other functions rather than predefined by itself.
              So the solution, in that case, would be making the return from within the update method



              public function update(Request $request, $id)
              return ($request['method']==true) ? $this->imageDelete($request, $id) : null;






              share|improve this answer

























                0












                0








                0







                Alright! It seems like laravel doesn't see the return from other functions rather than predefined by itself.
                So the solution, in that case, would be making the return from within the update method



                public function update(Request $request, $id)
                return ($request['method']==true) ? $this->imageDelete($request, $id) : null;






                share|improve this answer













                Alright! It seems like laravel doesn't see the return from other functions rather than predefined by itself.
                So the solution, in that case, would be making the return from within the update method



                public function update(Request $request, $id)
                return ($request['method']==true) ? $this->imageDelete($request, $id) : null;







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 26 at 16:59









                Virtual DeviceVirtual Device

                791 silver badge9 bronze badges




                791 silver badge9 bronze badges



























                    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%2f55361671%2fhow-to-redirect-back-to-edit-page-from-a-called-function%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