Looking to hire Laravel developers? Try LaraJobs

laravel-contact-information maintained by zoparga

Description
Add many address to many model with a single trait. E.g.: many shipping address for a customer.
Author
Last update
2022/04/27 15:26 (dev-main)
License
Downloads
12

Comments
comments powered by Disqus

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

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-contact-information

You can publish and run the migrations with:

php artisan vendor:publish --provider="zoparga\ContactInformation\ContactInformationServiceProvider" --tag="contact-information-migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --provider="zoparga\ContactInformation\ContactInformationServiceProvider" --tag="laravel-contact-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\ContactInformation\Traits\ContactInformationeableTrait;

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


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

$model->contactInformations()->create([
    'type' => 'phone',
    'information' => '+361123123',
    'primary' => 1,
]);

$model->contactInformations()->create([
    'type' => 'web',
    'information' => 'info.xyz',
    'primary' => 1,
]);

$contactInformationId = 1;

$model->updateContactInformation($contactInformationId, [
    'type' => 'phone',
    'information' => '+361123123',
    'primary' => 0,
]);


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

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

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


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.