netcore
4 years ago

Create data without having column in $fillable

Posted 4 years ago by netcore

Hello

How can I use Model::create() to insert data without having fillable column?

For example, table structure

data
    - name
    - level

In model (look, i have't added level in fillable array)

/* ... */
protected $fillable = [ 'name' ];
/* ... */

Controller

public function process (  Request $request ) {
    
    /*
    data given in request:
    'name' => 'something'
    */

    $data = $request->all();
    $data['level'] = 5,     
    Model::create ($data);
}

when create method is issued, level is not inserted, because i don't have added it to fillable

If i will add it to fillable, users will be able to inspect-element my frontend code to add level manally.

How to fix this?

Please sign in or create an account to participate in this conversation.