Package Data | |
---|---|
Maintainer Username: | olego |
Maintainer Contact: | oleg.fedoliak@gmail.com (Oleg Fedoliak) |
Package Create Date: | 2017-05-13 |
Package Last Update: | 2017-08-25 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-11 15:24:53 |
Package Statistics | |
---|---|
Total Downloads: | 866 |
Monthly Downloads: | 12 |
Daily Downloads: | 3 |
Total Stars: | 22 |
Total Watchers: | 2 |
Total Forks: | 1 |
Total Open Issues: | 2 |
This package is made to generate Domains, based on DB table.
Package get all table fields and creates domain. With Domain creates repository, service and Infrastructure. Also the Package automatically binds generated classes to your app, so you can easily use DI or make Service by contract $service = app(UserServiceInterface::class);
php artisan make:domain User --table=users
Require this package with composer using the following command:
$ composer require oleglfed/laravel-ddd
Go to your config/app.php
and add the service provider:
\oleglfed\LaravelDDD\LaravelDddServiceProvider::class
This package creates app/Domain
and app/Infrastructure
directories. So at first package should be able to create these two directories. Afterwards, you can revoke writable access from app
directory.
This package requires writable permissions to config/domains directory.
Before use, create config/domains
directory with writable permissions or allow the package to write into config
directory. It is necessary for writing domains binding. Afterwards, these domains will be bound to your app by LaravelDddServiceProvider
$ php artisan make:domain User --table=users
To generate domain, use the make:domain
artisan command. This command will create in ths Domains and Infrastructures directories inside app/ folder domain classes.
E.g. for User will be created classes
UserEloquent
UserRepository
EloquentUserRepository
UserService
And contracts for this classes
Option | Description
--------- | -------
table
| Based on Table will be created Eloquent, getters and setters
directory
| By default directory name takes from domain name. To override it --directory might be set
domain-path
| By default domain directory is app/Domains. To override it --domain-path might be set
infrastructure-path
| By default infrastructure directory is app/Infrastructures. To override it --infrastructure-path might be set
This package contains a few useful methods to work with services and repositories.
public function index(UserServiceInterface $service)
{
$service->all(); //Shows all records
$service->get(1); //Shows record with ID: 1
$servcie->findWhere(['first_name' => 'Oleg']); //Returns all records with provided where
$servcie->deleteWhere(['first_name' => 'Oleg']); //Deletes all records with provided where
$servcie->firstOrCreate(['email' => 'oleg.fedoliak@gmail.com']); //Returns a record with provided where, or creates it
$servcie->firstOrNull(['email' => 'oleg.fedoliak@gmail.com']); //Returns a record with provided where, or null
$servcie->lists(20, 10, ['first_name', 'email']); //Returns paginated list with `per page`, `offset`, `columns` (all by default)
$servcie->count(); //Returns count of records
//Create
$user = $service->newInstance();
$user->setFirstName('Oleg');
$user->setEmail('oleg.fedoliak@gmail.com');
$user = $servcie->create($user);
//Update
$user->setFirstName('John');
$user = $servcie->update($user);
//Save. There is a method which will check if record is exists, and if so will update it. Otherwise create it.
$user = $servcie->save($user);
//Delete
$isDeleted = $servcie->delete($user);
}
If your routes use resource
you can explicitly bind Domains
Open Providers\RouteServiceProvider
and add:
\Route::model('user', App\Domains\User\UserEloquent::class);
Then you are able to use:
public function update(Request $request, UserInterface $user, UserServiceInterface $service)
{
dd($user); <-- will be dumped User Domain
}
The Laravel DDD Generator is free software licensed under the MIT license.