Save data with a resource model in Magento
Magento 2 resource model save data with PostRepository save method and CouldNotSaveException handling.
Lesson Content
We already have our PostFactory and Post classes injected into PostRepository within its constructor:
<?php
declare(strict_types=1);
namespace Macademy\Blog\Model;
use Macademy\Blog\Api\Data\PostInterface;
use Macademy\Blog\Model\ResourceModel\Post;
use Macademy\Blog\Api\PostRepositoryInterface;
use Magento\Framework\Exception\NoSuchEntityException;
class PostRepository implements PostRepositoryInterface
{
public function __construct(
private PostFactory $postFactory,
private Post $postReso...
Join the discussion!
Comments
Want to comment on this lesson?
Enroll in this course to leave comments.