A
A
Alexander Alexandrovich2020-04-22 14:20:29
Laravel
Alexander Alexandrovich, 2020-04-22 14:20:29

How can one get expected values ​​with resolveRouteBinding?

I want to get an array of arguments that are expected in the method, for this:

class Example
{
    /**
     * @param \App\User $user
     *
     * @return \App\User
     */
    public function run(\App\User $user)
    {
        return $user;
    }
}


Route::get('/{user}', function () {

    $example = new Example();
    $class = new ReflectionClass($example);
    
    $current = Route::current();

    $arguments = $current->resolveMethodDependencies(
        $current->parameters(),
        $class->getMethod('run'),
    );

    dd($arguments);
});


I pull off the address ` example.com/1 ` and expect the ` $arguments ` array to contain the user model with the ordinal passed in, but it doesn't. The array consists of an empty model and a passed value:

array:2 [▼
  0 => App\User {#359 ▶}
  "user" => "1"
]


How can I achieve the desired behavior with the execution of the bind ( \Illuminate\Contracts\Routing\UrlRoutable::class ) for such an example?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question