Skip to content

Commit 1df3864

Browse files
committed
User profile Update
1 parent da02e91 commit 1df3864

19 files changed

+127
-1147
lines changed

app/Events/Backend/UserProfileUpdated.php

-38
This file was deleted.

app/Events/Frontend/UserProfileUpdated.php

-38
This file was deleted.

app/Http/Controllers/Backend/UserController.php

+2-189
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ public function store(Request $request)
270270
];
271271
$$module_name_singular->notify(new UserAccountCreated($data));
272272

273-
Flash::success(icon('fas fa-envelope').' Account Credentials Sent to User.')->important();
273+
Flash::success('Account Credentials Sent to User.')->important();
274274
}
275275

276276
Log::info(label_case($module_title.' '.$module_action)." | '".$$module_name_singular->name.'(ID:'.$$module_name_singular->id.") ' by User:".auth()->user()->name.'(ID:'.auth()->user()->id.')');
@@ -296,202 +296,15 @@ public function show($id)
296296
$module_action = 'Show';
297297

298298
$$module_name_singular = $module_model::findOrFail($id);
299-
$userprofile = Userprofile::where('user_id', $$module_name_singular->id)->first();
300299

301300
Log::info(label_case($module_title.' '.$module_action).' | User:'.auth()->user()->name.'(ID:'.auth()->user()->id.')');
302301

303302
return view(
304303
"backend.{$module_name}.show",
305-
compact('module_title', 'module_name', 'module_path', 'module_icon', 'module_action', 'module_name_singular', "{$module_name_singular}", 'userprofile')
306-
);
307-
}
308-
309-
/**
310-
* Display Profile Details of Logged in user.
311-
*
312-
* @param int $id
313-
* @return \Illuminate\Contracts\View\View
314-
*/
315-
public function profile(Request $request, $id)
316-
{
317-
$module_title = $this->module_title;
318-
$module_name = $this->module_name;
319-
$module_path = $this->module_path;
320-
$module_icon = $this->module_icon;
321-
$module_model = $this->module_model;
322-
$module_name_singular = Str::singular($module_name);
323-
$module_action = 'Profile Show';
324-
325-
$$module_name_singular = $module_model::with('roles', 'permissions')->findOrFail($id);
326-
327-
if ($$module_name_singular) {
328-
$userprofile = Userprofile::where('user_id', $id)->first();
329-
} else {
330-
Log::error('UserProfile Exception for Username: '.$username);
331-
abort(404);
332-
}
333-
334-
Log::info(label_case($module_title.' '.$module_action).' | User:'.auth()->user()->name.'(ID:'.auth()->user()->id.')');
335-
336-
return view("backend.{$module_name}.profile", compact('module_name', 'module_name_singular', "{$module_name_singular}", 'module_icon', 'module_action', 'module_title', 'userprofile'));
337-
}
338-
339-
/**
340-
* Edit the profile.
341-
*
342-
* @param int $id The ID of the profile to edit.
343-
* @return Illuminate\View\View The view for editing the profile.
344-
*
345-
* @throws Illuminate\Database\Eloquent\ModelNotFoundException If the profile is not found.
346-
*/
347-
public function profileEdit($id)
348-
{
349-
$module_title = $this->module_title;
350-
$module_name = $this->module_name;
351-
$module_path = $this->module_path;
352-
$module_icon = $this->module_icon;
353-
$module_model = $this->module_model;
354-
$module_name_singular = Str::singular($module_name);
355-
356-
$module_action = 'Edit Profile';
357-
358-
if (! auth()->user()->can('edit_users')) {
359-
$id = auth()->user()->id;
360-
}
361-
362-
$$module_name_singular = $module_model::findOrFail($id);
363-
$userprofile = Userprofile::where('user_id', $$module_name_singular->id)->first();
364-
365-
Log::info(label_case($module_title.' '.$module_action).' | User:'.auth()->user()->name.'(ID:'.auth()->user()->id.')');
366-
367-
return view(
368-
"backend.{$module_name}.profileEdit",
369-
compact('module_title', 'module_name', 'module_path', 'module_icon', 'module_action', 'module_name_singular', "{$module_name_singular}", 'userprofile')
304+
compact('module_title', 'module_name', 'module_path', 'module_icon', 'module_action', 'module_name_singular', "{$module_name_singular}")
370305
);
371306
}
372307

373-
/**
374-
* Updates the user profile.
375-
*
376-
* @param Request $request The request object.
377-
* @param int $id The ID of the user.
378-
* @return RedirectResponse The response redirecting to the user's profile page.
379-
*/
380-
public function profileUpdate(Request $request, $id)
381-
{
382-
$module_title = $this->module_title;
383-
$module_name = $this->module_name;
384-
$module_path = $this->module_path;
385-
$module_icon = $this->module_icon;
386-
$module_model = $this->module_model;
387-
$module_name_singular = Str::singular($module_name);
388-
389-
$module_action = 'Edit Profile';
390-
391-
$request->validate($request, [
392-
'avatar' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048',
393-
'first_name' => 'required|min:3|max:191',
394-
'last_name' => 'required|min:3|max:191',
395-
'email' => 'required|email|regex:/(.+)@(.+)\.(.+)/i|max:191|unique:'.$module_model.',email,'.$id,
396-
]);
397-
398-
if (! auth()->user()->can('edit_users')) {
399-
$id = auth()->user()->id;
400-
}
401-
402-
$$module_name_singular = User::findOrFail($id);
403-
404-
// Handle Avatar upload
405-
if ($request->hasFile('avatar')) {
406-
if ($$module_name_singular->getMedia($module_name)->first()) {
407-
$$module_name_singular->getMedia($module_name)->first()->delete();
408-
}
409-
410-
$media = $$module_name_singular->addMedia($request->file('avatar'))->toMediaCollection($module_name);
411-
412-
$$module_name_singular->avatar = $media->getUrl();
413-
414-
$$module_name_singular->save();
415-
}
416-
417-
$data_array = $request->except('avatar');
418-
$data_array['avatar'] = $$module_name_singular->avatar;
419-
$data_array['name'] = $request->first_name.' '.$request->last_name;
420-
421-
$user_profile = Userprofile::where('user_id', '=', $$module_name_singular->id)->first();
422-
$user_profile->update($data_array);
423-
424-
event(new UserProfileUpdated($user_profile));
425-
426-
flash(label_case($module_name_singular).' Updated Successfully!')->success()->important();
427-
428-
Log::info(label_case($module_title.' '.$module_action).' | User:'.auth()->user()->name.'(ID:'.auth()->user()->id.')');
429-
430-
return redirect(route('backend.users.profile', $$module_name_singular->id));
431-
}
432-
433-
/**
434-
* Change the password of the user's profile.
435-
*
436-
* @param int $id The ID of the user whose password will be changed. If the user does not have the "edit_users" permission, the ID will be set to the current authenticated user's ID.
437-
* @return \Illuminate\View\View The view that displays the form to change the profile password.
438-
*/
439-
public function changeProfilePassword($id)
440-
{
441-
if (! auth()->user()->can('edit_users')) {
442-
$id = auth()->user()->id;
443-
}
444-
445-
$title = $this->module_title;
446-
$module_title = $this->module_title;
447-
$module_name = $this->module_name;
448-
$module_name_singular = Str::singular($this->module_name);
449-
$module_icon = $this->module_icon;
450-
$module_action = 'Edit';
451-
452-
$$module_name_singular = User::findOrFail($id);
453-
454-
return view("backend.{$module_name}.changeProfilePassword", compact('module_name', 'module_title', "{$module_name_singular}", 'module_icon', 'module_action'));
455-
}
456-
457-
/**
458-
* Change the profile password for a user.
459-
*
460-
* @param Request $request The HTTP request object.
461-
* @param int $id The user ID.
462-
* @return \Illuminate\Http\RedirectResponse Redirects to the user's profile page.
463-
*
464-
* @throws \Illuminate\Validation\ValidationException If the validation fails.
465-
*/
466-
public function changeProfilePasswordUpdate(Request $request, $id)
467-
{
468-
$request->validate($request, [
469-
'password' => 'required|confirmed|min:6',
470-
]);
471-
472-
$module_title = $this->module_title;
473-
$module_name = $this->module_name;
474-
$module_path = $this->module_path;
475-
$module_icon = $this->module_icon;
476-
$module_model = $this->module_model;
477-
$module_name_singular = Str::singular($module_name);
478-
479-
if (! auth()->user()->can('edit_users')) {
480-
$id = auth()->user()->id;
481-
}
482-
483-
$$module_name_singular = User::findOrFail($id);
484-
485-
$request_data = $request->only('password');
486-
$request_data['password'] = Hash::make($request_data['password']);
487-
488-
$$module_name_singular->update($request_data);
489-
490-
Flash::success(Str::singular($module_title)."' Updated Successfully")->important();
491-
492-
return redirect("admin/{$module_name}/profile/{$id}");
493-
}
494-
495308
/**
496309
* Updates the password for a user.
497310
*

app/Listeners/Backend/UserCreated/UserCreatedProfileCreate.php

-47
This file was deleted.

app/Listeners/Backend/UserUpdated/UserUpdatedProfileUpdate.php

-47
This file was deleted.

0 commit comments

Comments
 (0)