1. Go to this page and download the library: Download dyanakiev/lurobind-2020 library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
dyanakiev / lurobind-2020 example snippets
// app/Providers/RouteBindingServiceProvider.php
namespace App\Providers;
use mmghv\LumenRouteBinding\RouteBindingServiceProvider as BaseServiceProvider;
class RouteBindingServiceProvider extends BaseServiceProvider
{
/**
* Boot the service provider
*/
public function boot()
{
// The binder instance
$binder = $this->binder;
// Here we define our bindings
}
}
$instance = new App\User;
return $instance->where($instance->getRouteKeyName(), $value)->firstOrFail();
/**
* Get the route key for the model.
*
* @return string
*/
public function getRouteKeyName()
{
return 'slug';
}
// Using a 'Class@method' callable style
$binder->bind('article', 'App\Article@findForRoute');
// Using a closure
$binder->bind('article', function($value) {
return \App\Article::where('slug', $value)->firstOrFail();
});
$binder->bind('article', 'App\Article', function($e) {
// We can return a default value if the model not found :
return new \App\Article();
// Or we can throw another exception for example :
throw new \NotFoundHttpException;
});