Skip to content

[5.4] Allow non-method Callables#19168

Merged
taylorotwell merged 2 commits into
laravel:5.4from
ConnorVG:patch-2
May 12, 2017
Merged

[5.4] Allow non-method Callables#19168
taylorotwell merged 2 commits into
laravel:5.4from
ConnorVG:patch-2

Conversation

@ConnorVG

Copy link
Copy Markdown
Contributor

Currently if you have a dynamic controller method (via __call) it will fail because of ReflectionMethod not finding the explicit method.

Here is an example, say we have ViewController that is simply:

namespace App\Http\Controllers;

class ViewController extends Controller
{
    /**
     * Get a static page view.
     *
     * @param string $method
     * @param array  $arguments
     *
     * @return \Illuminate\Http\Response
     */
    public function __call($method, $arguments = [])
    {
        return view($method)
            ->with($arguments);
    }
}

A route definition of:

$router->get('/', [
    'as' => 'get::home',
    'uses' => 'ViewController@home',
]);

and a view home.blade.php of:

<h1>We're home!</h1>

With the current setup it will fail with Method App\Http\Controllers\ViewController::home() does not exist but with the alteration it will succeed as it is still callable just not an explicit method.

@m1guelpf

Copy link
Copy Markdown
Contributor

Could you add some tests for this?

@ntzm

ntzm commented May 12, 2017

Copy link
Copy Markdown
Contributor

I think this is a good idea 👍

@ConnorVG ConnorVG changed the title Allow non-method Callables [5.4] Allow non-method Callables May 12, 2017
@taylorotwell taylorotwell merged commit 0cf1f76 into laravel:5.4 May 12, 2017
@ConnorVG ConnorVG deleted the patch-2 branch May 12, 2017 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants