Skip to content

Instantly share code, notes, and snippets.

@RyanNielson
Last active August 29, 2015 14:06
Show Gist options
  • Save RyanNielson/4f5b0157ab8c50319488 to your computer and use it in GitHub Desktop.
Save RyanNielson/4f5b0157ab8c50319488 to your computer and use it in GitHub Desktop.
Idea for multiple fillable options

This is a suggestion to improve fillable to make it easier to assign multiple values for fillable. This would be useful if a site had different roles, for example if an admin can edit things a user cannot.

To implement this it should just be a matter of a few changes by adding an extra parameter to a few methods for the fillable key, and passing this along when fillable is checked to check against the correct array.

Below is an example of what using this feature would look like.

// In model
class User extends Eloquent
{
protected $fillable = [
'default' => ['name', 'email'],
'admin' => ['name', 'email', 'role']
];
}
// When creating a model you can now do the following to control which "fillable" is used for mass assignment protection
User::create(Input::all(), 'default');
User::create(Input::all(), 'admin');
User::fill(Input::all(), 'admin');
// Perhaps the following also defaults to the "default" key.
User::create(Input::all());
// To implement this it should just be a matter of a few changes by adding an extra parameter to a few methods for the fillable key, and passing this along when fillable is checked to check against the correct array.
// If they choose to use old style fillable (single array), and don't pass a key, we'll just check if the default key exists, if it doesn't we'll treat fillable as a single dimensional array and do as before.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment