<commit_before><?php

namespace pelmered\APIHelper\Traits;

use pelmered\APIHelper\APIHelper;
use pelmered\APIHelper\ApiSerializer;

use Illuminate\Support\Facades\Auth;
use App\Http\Requests;
use Illuminate\Support\Facades\Gate;

use League\Fractal\Manager;
use League\Fractal\Resource\Collection;
use League\Fractal\Resource\Item;

trait ControllerRelationActions
{
    protected $resource = null;

    public function getSignleRelation($transformer, $resourceId, $relation, $relationId)
    {
        $model = static::RESOURCE_MODEL;

        $resource = $model::find($resourceId);

        if (!$resource) {
            return $this->notFoundResponse();
        }

        if (Gate::denies('read_'.$relation, $resource)) {
            return $this->permissionDeniedResponse();
        }

        $resourceRelation = $resource->$relation()->find($relationId);

        if (!$resourceRelation) {
            return $this->notFoundResponse();
        }

        $item = new Item($resourceRelation, $transformer);

        $data = $this->fractal->createData($item)->toArray();

        return $this->response($data);
    }

    /**
     * Get a listing of the resource.
     *
     * @return Response
     */<commit_msg>Fixed function name for getSingleRelation<commit_after><?php

namespace pelmered\APIHelper\Traits;

use pelmered\APIHelper\APIHelper;
use pelmered\APIHelper\ApiSerializer;

use Illuminate\Support\Facades\Auth;
use App\Http\Requests;
use Illuminate\Support\Facades\Gate;

use League\Fractal\Manager;
use League\Fractal\Resource\Collection;
use League\Fractal\Resource\Item;

trait ControllerRelationActions
{
    protected $resource = null;

    public function getSingleRelation($transformer, $resourceId, $relation, $relationId)
    {
        $model = static::RESOURCE_MODEL;

        $resource = $model::find($resourceId);

        if (!$resource) {
            return $this->notFoundResponse();
        }

        if (Gate::denies('read_'.$relation, $resource)) {
            return $this->permissionDeniedResponse();
        }

        $resourceRelation = $resource->$relation()->find($relationId);

        if (!$resourceRelation) {
            return $this->notFoundResponse();
        }

        $item = new Item($resourceRelation, $transformer);

        $data = $this->fractal->createData($item)->toArray();

        return $this->response($data);
    }

    /**
     * Get a listing of the resource.
     *
     * @return Response
     */
{'fraction_non_alphanumeric': 0.13209076175040518, 'fraction_numerical': 0.0, 'mean_word_length': 3.0016207455429496, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6633602', 'n_tokens_mistral': 725, 'n_tokens_neox': 718, 'n_words': 134}