How to store data from Repository in Bagisto

Updated 30 August 2022

In Bagisto we use a Repository pattern for interacting with the Database and before going forward to create the files we have to understand some concepts e.g – Contracts, Repository, and Model Proxies

Contracts

Contracts are a set of interfaces that define the core services provided by the Laravel framework. For example, the Illuminate\Contracts\Mail\Mailer contract defines the methods needed for sending an e-mail.

Repositories

Repositories create a bridge between models and controllers. Decouple the hard dependencies of models from the controllers. The model should not be responsible for communicating with or extracting data from the database

Model Proxies

The concept of Model proxies has been introduced to override the functionality of the existing Model. It is a type of model inheritance without creating a new table in the database.

Now, Let’s Get Started,

Step 1

First, we have to create a Model in packages/Webkul/HelloWorld/src/Models as illustrated below

Step 2

Now create an interface in a folder named Contract path packages/Webkul/HelloWorld/src/Contract and also implement the interface class in the above Model class

Step 3

In Bagisto we create a layer above the Model which we called Model Proxy. For this, we have to create a class where the Model exists which extends a class Konekt\Concord\Proxies\ModelProxy as illustrated below

Step 4

Now create a folder Repositories in which create a class HelloWorldRepository.php that extends Webkul\Core\Eloquent\Repository and create a method model() in the class that returns the path of the contract

Step 5

After creating the above files, Create a Service Provider as ModuleServiceProvider.php  which extends the Konekt\Concord\BaseModuleServiceProvider as illustrated below

Step 6

Now Register the Service Provider in the config/concord.php file

Now Run command

 

We will consistently update blog posts, so don’t forget to keep a check on it regularly. Also for any queries or doubts reach out to us at [email protected]. You can also raise a ticket at our HelpDesk System.

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Start a Project




    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home