Skip to content

Commit 0fc9604

Browse files
authored
Merge pull request #30 from cgiupponi/improve-documentation
Update installation.md
2 parents 22692db + db3d028 commit 0fc9604

File tree

1 file changed

+46
-3
lines changed

1 file changed

+46
-3
lines changed

docs/getting-started/installation.md

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,48 @@ Install @zeus Qr by running the following commands in your Laravel project direc
1111
composer require lara-zeus/qr
1212
```
1313

14+
## Migration
15+
16+
Make sure to edit your resource migration to add the required columns.
17+
The main one will be the same as your component; in the example below, it is set as `qr_code`.
18+
If you want to store the personalization, another column is required; in the example, it is `options`.
19+
20+
```php
21+
Schema::create('ticket_replies', function (Blueprint $table) {
22+
// other columns
23+
$table->string('qr_code');
24+
$table->text('options');
25+
// other columns
26+
});
27+
```
28+
29+
## Cast
30+
31+
The personalizations are stored as string but the component will use it as array so you need to tell to your model to cast it as array.
32+
33+
```php
34+
class QrCode extends Model
35+
{
36+
use HasFactory;
37+
38+
protected $casts = [
39+
'options' => 'array'
40+
];
41+
}
42+
```
43+
1444
## Usage:
1545

1646
use it in your resource
1747

1848
```php
1949
\LaraZeus\Qr\Components\Qr::make('qr_code')
20-
// to open the designer as slide over instead of a modal
50+
// to open the designer as slide over instead of a modal.
51+
// Comment it out if you prefer the modal.
2152
->asSlideOver()
2253

23-
//you can set the column you want to save the QR design options, you must cast it to array in your model
24-
->optionsColumn('string')
54+
// you can set the column you want to save the QR design options, you must cast it to array in your model
55+
->optionsColumn('options')
2556

2657
// set the icon for the QR action
2758
->actionIcon('heroicon-s-building-library')
@@ -64,6 +95,18 @@ PopoverEntry::make('name')
6495
->content(\LaraZeus\Qr\Facades\Qr::render(data:'dataOrUrl')),
6596
```
6697

98+
If you just want to print the QrCode in the InfoList you can use TextEntry with `formatStateUsing` method and pass the state and the $record as params.
99+
100+
```php
101+
TextEntry::make('qr_code')
102+
->formatStateUsing(function (string $state, $record) {
103+
return \LaraZeus\Qr\Facades\Qr::render(
104+
data: $state,
105+
options: $record->options // This is your model. We are passing the personalizations. If you want the default just comment it out.
106+
);
107+
}),
108+
```
109+
67110
### Usage with any action
68111

69112
to use the QR code as an action in anywhere you want:

0 commit comments

Comments
 (0)