src/Eloquent/Model.php
public function accessibleRelationsToArray()
	{
		$filtered  = [];
		$relations = $this->getArrayableRelations();

		/**
		 * @var $related \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Relations\Pivot
		 */
		foreach ($relations as $key => $related_collection) {
			if (! $this->access_authorizer->canAccess($key)) {
				continue;
			}

			if ($related_collection instanceof Pivot) {
				// Access test done above
				$filtered[$key] = $related_collection;
				continue;
			}

			// Many relation
			if ($related_collection instanceof Collection) {
				foreach ($related_collection as $index => $related) {
					$filtered[$key][$index] = $related->accessibleAttributesToArray();
				}
			} elseif ($related_collection instanceof LaravelModel) {
				// Single relation
				$filtered[$key] = $related_collection->accessibleAttributesToArray();
			}
		}

		return $filtered;
	}
public function accessibleRelationsToArray()
	{
		$filtered  = [];
		$relations = $this->getArrayableRelations();

		/**
		 * @var $related \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Relations\Pivot
		 */
		foreach ($relations as $key => $related_collection) {
			if (! $this->access_authorizer->canAccess($key)) {
				continue;
			}

			if ($related_collection instanceof Pivot) {
				// Access test done above
				$filtered[$key] = $related_collection;
				continue;
			}

			// Many relation
			if ($related_collection instanceof Collection) {
				foreach ($related_collection as $index => $related) {
					$filtered[$key][$index] = $related->accessibleAttributesToArray();
				}
			} elseif ($related_collection instanceof LaravelModel) {
				// Single relation
				$filtered[$key] = $related_collection->accessibleAttributesToArray();
			}
		}

		return $filtered;
	}
public function accessibleRelationsToArray ( ) { $ filtered = [ ] ; $ relations = $ this -> getArrayableRelations ( ) ; /**
		 * @var $related \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Relations\Pivot
		 */ foreach ( $ relations as $ key => $ related_collection ) { if ( ! $ this -> access_authorizer -> canAccess ( $ key ) ) { continue ; } if ( $ related_collection instanceof Pivot ) { // Access test done above $ filtered [ $ key ] = $ related_collection ; continue ; } // Many relation if ( $ related_collection instanceof Collection ) { foreach ( $ related_collection as $ index => $ related ) { $ filtered [ $ key ] [ $ index ] = $ related -> accessibleAttributesToArray ( ) ; } } elseif ( $ related_collection instanceof LaravelModel ) { // Single relation $ filtered [ $ key ] = $ related_collection -> accessibleAttributesToArray ( ) ; } } return $ filtered ; }
Filter relations which can and can't be accessed by the user

@return array
Filter relations which can and can t be accessed by the user