Skip to content

Commit

Permalink
Allow customization of label class for fields & barcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
rpungello committed Jan 25, 2024
1 parent bedd092 commit a4163a4
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 2 deletions.
5 changes: 5 additions & 0 deletions config/labels.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

return [
'label_class' => \Rpungello\LaravelLabels\Models\Label::class,
];
1 change: 1 addition & 0 deletions src/LabelServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function configurePackage(Package $package): void
*/
$package
->name('laravel-label-printer')
->hasConfigFile('labels')
->hasMigration('create_labels_table')
->hasMigration('create_label_fields_table')
->hasMigration('create_label_barcodes_table');
Expand Down
2 changes: 1 addition & 1 deletion src/Models/LabelBarcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ class LabelBarcode extends Model

public function label(): Relation
{
return $this->belongsTo(Label::class);
return $this->belongsTo(config('labels.label_class'));
}
}
2 changes: 1 addition & 1 deletion src/Models/LabelField.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ class LabelField extends Model

public function label(): Relation
{
return $this->belongsTo(Label::class);
return $this->belongsTo(config('labels.label_class'));
}
}
43 changes: 43 additions & 0 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

use Rpungello\LaravelLabels\Enums\BarcodeType;
use Rpungello\LaravelLabels\Models\Label;
use Rpungello\LaravelLabels\Models\LabelBarcode;
use Rpungello\LaravelLabels\Models\LabelField;

it('loads correct model classes', function () {
$template = Label::factory()->create([
'page_width' => 215.9,
'page_height' => 279.4,
'horizontal_margin' => 4.8,
'vertical_margin' => 12.7,
'label_width' => 66.7,
'label_height' => 25.4,
'horizontal_spacing' => 2.9,
'vertical_spacing' => 0,
]);
$template->fields()->create([
'x_pos' => 0,
'y_pos' => 0,
'width' => 66.7,
'height' => 25.4,
'content' => '{value}',
]);
$template->barcodes()->create([
'x_pos' => 0,
'y_pos' => 0,
'width' => 66.7,
'height' => 25.4,
'type' => BarcodeType::OneDimensional,
'symbology' => 'C128',
'content' => '{value}',
]);

expect($template->fields)->toHaveCount(1)
->and($template->fields[0])->toBeInstanceOf(LabelField::class)
->and($template->fields[0]->label)->toBeInstanceOf(Label::class)
->and($template->barcodes)->toHaveCount(1)
->and($template->barcodes[0])->toBeInstanceOf(LabelBarcode::class)
->and($template->barcodes[0]->label)->toBeInstanceOf(Label::class);

});

0 comments on commit a4163a4

Please sign in to comment.