Support the ongoing development of Laravel.io →
Requests Eloquent IOC
Last updated 2 years ago.
0

Laravel Docs says:

Sometimes you may wish to use your own resolver for route parameters. Simply use the Route::bind method:

Route::bind('user', function($value, $route) { return User::where('name', $value)->first(); });

using the above you could setup a route service provider. Something like this

class RoutesServiceProvider
{
	//Inject reposiotry into constructor

	public function $register($app)
	{
		$app['router']->bind('model', function($id, $route)) {
			return $this->modelRepository->findById($id);
		}

	}
}
Last updated 2 years ago.
0

Thank you very much! I can't implement it right now but wanted to thank you for taking the time to answer so clearly. I'll update my replay as soon as I have chance to add the code.

Last updated 2 years ago.
0

Thanks damienadermann, really appreciate the help!

Last updated 2 years ago.
0

How this can be done in laravel 5.3 ?

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Deacs deacs Joined 17 Dec 2013

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.