Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to the $fillable array in the eloquent classes. #31

Open
phiter opened this issue Dec 19, 2017 · 4 comments
Open

Add support to the $fillable array in the eloquent classes. #31

phiter opened this issue Dec 19, 2017 · 4 comments
Milestone

Comments

@phiter
Copy link

phiter commented Dec 19, 2017

The $fillable array defines what columns in a model can be filled trough mass assignment.

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Flight extends Model
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['name'];
}

It'd allow us to use this function:

$flight = App\Flight::create(['name' => 'Flight 10']);

Or this one if the model is already defined:

$flight->fill(['name' => 'Flight 22']);

Could you add inspection for this array, and maybe typehint the expected type on the fill and create methods based on annotated column type?

Thanks!

@rentalhost rentalhost added this to the 1.0.0+ milestone Dec 19, 2017
@rentalhost
Copy link
Owner

Thanks. I have added to 1.0.0+ milestone, but it doesn't mean that will be a very future feature. Is just a control milestone.

@rentalhost
Copy link
Owner

It should works like:

$fillable = [
    'name',
    'age'
];

App\User::create([
    'name' => 'John',
    'age' => 18,
    'title' => 'Commander', 
        // Warn: property $title was not declared as $fillable.
        // Quick-fix: add $title to $fillable array.
]);

@phiter
Copy link
Author

phiter commented Dec 19, 2017

I'd add this too if possible/necessary:

/* @property int $age */

$fillable = [
    'name',
    'age'
];

App\User::create([
    'name' => 'John',
    'age' => "18", // Warning: expected type is integer, string given.
]);

@rentalhost
Copy link
Owner

Uhh... I don't know if it is possible, but I can try. Could you please create another issue for that? Just fill title and put a reference to your previous comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants