PHP code example of crumby / route-resolver

1. Go to this page and download the library: Download crumby/route-resolver 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/ */

    

crumby / route-resolver example snippets


> composer san vendor:publish --provider="Crumby\RouteResolver\RouteResolverServiceProvider" --tag=config

'providers' => [
    ......................
    'Crumby\RouteResolver\RouteResolverServiceProvider',
    ........................
 ];
 
 'aliases' => [ 
    ......................
    'RouteResolver' => 'Crumby\RouteResolver\Facades\RouteResolver',
    ......................
 ];

    
    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 <[email protected]>
     */
    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;
        }
    }