Code Monkey home page Code Monkey logo

laravel-update-fillable's Introduction

Laravel Update Fillable

Laravel Update Fillable is a command-line tool that updates the $fillable property of Eloquent models based on the current database schema.

Installation

Install the package via Composer:

composer require jrbarros/laravel-update-fillable --dev

Usage

To update the $fillable property of all Eloquent models in your project:

php artisan update:fillable

To update the $fillable property of a specific Eloquent model:

php artisan update:fillable ModelName

To update the $fillable property of all Eloquent models in a specific directory (e.g. app/Models):

php artisan update:fillable --directories=app/Models

To exclude certain columns from the $fillable property:

php artisan update:fillable --exclude=id,created_at,updated_at

To write the changes to the model files:

php artisan update:fillable --write

To specify the path to your project:

php artisan update:fillable --path=/path/to/project

Options

The following options are available:

  • --write: Write changes to the model files (default: false)
  • --exclude: Comma-separated list of column names to exclude from the fillable property (default: "id")
  • --path: The path to the project (default: base_path())
  • --directories: Comma-separated list of directories where the models are located (default: "app") model: The name of a specific model to update (optional)

Customization

You can customize the behavior of the package by creating a nonFillable property in your model classes. This property should be an array of column names that should be excluded from the fillable property:

class User extends Model
{
    protected $nonFillable = ['password'];
    protected $fillable = ['name', 'email'];
}

TODO

  • Remove migration, model e config and use what you need to test us, creating less useless code
  • Clean existing tests and create more
  • Refactor any function and check compatibility with older versions of laravel

License

Laravel Update Fillable is open-sourced software licensed under the MIT license.

laravel-update-fillable's People

Contributors

freekmurze avatar mvdnbrk avatar jrbarros avatar pforret avatar sebastiandedeyne avatar dependabot[bot] avatar nielsvanpach avatar github-actions[bot] avatar adrianmrn avatar alexvanderbist avatar riasvdv avatar patinthehat avatar irfanm96 avatar crynobone avatar igedeon avatar jessarcher avatar sixlive avatar willemvb avatar abenerd avatar koossaayy avatar yaroslawww avatar medilies avatar narcisonunez avatar erikn69 avatar bvtterfly avatar thecaliskan avatar olumby avatar brendt avatar gizburdt avatar jeroenboumans avatar

Stargazers

AndreGartner avatar Dayvison Marley Nunes Silva avatar Elvio A. Amaral avatar Fernando "ferox" dos Santos avatar  avatar Rodrigo Cabral avatar Vitor Cordeiro avatar Douglas Cardoso avatar

Watchers

 avatar

laravel-update-fillable's Issues

[Bug]: It tries to add a $hidden to $fillable

What happened?

If you have a filed in $hidden, then it suggest that it will be added to $fillable

How to reproduce the bug

php artisan update:fillable

normally User model have the 'remember_token' in the $hidden, but this command tries to add it to the $fillable

Package Version

0.0.4

PHP Version

8.3.2

Laravel Version

10.43.0

Which operating systems does with happen with?

macOS

Notes

No response

[Bug]: Class "App\Models\Traits\Arr" does not exist

What happened?

Installed and executed

php artisan update:fillable
 ReflectionException 

  Class "App\Models\Traits\Arr" does not exist

  at vendor/jrbarros/laravel-update-fillable/src/LaravelUpdateFillableUpdater.php:298
    294▕                 if (! $className) {
    295▕                     continue;
    296▕                 }
    297▕ 
  ➜ 298▕                 $reflection = new ReflectionClass($className);
    299▕ 
    300▕                 if ($reflection->isSubclassOf(Model::class) && ! $reflection->isAbstract()) {
    301▕                     $models[] = $className;
    302▕                 }

      +15 vendor frames 

  16  artisan:35
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))


How to reproduce the bug

Install and execute

Package Version

0.0.4

PHP Version

8.3.2

Laravel Version

10.43.0

Which operating systems does with happen with?

macOS

Notes

I have a Traits folder in my Models folder, but all references to Arr is solved with a

use

I added this:

try {
                    $reflection = new ReflectionClass($className);

                    if ($reflection->isSubclassOf(Model::class) && ! $reflection->isAbstract()) {
                        $models[] = $className;
                    }

                }
                catch (\ReflectionException $exception)
                {
                    Log::error($className);
                }

not sure why this package tries to process

 App\Models\Traits\Arr  

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.