1

I'm relatively new to the laravel framework and i noticed a pretty disturbing issue with laravel controllers. I dont know if its me but it doesnt seem to work at all. Lets say i have a controller and i want to split the logic contained in the method called when the request hits a route tied to the controller.

class SomeController extends BaseController
{
    function doSomething()
    {
        $this->doSomethingExtra();
    }

    function doSomethingExtra()
    {
        return "Something Extra Done";
    }
}

And lets say a have to route defined like so

Route::get('main/dashboard','SomeController@doSomething');

the second method called from the first never returns the string "Something Extra Done" to the browser. infact it returns an empty 200 response. However this seems to work when you return response from the doSomething() as usual. Anyone know why this is behaving this way? is there anyway to breakup a controller logic into several Methods that actually return responses to the client?

1 Answer 1

5

Change this

 $this->doSomethingExtra();

to this.

 return $this->doSomethingExtra();
Sign up to request clarification or add additional context in comments.

2 Comments

You Sir deserve a beer!! Thanks a bunch
I'd like to add this has nothing to do with Laravel controllers. This is the intended behavior of PHP.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.