baks-dev/manufacture-part
Laravel/PHP модуль производства партий продукции (manufacture-part). Поддерживает установку через Composer, установку конфигурации и ресурсов, обновление схемы БД через миграции Doctrine и запуск PHPUnit-тестов группы manufacture-part.
Prerequisites:
composer require baks-dev/manufacture-part baks-dev/users-table baks-dev/core
php artisan vendor:publish --provider="BaksDev\ManufacturePart\ManufacturePartServiceProvider"
Database Setup:
php artisan migrate
php artisan doctrine:migrations:diff
php artisan doctrine:migrations:migrate
First Use Case:
BatchManager service:
use BaksDev\ManufacturePart\Service\BatchManager;
$batchManager = app(BatchManager::class);
$batch = $batchManager->create([
'product_id' => 1,
'quantity' => 100,
'serial_prefix' => 'PROD-2024',
]);
$serials = $batchManager->generateSerials($batch->id, 100);
Key Configuration:
.env for batch settings (e.g., MANUFACTURE_PART_SERIAL_FORMAT).baks-dev/users-table (if using its auth system).Batch Creation & Management:
BatchManager for CRUD operations.
// Create with custom attributes
$batch = $batchManager->create([
'product_id' => 1,
'expiry_date' => now()->addYear(),
'notes' => 'Premium batch',
]);
BatchValidator for custom rules:
use BaksDev\ManufacturePart\Validator\BatchValidator;
class CustomBatchValidator extends BatchValidator {
protected function rules(): array {
return array_merge(parent::rules(), [
'custom_field' => 'required|string',
]);
}
}
Serial Number Handling:
$batchManager->generateSerials($batchId, 50, 'SERIAL-{YYYYMMDD}-{INCREMENT}');
if ($batchManager->isValidSerial($batchId, 'INVALID-123')) {
// Handle invalid serial
}
CLI Integration:
// Example: Convert Symfony command to Artisan
php artisan manufacture:create --product=1 --quantity=100
php artisan make:command ManufactureBatchReport
// In command handler
$this->call('manufacture:list', ['--batch-id' => $batchId]);
Event-Driven Extensions:
BatchCreated):
use BaksDev\ManufacturePart\Event\BatchCreated;
event(new BatchCreated($batch));
event(new CustomBatchEvent($batch));
baks-dev/users-table permissions with Laravel’s Gate or Policy:
Gate::define('manage-batches', function (User $user) {
return $user->hasRole('admin');
});
laravel-doctrine/orm for hybrid ORM or translate models:
// Example: Convert Doctrine entity to Eloquent
class Batch extends Model {
protected $connection = 'doctrine';
}
Route::apiResource:
Route::apiResource('batches', BatchController::class)
->middleware('auth:sanctum');
Symfony Dependency Hell:
baks-dev/core may conflict with Laravel’s service container.Symfony\Component\DependencyInjection\ContainerInterface adapter:
$container = new ContainerBuilder();
$container->register('batch.manager', BatchManager::class);
Migration Conflicts:
Schema::connection('doctrine')->raw('ALTER TABLE batches ADD COLUMN custom_field VARCHAR(255)');
CLI Tooling Gaps:
bin/console won’t work in Laravel.php artisan manufacture:create --help
// In ArtisanCommand
protected $signature = 'manufacture:create {product} {quantity}';
Serialization Format Collisions:
$batchManager->validateSerialFormat('PROD-{INCREMENT}', 1000);
Doctrine Debugging:
$doctrineConfig->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
dd() with Doctrine entities:
dd($batch->getSerials()->toArray());
Event Listener Issues:
EventServiceProvider:
protected $listen = [
BatchCreated::class => [
BatchCreatedListener::class,
],
];
Permission Denied:
403 Forbidden on batch operations.baks-dev/users-table roles are synced with Laravel’s auth:
if (!auth()->user()->can('manage-batches')) {
abort(403);
}
Custom Batch Attributes:
Batch entity:
namespace App\Entity;
use BaksDev\ManufacturePart\Entity\Batch as BaseBatch;
class Batch extends BaseBatch {
#[ORM\Column]
private string $customAttribute;
}
Validation Rules:
BatchValidator:
class ExtendedBatchValidator extends BatchValidator {
public function validate(array $data, Batch $batch = null): void {
parent::validate($data, $batch);
$this->validateCustomRules($data);
}
}
Serial Number Generators:
SerialGeneratorInterface:
class CustomSerialGenerator implements SerialGeneratorInterface {
public function generate(int $batchId, int $quantity, string $format): array {
return array_map(fn($i) => str_replace(
['{INCREMENT}'],
[$i],
$format
), range(1, $quantity));
}
}
API Resources:
BatchResource (if using API tools like spatie/laravel-api-resources):
class CustomBatchResource extends BatchResource {
public function toArray($request) {
$array = parent::toArray($request);
$array['custom_field'] = $this->customField;
return $array;
}
}
Environment Variables:
.env structure.config/manufacture-part.php:
'serial_format' => env('MANUFACTURE_PART_SERIAL_FORMAT', 'PROD-{INCREMENT}'),
Doctrine Configuration:
config/packages/doctrine.php:
doctrine:
dbal:
connections:
default:
url: '%env(DATABASE_URL)%'
Translation Strings:
How can I help you explore Laravel packages today?