php - Saving/Updating User Profile in Laravel 5 -
php - Saving/Updating User Profile in Laravel 5 -
i can't seem save updated profile database.
in edit.blade.php:
{!! form::model($user, ['method' => 'patch', 'route' => ['profile.update', $user->company_name] ]) !!} // fields {!! form::submit('update profile', ['class' => 'btn btn-primary']) !!} {!! form::close() !!} in profilescontroller:
public function update($company_name) { $user = user::wherecompanyname($company_name)->firstorfail(); $user->save(); // no validation implemented flash('you have edited profile'); homecoming redirect('/'); } after hitting update button, shows flash message on homepage it's not saving database. im coming rails , sense need whitelist something.
the point is, don't alter user model @ all... retrive it, , save 1 time again without setting fields.
$user = user::wherecompanyname($company_name)->firstorfail(); // 'fills' user model fields of input fillable $user->fill(\input::all()); $user->save(); // no validation implemented if using above method
$user->fill(\input::all()); you have add together $fillable array user model like
protected $fillable = ['name', 'email', 'password']; // add together fields need if explicitly want set 1 or 2 ( or three....) field update them
$user->email = \input::get('email'); // email example.... $user->name = \input::get('name'); // example... ... $user->save(); if have tried anwer sinmok provided, "whooops" page because used
input::get('field'); instead of
\input::get('field'); on blade syntax assume utilize laravel 5. controller namespaced have add together \ before input reference root namespace ( or set utilize statement on top of class)
generally on development server should enable debugging. have more detailed info what's going wrong pure.. "whoops... "
in config/app.php file can set
'debug' => true; or
you have @ http://laravel.com/docs/5.0/configuration , utilize .env file.
if utilize .env file create sure there entry like
app_debug=true then can access value in config/app.php
'debug' => env('app_debug'), there should .env.example in installation give clue how such file like.
php laravel laravel-5
Comments
Post a Comment