Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

to list all relations of model laravel

public static function definedRelations(): array
{
      $reflector = new ReflectionClass(get_called_class());

      return collect($reflector->getMethods())
          ->filter(
              fn($method) => !empty($method->getReturnType()) &&
                  str_contains(
                      $method->getReturnType(), 
                      'IlluminateDatabaseEloquentRelations'
                 )
          )
          ->pluck('name')
          ->all();
 }
Source by laracasts.com #
 
PREVIOUS NEXT
Tagged: #list #relations #model #laravel
ADD COMMENT
Topic
Name
4+9 =