diff --git a/app/Models/Customer.php b/app/Models/Customer.php index ccbcac7..eb26fb1 100644 --- a/app/Models/Customer.php +++ b/app/Models/Customer.php @@ -29,12 +29,34 @@ class Customer extends Model */ protected $appends = [ 'created', + 'street', + 'city' ]; + /** + * Deliver the customer's address as street directly with the model. + */ + public function getStreetAttribute(): string + { + if (is_null($this->address)) { + return ''; + } + return $this->address->address; + } + + /** + * Deliver the customer's address as city directly with the model. + */ + public function getCityAttribute(): string + { + if (is_null($this->address)) { + return ''; + } + return $this->address->city; + } + /** * Get the created_at attribute in local time format. - * - * @return string */ public function getCreatedAttribute(): string { @@ -43,8 +65,6 @@ class Customer extends Model /** * Get the invoice address. - * - * @return HasOne */ public function address(): HasOne { @@ -56,8 +76,6 @@ class Customer extends Model /** * Get the delivery address. - * - * @return HasOne */ public function delivery(): HasOne { @@ -69,8 +87,6 @@ class Customer extends Model /** * Get all customer's addresses. - * - * @return HasMany */ public function addresses(): HasMany { diff --git a/database/migrations/2024_11_25_162738_create_invoices_table.php b/database/migrations/2024_11_25_162738_create_invoices_table.php index d54e396..a92682c 100644 --- a/database/migrations/2024_11_25_162738_create_invoices_table.php +++ b/database/migrations/2024_11_25_162738_create_invoices_table.php @@ -16,7 +16,7 @@ return new class extends Migration $table->foreignId('user_id')->constrained(); $table->foreignId('customer_id')->constrained(); $table->foreignId('address_id')->constrained(); - $table->foreignId('delivery_id')->references('id')->on('addresses'); + $table->foreignId('delivery_id')->nullable()->references('id')->on('addresses'); $table->string('invoice_number'); $table->string('type'); // Map to external formats diff --git a/lang/de/invoice.php b/lang/de/invoice.php index c73596f..7d986b8 100644 --- a/lang/de/invoice.php +++ b/lang/de/invoice.php @@ -21,7 +21,8 @@ return [ 'Select customer' => 'Kunde auswählen', 'Select address' => 'Adresse auswählen', 'Search customer' => 'Kunden suchen', - 'Select your customer and address' => 'Wähle einen Kunden und seine Adresse aus', + 'Select your customer and address' => 'Wähle einen Kunden und seine Adresse aus.', + 'Select your customer\'s address' =>'Wähle die Adresse des Kunden aus.', 'Invoice item' => 'Rechnungsposition', 'Invoice items' => 'Rechnungspositionen', 'Amount' => 'Menge', diff --git a/resources/views/invoice/create.blade.php b/resources/views/invoice/create.blade.php index c0c2121..d77128d 100644 --- a/resources/views/invoice/create.blade.php +++ b/resources/views/invoice/create.blade.php @@ -9,8 +9,7 @@
- {{ __("invoice.Select your customer and address") }} + {{ __("invoice.Select your customer's address") }}