-
resources/views/frontend/users/profileEdit.blade.php
Open in GitHub// {{ html()->modelForm($userprofile, 'PATCH', route('frontend.users.profileUpdate', $$module_name_singular->id))->class('form-horizontal')->acceptsFiles()->open() }} <div class="form-group row"> {{ html()->label(__('labels.backend.users.fields.avatar'))->class('col-md-2 form-control-label')->for('name') }} <div class="col-md-5"> <img src="{{asset($user->avatar)}}" class="user-profile-image img-fluid img-thumbnail" style="max-height:200px; max-width:200px;" /> </div> <div class="col-md-5"> <div class="form-group"> <label for="file-multiple-input">Click here to update photo</label> <input id="file-multiple-input" name="avatar" multiple="" type="file" class="form-control-file"> </div> </div> </div> <div class="row"> <div class="col-md-6"> <div class="form-group"> <?php $field_name = 'first_name'; $field_lable = label_case($field_name); $field_placeholder = $field_lable; $required = "required"; ?> {{ html()->label($field_lable, $field_name) }} {!! fielf_required($required) !!} {{ html()->text($field_name)->placeholder($field_placeholder)->class('form-control')->attributes(["$required"]) }} </div> </div> <div class="col-md-6"> <div class="form-group"> <?php $field_name = 'last_name'; $field_lable = label_case($field_name); $field_placeholder = $field_lable; $required = "required"; ?> {{ html()->label($field_lable, $field_name) }} {!! fielf_required($required) !!} {{ html()->text($field_name)->placeholder($field_placeholder)->class('form-control')->attributes(["$required"]) }} </div> </div> <div class="col-md-6"> <div class="form-group"> <?php $field_name = 'email'; $field_lable = label_case($field_name); $field_placeholder = $field_lable; $required = ""; ?> {{ html()->label($field_lable, $field_name) }} {!! fielf_required($required) !!} {{ html()->email($field_name)->placeholder($field_placeholder)->class('form-control')->attributes(["$required"])->disabled() }} </div> </div> <div class="col-md-6"> <div class="form-group"> <?php $field_name = 'mobile'; $field_lable = label_case($field_name); $field_placeholder = $field_lable; $required = ""; ?> {{ html()->label($field_lable, $field_name) }} {!! fielf_required($required) !!} {{ html()->text($field_name)->placeholder($field_placeholder)->class('form-control')->attributes(["$required"]) }} </div> </div> </div> <div class="row"> <div class="col-sm-6"> <div class="form-group"> <?php $field_name = 'date_of_birth'; $field_lable = label_case($field_name); $field_placeholder = $field_lable; $value = ($userprofile->$field_name != "")? $userprofile->$field_name->toDateString() : ""; $required = "required"; ?> {{ html()->label($field_lable, $field_name) }} {!! fielf_required($required) !!} {{ html()->text($field_name)->placeholder($field_placeholder)->class('form-control')->value($value)->attributes(["$required", 'type'=>'date']) }} </div> </div> <div class="col-sm-6"> <div class="form-group"> <?php $field_name = 'gender'; $field_lable = label_case($field_name); $field_placeholder = "-- Select an option --"; $required = ""; $select_options = [ 'Female' => 'Female', 'Male' => 'Male', 'Other' => 'Other', ]; ?> {{ html()->label($field_lable, $field_name) }} {!! fielf_required($required) !!} {{ html()->select($field_name, $select_options)->placeholder($field_placeholder)->class('form-control ')->attributes(["$required"]) }} </div> </div> </div> <div class="row"> <div class="col-12 col-sm-6"> <div class="form-group"> <?php $field_name = 'address'; $field_lable = label_case($field_name); $field_placeholder = $field_lable; $required = ""; ?> {{ html()->label($field_lable, $field_name) }} {!! fielf_required($required) !!} {{ html()->textarea($field_name)->placeholder($field_placeholder)->class('form-control')->attributes(["$required"]) }} </div> </div> <div class="col-12 col-sm-6"> <div class="form-group"> <?php $field_name = 'bio'; $field_lable = label_case($field_name); $field_placeholder = $field_lable; $required = ""; ?> {{ html()->label($field_lable, $field_name) }} {!! fielf_required($required) !!} {{ html()->textarea($field_name)->placeholder($field_placeholder)->class('form-control')->attributes(["$required"]) }} </div> </div> </div> <div class="row"> <div class="col-12 col-sm-3"> <div class="form-group"> <?php $field_name = 'url_website'; $field_lable = label_case($field_name); $field_placeholder = $field_lable; $required = ""; ?> {{ html()->label($field_lable, $field_name) }} {!! fielf_required($required) !!} {{ html()->text($field_name)->placeholder($field_placeholder)->class('form-control')->attributes(["$required"]) }} </div> </div> <div class="col-12 col-sm-3"> <div class="form-group"> <?php $field_name = 'url_facebook'; $field_lable = label_case($field_name); $field_placeholder = $field_lable; $required = ""; ?> {{ html()->label($field_lable, $field_name) }} {!! fielf_required($required) !!} {{ html()->text($field_name)->placeholder($field_placeholder)->class('form-control')->attributes(["$required"]) }} </div> </div> <div class="col-12 col-sm-3"> <div class="form-group"> <?php $field_name = 'url_twitter'; $field_lable = label_case($field_name); $field_placeholder = $field_lable; $required = ""; ?> {{ html()->label($field_lable, $field_name) }} {!! fielf_required($required) !!} {{ html()->text($field_name)->placeholder($field_placeholder)->class('form-control')->attributes(["$required"]) }} </div> </div> <div class="col-12 col-sm-3"> <div class="form-group"> <?php $field_name = 'url_linkedin'; $field_lable = label_case($field_name); $field_placeholder = $field_lable; $required = ""; ?> {{ html()->label($field_lable, $field_name) }} {!! fielf_required($required) !!} {{ html()->text($field_name)->placeholder($field_placeholder)->class('form-control')->attributes(["$required"]) }} </div> </div> </div> <div class="form-group row"> {{ html()->label(__('labels.backend.users.fields.password'))->class('col-md-2 form-control-label')->for('password') }} <div class="col-md-10"> <a href="{{ route('frontend.users.changePassword', $$module_name_singular->id) }}" class="btn btn-outline-primary btn-sm"><i class="now-ui-icons objects_key-25"></i> Change password</a> </div> </div> <div class="row mt-4"> <div class="col"> <div class="form-group"> {!! Form::button("<i class='fas fa-save'></i> Save", ['class' => 'btn btn-success', 'type'=>'submit']) !!} </div> </div> </div> {{ html()->closeModelForm() }} //
-
routes/web.php
Open in GitHub// Route::group(['namespace' => 'Frontend', 'as' => 'frontend.'], function () { // Route::group(['middleware' => ['auth']], function () { $module_name = 'users'; $controller_name = 'UserController'; // Route::get('profile/{id}/edit', ['as' => "$module_name.profileEdit", 'uses' => "$controller_name@profileEdit"]); Route::patch('profile/{id}/edit', ['as' => "$module_name.profileUpdate", 'uses' => "$controller_name@profileUpdate"]); // }); }); //
-
app/Http/Controllers/Frontend/UserController.php
Open in GitHubuse App\Http\Controllers\Controller; use App\Models\Permission; use App\Models\Role; use App\Models\User; use App\Models\Userprofile; use App\Models\UserProvider; use Illuminate\Http\Request; use App\Events\Frontend\UserProfileUpdated; class UserController extends Controller { // public function profileEdit($id) { $module_title = $this->module_title; $module_name = $this->module_name; $module_path = $this->module_path; $module_icon = $this->module_icon; $module_model = $this->module_model; $module_name_singular = Str::singular($module_name); $module_action = 'Edit Profile'; $page_heading = ucfirst($module_title); $title = $page_heading.' '.ucfirst($module_action); if (!auth()->user()->can('edit_users')) { $id = auth()->user()->id; } if ($id != auth()->user()->id) { return redirect()->route('frontend.users.profile', $id); } $$module_name_singular = $module_model::findOrFail($id); $userprofile = Userprofile::where('user_id', $id)->first(); $body_class = 'profile-page'; return view( "frontend.$module_name.profileEdit", compact('module_title', 'module_name', 'module_path', 'module_icon', 'module_action', 'module_name_singular', "$module_name_singular", 'userprofile', 'body_class') ); } public function profileUpdate(Request $request, $id) { $module_title = $this->module_title; $module_name = $this->module_name; $module_path = $this->module_path; $module_icon = $this->module_icon; $module_model = $this->module_model; $module_name_singular = Str::singular($module_name); $module_action = 'Profile Update'; if ($id != auth()->user()->id) { return redirect()->route('frontend.users.profile', $id); } $this->validate($request, [ 'first_name' => 'required|string|max:191', 'last_name' => 'required|string|max:191', 'avatar' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048', ]); $module_name = $this->module_name; $module_name_singular = Str::singular($this->module_name); if (!auth()->user()->can('edit_users')) { $id = auth()->user()->id; $username = auth()->user()->username; } $$module_name_singular = $module_model::findOrFail($id); $filename = $$module_name_singular->avatar; // Handle Avatar upload if ($request->hasFile('avatar')) { if ($$module_name_singular->getMedia($module_name)->first()) { $$module_name_singular->getMedia($module_name)->first()->delete(); } $media = $$module_name_singular->addMedia($request->file('avatar'))->toMediaCollection($module_name); $$module_name_singular->avatar = $media->getUrl(); $$module_name_singular->save(); } $data_array = $request->except('avatar'); $data_array['avatar'] = $$module_name_singular->avatar; $data_array['name'] = $request->first_name.' '.$request->last_name; $user_profile = Userprofile::where('user_id', '=', $$module_name_singular->id)->first(); $user_profile->update($data_array); event(new UserProfileUpdated($user_profile)); return redirect()->route('frontend.users.profile', $$module_name_singular->id)->with('flash_success', 'Update successful!'); } // }