byCedric/Allay

View on GitHub
src/Http/Controllers/Traits/ShowAction.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

/*
 * This file is part of the Allay package.
 *
 * (c) Cedric van Putten <me@bycedric.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace ByCedric\Allay\Http\Controllers\Traits;

use ByCedric\Allay\Contracts\Resource\Manager;
use ByCedric\Allay\Contracts\Resource\Readable;
use ByCedric\Allay\Contracts\Resource\Resolver;

trait ShowAction
{
    /**
     * Display a single resource, that matches the requested id.
     *
     * @param  \ByCedric\Allay\Contracts\Resource\Manager  $manager
     * @param  \ByCedric\Allay\Contracts\Resource\Resolver $resolver
     * @return mixed
     */
    public function show(Manager $manager, Resolver $resolver)
    {
        $resource = $manager->make($resolver->getResource());

        if ($resource instanceof Readable) {
            $resource = $resource->getReadableQuery($resource->newQuery());
        }

        return $resource->findOrFail($resolver->getId());
    }
}