-
-
Save BenSeward/f6b1d800ac1f8ab90dad86387d09d7a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use Illuminate\Http\Request; | |
use App\User; | |
use App\Http\Requests; | |
use Illuminate\Support\Facades\Auth; | |
class AccountController extends Controller | |
{ | |
/** | |
* Display a listing of the resource. | |
* | |
* @return \Illuminate\Http\Response | |
*/ | |
public function index() | |
{ | |
// | |
return view('Account.index'); | |
} | |
/** | |
* Show the form for creating a new resource. | |
* | |
* @return \Illuminate\Http\Response | |
*/ | |
public function create() | |
{ | |
// | |
} | |
/** | |
* Store a newly created resource in storage. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @return \Illuminate\Http\Response | |
*/ | |
public function store(Request $request) | |
{ | |
// | |
} | |
/** | |
* Display the specified resource. | |
* | |
* @param int $id | |
* @return \Illuminate\Http\Response | |
*/ | |
public function show($id) | |
{ | |
// | |
} | |
/** | |
* Show the form for editing the specified resource. | |
* | |
* @param int $id | |
* @return \Illuminate\Http\Response | |
*/ | |
public function edit($id) | |
{ | |
// | |
} | |
/** | |
* Update the specified resource in storage. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param int $id | |
* @return \Illuminate\Http\Response | |
*/ | |
public function update(Request $request) | |
{ | |
$this->validate($request, [ | |
'name' => '', | |
'email' => '', | |
'telephone' => '', | |
'job_title' => '', | |
'profile_description' => '', | |
'education' => '', | |
]); | |
User::find(Auth::user()->id)->update([ | |
'name' => $request->get('name'), | |
'email' => $request->get('email'), | |
'telephone' => $request->get('telephone'), | |
'job_title' => $request->get('job_title'), | |
'profile_picture' => $request->get('profile_picture'), | |
'profile_description' => $request->get('profile_description'), | |
'education' => $request->get('education'), | |
]); | |
$userImage = User::find(Auth::user()->id); | |
if (!empty($request->file('profile_picture')) && $request->file('profile_picture')->isValid()) { | |
$fileName = md5(time() . pathinfo($request->file('profile_picture')->getClientOriginalName(), PATHINFO_FILENAME)) . '.' . pathinfo($request->file('profile_picture')->getClientOriginalName(), PATHINFO_EXTENSION); | |
$request->file('profile_picture')->move('profile-pictures', $fileName); | |
$userImage->update([ | |
'profile_picture' => $fileName, | |
]); | |
} else { | |
$fileName = $request->get('old-image'); | |
} | |
$userImage->update([ | |
'profile_picture' => $fileName, | |
]); | |
} | |
/** | |
* Remove the specified resource from storage. | |
* | |
* @param int $id | |
* @return \Illuminate\Http\Response | |
*/ | |
public function destroy($id) | |
{ | |
// | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
$(document).ready(function(){ | |
$('#account-update').on('submit', function(e) { | |
e.preventDefault(); | |
var formData = new FormData(); | |
// other inputs | |
//append some non-form data also | |
formData.append('name',$('input[name=name]').val()), | |
formData.append('_token',$('input[name=_token]').val()), | |
$.ajax({ | |
type: "POST", | |
url: '{{ url('account.update', auth()->user()->id) }}', | |
data: formData, | |
processData: false, | |
contentType: false, | |
dataType: "json", | |
success: function(data, textStatus, jqXHR) { | |
//process data | |
}, | |
error: function(data, textStatus, jqXHR) { | |
//process error msg | |
}, | |
}); | |
}); | |
}); | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form class="form-horizontal" id="account-update" role="form" method="POST" action="{{ url('account.update', auth()->user()->id) }}" enctype="multipart/form-data"> | |
{{ csrf_field() }} | |
<div class="form-group"> | |
<label for="name" class="col-sm-2 control-label">Name</label> | |
<div class="col-sm-10"> | |
<input name="name" type="text" class="form-control" id="name" placeholder="Name"> | |
</div> | |
</div> | |
<div class="form-group"> | |
<label for="email" class="col-sm-2 control-label">Email</label> | |
<div class="col-sm-10"> | |
<input name="email" type="email" class="form-control" id="email" placeholder="Email"> | |
</div> | |
</div> | |
<div class="form-group"> | |
<label for="telephone" class="col-sm-2 control-label">Contact Number</label> | |
<div class="col-sm-10"> | |
<input name="telephone" type="telephone" class="form-control" id="telephone" placeholder="+(44)754 5635 950"> | |
</div> | |
</div> | |
<div class="form-group"> | |
<label for="job_title" class="col-sm-2 control-label">Job Description</label> | |
<div class="col-sm-10"> | |
<input name="job_title" type="text" class="form-control" id="job_title" placeholder="Web Developer"> | |
</div> | |
</div> | |
<div class="form-group"> | |
<label for="profile_description" class="col-sm-2 control-label">About Me</label> | |
<div class="col-sm-10"> | |
<textarea name="profile_description" class="form-control" id="profile_description" placeholder="Tell us about yourself..."></textarea> | |
</div> | |
</div> | |
<div class="form-group"> | |
<label for="education" class="col-sm-2 control-label">Education</label> | |
<div class="col-sm-10"> | |
<input name="education" type="text" class="form-control" id="education"> | |
</div> | |
</div> | |
<div class="form-group"> | |
<label for="profile_picture" class="col-sm-2 control-label">Profile Picture</label> | |
<div class="col-sm-10"> | |
<input name="profile_picture" type="file" class="form-control" id="profile_picture"> | |
</div> | |
</div> | |
<div class="form-group"> | |
<div class="col-sm-offset-2 col-sm-10"> | |
<button type="submit" class="btn send-btn">Submit</button> | |
</div> | |
</div> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment