zoparga/laravel-company-information

Add many address to many model with a single trait. E.g.: many shipping address for a customer.

0.8.1 2022-04-27 13:26 UTC

This package is auto-updated.

Last update: 2024-10-27 18:45:55 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Installation

You can install the package via composer:

composer require zoparga/laravel-company-information

You can publish and run the migrations with:

php artisan vendor:publish --provider="zoparga\CompanyInformation\CompanyInformationServiceProvider" --tag="company-information-migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --provider="zoparga\CompanyInformation\CompanyInformationServiceProvider" --tag="laravel-company-information-config"

This is the contents of the published config file:

Usage

  • publish migration file
  • migrate
  • add trait to model
  • use it

Prepare model

use zoparga\CompanyInformation\Traits\CompanyInformationeableTrait;

class {{model}} extends Model { use CompanyInformationeableTrait; }

$model = \App\Models\Model::find(1);

$model->companyInformations()->create([
    'full_name' => 'YOUR INFORMATION',
    'main_address' => 'YOUR INFORMATION',
    'bank_bic' => 'YOUR INFORMATION',
    'bank_iban' => 'YOUR INFORMATION',
    'vat' => 'YOUR INFORMATION',
]);

$companyInformationId = 1;

$model->updateCompanyInformation($companyInformationId, [
    'full_name' => 'YOUR INFORMATION',
    'main_address' => 'YOUR INFORMATION',
    'bank_bic' => 'YOUR INFORMATION',
    'bank_iban' => 'YOUR INFORMATION',
    'vat' => 'YOUR INFORMATION',
]);

Get the addresses, order by ID - desc
Or you can limit it here
$model->getLatestCompanyInformationes()->get();

Or you can limit it here
$model->getLatestCompanyInformationes()->limit(3)->get();

Of course you can get last created address
$model->getLastCompanyInformation();

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.