You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$invoice->buyer()->associate($customer); // optionnally associate the invoice to any model
720
728
$invoice->invoiceable()->associate($order); // optionnally associate the invoice to any model
@@ -758,11 +766,12 @@ When creating an invoice, you can dynamically specify the prefix and series with
758
766
759
767
```php
760
768
use Elegantly\Invoices\Models\Invoice;
769
+
761
770
$invoice = new Invoice();
762
771
763
772
$invoice->configureSerialNumber(
764
773
prefix: "ORG",
765
-
serie: $buyer_id,
774
+
serie: $buyerId,
766
775
);
767
776
```
768
777
@@ -775,6 +784,7 @@ The format you choose will determine the types of information you need to provid
775
784
Below is an example of the most complex serial number format you can create with this package:
776
785
777
786
```php
787
+
use Elegantly\Invoices\Models\Invoice;
778
788
779
789
$invoice = new Invoice();
780
790
@@ -791,6 +801,50 @@ $invoice->save();
791
801
$invoice->serial_number; // IN-000100-24010001
792
802
```
793
803
804
+
### Storing the Logo
805
+
806
+
By default, the PDF logo is loaded from the configuration defined in your config file.
807
+
808
+
If you want the logo to remain consistent over time, even if the config changes, you can store it directly in the database:
809
+
810
+
```php
811
+
use Elegantly\Invoices\Models\Invoice;
812
+
813
+
$invoice = new Invoice();
814
+
815
+
// Store the current config logo in the database
816
+
$invoice->setLogoFromConfig();
817
+
818
+
// ...
819
+
820
+
$invoice->save();
821
+
```
822
+
823
+
### Storing a Dynamic Logo
824
+
825
+
If your application allows users to upload or select their own company logos, you can dynamically set the logo on each invoice by updating the `logo` attribute on the `Invoice` model.
826
+
827
+
You can do this in several ways:
828
+
829
+
```php
830
+
use Elegantly\Invoices\Models\Invoice;
831
+
832
+
$invoice = new Invoice();
833
+
834
+
// Set the logo from an uploaded file (e.g., Illuminate\Http\UploadedFile)
835
+
$invoice->setLogoFromFile($file);
836
+
837
+
// Set the logo from a local filesystem path
838
+
$invoice->setLogoFromPath($path);
839
+
840
+
// Set the logo directly from raw file content (string or binary data)
841
+
$invoice->logo = $rawFileContent;
842
+
843
+
// ...
844
+
845
+
$invoice->save();
846
+
```
847
+
794
848
### Converting an `Invoice` Model to a `PdfInvoice`
795
849
796
850
You can obtained a `PdfInvoice` class from your `Invoice` model by calling the `toPdfInvoice` method:
@@ -907,7 +961,7 @@ class PaymentInvoice extends Notification implements ShouldQueue
907
961
public function toMail($notifiable)
908
962
{
909
963
return (new MailMessage)
910
-
->attach($this->invoice->toMailAttachment());
964
+
->attach($this->invoice);
911
965
}
912
966
}
913
967
```
@@ -1117,68 +1171,6 @@ return [
1117
1171
];
1118
1172
```
1119
1173
1120
-
### Using a Dynamic Logo
1121
-
1122
-
In scenarios where the invoice logo needs to be set dynamically (for instance, allowing users to upload their own company logo), you can achieve this by overriding the `getLogo` method in your `Invoice` model.
1123
-
1124
-
Follow these steps:
1125
-
1126
-
1.**Create a Custom `Invoice` Model**:
1127
-
1128
-
Define your own `App\Models\Invoice` that extends `\Elegantly\Invoices\Models\Invoice` class.
1129
-
Inside this custom model, implement the `getLogo` method to return the path or data for your dynamic logo.
1130
-
1131
-
> [!NOTE]
1132
-
> The `getLogo` method must return either a base64-encoded data URL (e.g., `data:image/png;base64,...`) or a local filesystem path to the logo image.
1133
-
1134
-
Here's an example of how you might implement this:
1135
-
1136
-
```php
1137
-
namespace App\Models;
1138
-
1139
-
use Illuminate\Http\File;
1140
-
1141
-
class Invoice extends \Elegantly\Invoices\Models\Invoice
1142
-
{
1143
-
public function getLogo(): ?string
1144
-
{
1145
-
$logoPath = public_path('logo.png'); // Replace with your dynamic logic
1146
-
1147
-
if (!file_exists($logoPath)) {
1148
-
return null; // Or a default logo
1149
-
}
1150
-
1151
-
$file = new File($logoPath);
1152
-
$mime = $file->getMimeType();
1153
-
$logoData = "data:{$mime};base64," . base64_encode(file_get_contents($logoPath)); // Use file_get_contents for raw data
1154
-
1155
-
return $logoData;
1156
-
}
1157
-
}
1158
-
```
1159
-
1160
-
2.**Publish Package Configuration**:
1161
-
1162
-
If you haven't done so already, publish the package's configuration file:
0 commit comments