You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am new to using this package and although I read the documentation completely, I am confused about using it.
Imagine I have a product class and each product has several photos. I use the spatie media-library package to manage photos. How should my ProductData class be so I can use it both when creating the product with the form and displaying it?
I know that I can use the fromModel method as below, but in this case, what should I do to create the product through ProductData?
class ProductData extends Data
{
/**
* @param Collection<int, Media> $media
*/
public function __construct(
public string $title,
public array $media,
) {
}
public static function fromModel(Product $product): self
{
return new self(
$product->title,
$product->getMedia()
);
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am new to using this package and although I read the documentation completely, I am confused about using it.
Imagine I have a product class and each product has several photos. I use the spatie media-library package to manage photos. How should my ProductData class be so I can use it both when creating the product with the form and displaying it?
I know that I can use the fromModel method as below, but in this case, what should I do to create the product through ProductData?
Beta Was this translation helpful? Give feedback.
All reactions