Support the ongoing development of Laravel.io →
posted 7 years ago
Eloquent
Last updated 2 years ago.
0

Not sure why you did all of this. You just had to set fillable.

0

@lagbox : i don't know what you mean by all of this ..!!

i already set the fillable and everything was normal and this problem suddenly happened after i made the Accessors ..

all of this to explain the situation and make the problem obvious to you ..

you can read what i did again , and you will see that everything is normal, but i don't know what cause the problem ..

and this is some dd() test :

  • in the createUser method in the User model i dd() the userData variable :
array:9 [
  "email" => "[email protected]"
  "password" => "123456"
  "phone" => "0321561235"
  "name" => "ryan"
  "api_token" => "Q3kphRxwQzcdah55yZUS9Ip6Vjt8qi09EkgrlDaRTd8jpYLGwOpqhANcW5Ce"
  "status" => 1
  "dashboard_access" => 0
  "role" => "member"
]
  • and i dd() the fillable attributes of a new instance of the User model :
array:16 [
  0 => "name"
  1 => "email"
  2 => "password"
  3 => "img"
  4 => "gender"
  5 => "phone"
  6 => "address_ar"
  7 => "address_en"
  8 => "address_coordinates"
  9 => "role"
  10 => "dashboard_access"
  11 => "status"
  12 => "confirmed"
  13 => "confirmation_code"
  14 => "api_token"
  15 => "membership_id"
]
0

@lagbox :

in my User model i made a construct to make dynamically hidden attributes :

and when i comment this construct, it worked again .. but idk why this cause this problem :

public function __construct()
    {
        // to hide unused properties in the returned josn api.
        if(request()->segment(1) == 'api'){
            $this->addHidden(['membership_allowed_days']);
        }
        
    }
0

@lagbox : it solved now as i should call the parent construct in User construct to not override the existing mass assignment attributes :)

like this :

    public function __construct($attributes = [])
    {
        // To not override the existing mass assignment attributes
        parent::__construct($attributes);
        
        // to hide unused properties in the returned josn api.
        if(request()->segment(1) == 'api'){
            $this->addHidden(['membership_allowed_days']);
        }
    }
0

Sign in to participate in this thread!

Eventy

Your banner here too?

reyoryan reyoryan Joined 26 Apr 2017

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.