Skip to content

Instantly share code, notes, and snippets.

@Sarav-S
Last active September 23, 2016 02:52
Show Gist options
  • Save Sarav-S/1d028bce8370a52d6316566d1601d812 to your computer and use it in GitHub Desktop.
Save Sarav-S/1d028bce8370a52d6316566d1601d812 to your computer and use it in GitHub Desktop.
<?php
private function save($request, $user = null) {
$status = "update";
if (! $user) {
$user = new User;
$status = "create";
}
$user->name = $request->input('name');
$user->email = $request->input('email');
if ($request->has('password')) {
$user->password = bcrypt($request->input('password'));
}
if ($user->save()) {
session()->flash('status', 'User '.$status.'d successfully');
return redirect(route('users'));
}
session()->flash('status', 'Unable to '.$status.' user. Please try again');
return back()->withInput();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment