I've managed to retrieve and display the Auth user profile details in my profile view, but I'm missing something (or a few things) to do the actual update.
Can you help?
profile.blade.view
<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="panel panel-default">
<div class="panel-heading">Update your user profile</div>
<div class="panel-body">
{!! Form::open(array('action' => array('HomeController@postProfileEdit', $user->id))) !!}
<div class="form-group">
{!! Form::label('firstName', 'First name:') !!}
{!! Form::text('firstName', $userinfo->first_name, ['class' => 'form-control']) !!}
{!! Form::label('lastName', 'Last name:') !!}
{!! Form::text('lastName', $userinfo->last_name, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::submit('Update', ['class'=>'btn primary']) !!}
</div>
{!! Form::close() !!}
</div>
</div>
</div>
</div>
routes.php
Route::get('profile', 'HomeController@profile');
Route::post('profile', 'HomeController@postProfileEdit');
HomeController.php - profile()
/**
* Show the application user profile to the user.
*
* @return Response
*/
public function profile()
{
$user = Auth::user();
$userinfo = \Auth::user();
return view('profile')->with(['user' => $user])->with('userinfo', $userinfo);
}
HomeController.php - postProfileEdit(Request $request)
/**
* Store updates to user profile.
*
* @return Response
*/
public function postProfileEdit(Request $request)
{
$userinfo = Request::all();
$user = new User;
$user->exists = true;
$user->id = Auth::user();
$user->first_name = $userinfo['firstName'];
$user->save();
return redirect()->action('HomeController@profile');
//return Response::make('Your user profile was updated successfully!');
}
requests.php - for validation
abstract class Request extends FormRequest {
/**
* The URI to redirect to if validation fails
*
* @var string
*/
protected $redirect = 'users/create';
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'firstName' => 'required|min:3',
'lastName' => 'required|min:3'
];
}
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return false;
}
}
I'm getting:
FatalErrorException in HomeController.php line 170: Class 'App\Http\Controllers\updateProfile' not found
I know the $updateProfile = new updateProfile;
line is wrong, I'm just not sure what is wrong.
Hope this makes sense.
Update:
I changed the class from updateProfile to User (name of the model where I'm doing the change) in HomeController.php
Now I get the following message:
ErrorException in HomeController.php line 174: Undefined variable: userinfo
I'm not sure I can use userinfo from profile.blade.view (see above).
Update
I was able to make it work (or not get an error) by fixing HomeController@postProfileEdit (post), and return to HomeController@profile (get) when done. But apparently, the save did not get done because even though I changed the first_name value, it stays the same when I go back to HomeController@profile (where first_name is retrieved and displayed).