php - laravel default image not working -


i new laravel , im facing problem:

i have code in registercontroller:

 protected function create(array $data) {     $pic_path="";     if($data['gender'] =='male'){         $pic_path = 'http://localhost:8000/img/profile-default-male.png';     }else if($data['gender'] =='female'){         $pic_path='http://localhost:8000/img/default_women.jpg';     }     return user::create([          'name' => $data['name'],             'pic' => $pic_path,         'gender' => $data['gender'],         'slug' => str_slug($data['name'],'-'),         'email' => $data['email'],         'password' => bcrypt($data['password']),     ]); } 

but in register.blade.php: have this

   <img src="{{asset('/img/default_women.jpg')}}" width="80px" height="80px"> 

i know have put this:auth::user()->pic inside img src tried lot , not working

also got error:

sqlstate[hy000]: general error: 1364 field 'pic' doesn't have default value (sql: insert `users` (`name`, `gender`, `slug`, `email`, `password`, `updated_at`, `created_at`) values (w, female, w, w@w.com, $2y$10$xcgyva2xcgbcttgvbsk2n.haz4vjt2mmlsmj5fxx80bzqvpfhrili, 2017-09-12 00:49:41, 2017-09-12 00:49:41)) 

so appreciated thank you

laravel protects against mass assignment vulnerabilities limiting fields can mass assign.

you'll need add pic attribute $fillable attribute in user model:

class user extends model {     protected $fillable = [         ..., 'pic' //ensure pic in array     ]; } 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -