-
Hi, in first thank you for your package, I have a problem loading relation from role with my DTO. I have same schema with my other DTO's and they work. I show you my RoleDTO : <?php
namespace App\Data;
use Spatie\LaravelData\Data;
use Spatie\LaravelData\DataCollection;
use Spatie\LaravelData\Lazy;
use Spatie\LaravelData\Optional;
use Spatie\Permission\Models\Role;
use Spatie\TypeScriptTransformer\Attributes\TypeScript;
#[TypeScript]
class RoleData extends Data
{
public function __construct(
public int $id,
public string $name,
/** @var DataCollection<PermissionData> */
public Lazy|DataCollection|Optional $permissions,
public string $created_at,
public string $updated_at,
) {
}
public static function fromModel(Role $role): self
{
dd($role->toArray());
return new self(
id: $role->id,
name: $role->name,
permissions: Lazy::create(fn () => PermissionData::collection($role->permissions)),
created_at: $role->created_at->toDateTimeString(),
updated_at: $role->updated_at->toDateTimeString(),
);
}
} You can observe dd before return. It show me that permissions are correctly loaded. I don't understand why when use it to my front I have undefined value ( I use Inertia React TS ) Thank you in advanced for your help |
Beta Was this translation helpful? Give feedback.
Answered by
Tiskiel
May 12, 2023
Replies: 1 comment
-
My bad, I bad reading documentation to laravel-data to Spatie. I need use : Lazy::whenLoaded('permissions', $role, fn () => PermissionData::collection($role->permissions)) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Tiskiel
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My bad, I bad reading documentation to laravel-data to Spatie.
I need use :
Spatie laravel-data