Giter VIP home page Giter VIP logo

Comments (2)

CristianLlanos avatar CristianLlanos commented on May 18, 2024 1

One reason to keep them in the user models is because if you want to overide the fillable property you will need to completely replace all those fields in each model. Whereas if you have them in the user models, it does not matter. You can change them (delete or add one field) or completely delete them if you don't need them.

For instance, your proposed behaviour would be like the following:

class BaseUser extends Eloquent
{
    protected $fillable = ['firstName', 'lastName', 'password', 'gender'];
}

class User extends BaseUser
{
    protected $fillable = ['firstName', 'lastName', 'password'];
}

If I wanted to add another field to my fillable property, I would need to write all the other fields as well. That isn't convenient at all.

However, if we have those fillable attributes in the User class, it'll be so easy to add a new field to the fillable property.

/** First generated model **/
class User extends BaseUser
{
    protected $fillable = ['firstName', 'lastName', 'password'];
}

/** You'll just need to add another field and that's it **/
class User extends BaseUser
{
    protected $fillable = ['firstName', 'lastName', 'password', 'gender'];
}

Another reason not to have new fields automatically added to the fillable property is because it can be dangerous. Since all new database fields will be automatically a fillable attribute, you don't get to decide weather you actually want it to be fillable or not. Remember that the reason for having fillable attributes is to defend yourself from mass assignment. If every new field is mass assignable by default, you are potentially creating security vulnerabilities in your system without even being aware of it.

from laravel.

CristianLlanos avatar CristianLlanos commented on May 18, 2024

Perhaps an option to enable one feature or another would be fine. The safer one should be the default and putting the fillable property in base models would have to be manually enabled. What do you think? Seems reasonable to me 🤔 And I'm willing to accept this pull request if you would like to contribute :)

from laravel.

Related Issues (20)

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.