forge/app/Http/Controllers/Api/V0/ApiController.php
Refringe 3a334033fe
API Updates
Brings the API in close sync to the rest of the site.
- Adds resources for License, UserRole, and ModVersion models
- Adds filtering on attribute data
- The `includes` data is now disabled by default and available conditionally
2024-08-08 16:11:50 -04:00

37 lines
973 B
PHP

<?php
namespace App\Http\Controllers\Api\V0;
use App\Http\Controllers\Controller;
use Illuminate\Support\Str;
class ApiController extends Controller
{
/**
* 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
{
$param = request()->get('include');
if (! $param) {
return false;
}
$includeValues = explode(',', Str::lower($param));
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);
}
}