2024-08-07 23:30:09 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Api\V0;
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use Illuminate\Support\Str;
|
2024-09-11 23:08:58 -04:00
|
|
|
use Psr\Container\ContainerExceptionInterface;
|
|
|
|
use Psr\Container\NotFoundExceptionInterface;
|
2024-08-07 23:30:09 -04:00
|
|
|
|
|
|
|
class ApiController extends Controller
|
|
|
|
{
|
2024-08-08 16:11:50 -04:00
|
|
|
/**
|
|
|
|
* Determine if the given relationship should be included in the request. If more than one relationship is provided,
|
|
|
|
* only one needs to be present in the request for this method to return true.
|
|
|
|
*/
|
|
|
|
public static function shouldInclude(string|array $relationships): bool
|
2024-08-07 23:30:09 -04:00
|
|
|
{
|
2024-09-11 23:08:58 -04:00
|
|
|
try {
|
|
|
|
$param = request()->get('include');
|
|
|
|
} catch (NotFoundExceptionInterface|ContainerExceptionInterface $e) {
|
|
|
|
return false;
|
|
|
|
}
|
2024-08-07 23:30:09 -04:00
|
|
|
|
|
|
|
if (! $param) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$includeValues = explode(',', Str::lower($param));
|
|
|
|
|
2024-08-08 16:11:50 -04:00
|
|
|
if (is_array($relationships)) {
|
|
|
|
foreach ($relationships as $relationship) {
|
|
|
|
if (in_array(Str::lower($relationship), $includeValues)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return in_array(Str::lower($relationships), $includeValues);
|
2024-08-07 23:30:09 -04:00
|
|
|
}
|
|
|
|
}
|