Package Data | |
---|---|
Maintainer Username: | crumby |
Maintainer Contact: | avassilenko2@gmail.com (Andrei Vassilenko) |
Package Create Date: | 2017-08-14 |
Package Last Update: | 2017-08-23 |
Language: | PHP |
License: | MIT License |
Last Refreshed: | 2024-11-15 15:02:10 |
Package Statistics | |
---|---|
Total Downloads: | 92 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 0 |
Total Forks: | 0 |
Total Open Issues: | 0 |
> composer require crumby/route-resolver:"dev-master"
> php artisan vendor:publish --provider="Crumby\RouteResolver\RouteResolverServiceProvider" --tag=config
File: config/app.php
'providers' => [
......................
'Crumby\RouteResolver\RouteResolverServiceProvider',
........................
];
'aliases' => [
......................
'RouteResolver' => 'Crumby\RouteResolver\Facades\RouteResolver',
......................
];
<?php
namespace App\Resolvers;
use Crumby\RouteResolver\Contracts\ParamResolver as ParamResolver;
use Crumby\RouteResolver\Contracts\ParamResolverCollection as ParamResolverCollection;
use App\Content as Content;
/**
* Description of PackageResolver
*
* @author Andrei Vassilenko <avassilenko2@gmail.com>
*/
class PackageResolver implements ParamResolver, ParamResolverCollection {
protected $service;
public function __construct(Content $content) {
$this->service = $content;
}
public function collection($param=null) {
return Content::fillIds($this->service->getIdsWithSameAttribute('content_group'), ['att' => 'content_locale', 'excl' => 'value']);
}
public function item($param=null) {
return Content::fillIds([$this->service->id], ['att' => 'content_locale', 'excl' => 'value'])->first();
}
public function label($item=null) {
return $item->title;
}
public function locale($item=null) {
return $item->attr_value;
}
public function segment($item=null) {
return $item->slug;
}
}
return [
.........................
'package' => 'App\Resolvers\PackageResolver',
........................
];
when route resolve route /packages/{package} it calls Resolver Service and substitute last segment of url {package} with localized value returned by Resolver Class method segment(), in our example PackageResolver::segment().
in file, for example: app/Resolvers/PackageResolver.php
$resolvers = \RouteResolver::getFromRequest()
// below returns something like /packages/{package}
$uriWithParam = \Route::getCurrentRoute()->uri();
$allRoutes = \RouteResolver::resolveRouteCollection($uriWithParam, $resolvers);
https://semver.mwl.be/#?package=crumby%2Froute-resolver&version=dev-master&minimum-stability=stable