Skip to content

The Dynamic Update Trait for Laravel provides a convenient way to dynamically update model attributes using magic methods.

License

Notifications You must be signed in to change notification settings

shahsawoodshinwari/dynamic-update-trait

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Dynamic Update Trait

The Dynamic Update Trait for Laravel provides a convenient way to dynamically update model attributes using magic methods. This trait allows you to update individual model attributes without explicitly defining setter methods for each attribute. It simplifies the process of updating model fields by providing a generic update method that can be called with dynamic method names.

Installation

You can install the package via Composer:

composer require shaka/dynamic-update-trait

Usage

To use the Dynamic Update Trait, simply use it in your Eloquent model:

<?php
 
namespace App\Models;
 
use Illuminate\Database\Eloquent\Model;
use Shaka\DynamicUpdateTrait\Traits\DynamicUpdateTrait;


class User extends Model
{
  use DynamicUpdateTrait;
}

You can then update model attributes dynamically:

$model = User::find(1);
$model->updateName('Shah Sawood'); // name field will be updated 
$model->updateEmail('shahsawoodshinwari@gmail.com'); // email field will be updated

Additional Information

The package expects the fields to be updated are in snake_case.

Contributing

Contributions are welcome! Feel free to submit pull requests or open issues to improve the package.

License

The Dynamic Update Trait for Laravel is open-sourced software licensed under the MIT license.

About

The Dynamic Update Trait for Laravel provides a convenient way to dynamically update model attributes using magic methods.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages