Open Grummfy opened 6 years ago
I don't understand what you mean - could you please provide some code example?
I also think this would be great! Especially when using enums.
You now get the Unresolvable dependency resolving [Parameter #0 [ <required> array $values ]] in class SomeValueObject
:
Example:
use Illuminate\Contracts\Routing\UrlRoutable;
class SomeValueObject implements UrlRoutable
{
public int $id;
public function __construct(array $values)
{
$this->id = $values['id'];
}
public function resolveRouteBinding($value)
{
if ($value === 'valid') {
return new self(['id' => $value]);
}
return null;
}
public function getRouteKey()
{
return $this->id;
}
public function getRouteKeyName(): string
{
return 'id';
}
}
Route:
Route::get('/foo/{some}', function (SomeValueObject $foobar) {
dd('never getting here :(');
});
If resolveRouteBinding
was static it would just skip the constructor meaning you won't get the exception.
Hello, today if we have an eloquent model we simply bind (if specific needs) it to the route or just do anything and laravel will do the work perfectly. It's simple and very helpful.
Today, more and more people use value object (or other class) for a lot of things. It could be very helpful to have something similar.
Three way of doing this, pop in my mind:
Thanks