Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel redirection from private method

I have a controller that has a method. The code is too long in the method, so I have put some of the codes in other private methods, so that methods become understandable and not make a mess out of it.

Now, when I access the public method from the URL, depending on parameters, it will call a specific private method to process the job. After the job is processed, I want to redirect to a URL, but the redirection is not working.

A sample of my code is as follows:

class SomeClass extends BaseController{
    public function getMethodName()
        {
            //check the params and choose a private method to call
            $this->processJob();
        }
    private function processJob()
    {
         //process the job and redirect at the end
         return Redirect::to('some/url');
    }
}

The problem is, the above redirect does not work. Why is that? In Codeigniter, when you used redirect it works nomatter where it is called from.

If the above code sample is not the right way to do it, would appreciate if someone could show me how it is to be done. Thanks.

like image 213
WebNovice Avatar asked Jul 29 '13 14:07

WebNovice


2 Answers

You have to return the return from $this->processJob() too.

class SomeClass extends BaseController{
  public function getMethodName()
  {
      //check the params and choose a private method to call
      return $this->processJob();
  }

  private function processJob()
  {
     //process the job and redirect at the end
     return Redirect::to('some/url');
  }
}
like image 158
mgrueter Avatar answered Oct 26 '22 10:10

mgrueter


You can try to redirect to another page from your public function, according to your private function result (I think it's a better solution to make your code more human readable). But it could works like you wrote it ...

like image 26
netvision73 Avatar answered Oct 26 '22 10:10

netvision73