On laravel 10 site I have a traite with getModelTitle method defined
<?php
namespace AppLibraryTraits;
trait AppCommonTrait
{
protected function getModelTitle(string $dataType): string
{
$a = Str::of($dataType)->explode('\');
return ((count($a) === 3)) ? $a[2] : '';
}
But I failed to call it from a static app/Data/DataObjectUser.php class :
use AppModelsPost;
use SpatieLaravelDataData;
class DataObjectUser extends Data // extends spatie/laravel-data package
{
use AppCommonTrait;
public function __construct() {
...
}
public static function getFilteredData(bool $returnJson = false, bool $extendResource = false): array
{
return self::$dataRows;
}
public static function filter(): bool
{
$model = self::getModelTitle(Post::class);
I have error :
Non-static method AppDataDataObjectUser::getModelTitle() cannot be called statically
Object DataObjectUser called statically and I do not know if there is a way it calls traite method ?
"laravel/framework": "^10.48.7",
"spatie/laravel-data": "^4.4.1",
Thanks in advance!