Skip to content

Commit

Permalink
Change User Information
Browse files Browse the repository at this point in the history
  • Loading branch information
YasserElgammal committed Jan 14, 2023
1 parent a4349aa commit ae3cd37
Show file tree
Hide file tree
Showing 11 changed files with 183 additions and 12 deletions.
48 changes: 48 additions & 0 deletions app/Http/Controllers/Admin/AccountController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Http\Requests\UpdateAccountRequest;
use App\Models\User;
use Illuminate\Support\Facades\Storage;

class AccountController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$user = Auth()->user();
return view('admin.account.index', compact('user'));
}


/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(UpdateAccountRequest $request)
{
$user = auth()->user();
$data = $request->safe()->except('avatar');

if ($request->hasfile('avatar')) {
if ($user->avatar != null) {
Storage::delete($user->avatar);
}
$get_file = $request->file('avatar')->store('images/profiles');
$user->avatar = $get_file;
}

$user->update($data);

return to_route('admin.account.index')->with('message', 'Account Updated');
}
}
2 changes: 2 additions & 0 deletions app/Http/Controllers/Admin/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Http\Requests\UpdateAccountRequest;
use App\Models\Role;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;

class UserController extends Controller
{
Expand Down
35 changes: 35 additions & 0 deletions app/Http/Requests/UpdateAccountRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class UpdateAccountRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array<string, mixed>
*/
public function rules()
{
return [
'avatar' => ['image', 'mimes:jpeg,png,jpg', 'max:2048'],
'url_fb' => ['required', 'url'],
'url_insta' => ['required', 'url'],
'url_twitter' => ['required', 'url'],
'url_linkedin' => ['required', 'url'],
'bio' => ['required', 'min:4']
];
}
}
6 changes: 3 additions & 3 deletions app/Http/Requests/UpdateSettingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public function authorize()
public function rules()
{
return [
'site_name' => ['required', 'min:3'],
'description' => ['required', 'min:3'],
'about' => ['required', 'min:3'],
'site_name' => ['required', 'min:3', 'max:20'],
'description' => ['required', 'min:3', 'max:255'],
'about' => ['required', 'min:3', 'max:255'],
'copy_rights' => ['required', 'min:3'],
'url_fb' => ['required', 'url'],
'url_insta' => ['required', 'url'],
Expand Down
6 changes: 6 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ class User extends Authenticatable
'name',
'email',
'password',
'role_id',
'avatar',
'bio',
'url_fb',
'url_insta',
'url_twitter',
'url_linkedin'
];

/**
Expand Down
3 changes: 2 additions & 1 deletion app/View/Components/AdminLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function __construct()
*/
public function render()
{
return view('admin.layouts.admin');
$user_avatar = auth()->user()->avatar;
return view('admin.layouts.admin', compact('user_avatar'));
}
}
73 changes: 73 additions & 0 deletions resources/views/admin/account/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<x-admin-layout>

<div class="w-full h-screen overflow-x-hidden border-t flex flex-col">
<main class="w-full flex-grow p-6">
<h1 class="w-full text-3xl text-black pb-6">User Profile</h1>

<div class="w-full mt-12">
<p class="text-xl pb-3 flex items-center">
<i class="fas fa-list mr-3"></i> User Details
</p>
<div class="flex items-center justify-center mb-4">



<form method="POST" action="{{ route('admin.account.update', $user->id) }}" enctype="multipart/form-data">
@csrf
@method('PUT')

@if ($user->avatar == null)
<img src="{{ asset('import/assets/profile-pic-dummy.png') }}"
class="rounded-full shadow h-32 w-32">
@else
<img src="{{ asset('storage') . '/' . $user->avatar }}"
class="rounded-full shadow h-32 w-32">
@endif
<label class="ml-4 block text-sm text-gray-600" for="message">Choose Image: </label>
<input class="ml-2" type="file" id="myimage" name="avatar">
</div>
<div class="grid gap-6 mb-6 md:grid-cols-2">
<div class="mb-1">
<label for="url_insta"
class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Instagram
URL</label>
<input type="text" name="url_insta" id="url_insta" value="{{ $user->url_insta }}"
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
required>
</div>
<div class="mb-1">
<label for="url_twitter"
class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Twitter URL</label>
<input type="text" name="url_twitter" id="url_twitter" value="{{ $user->url_twitter }}"
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
required>
</div>
<div class="mb-1">
<label for="url_linkedin"
class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">LinkedIN
URL</label>
<input type="text" name="url_linkedin" id="url_linkedin" value="{{ $user->url_linkedin }}"
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
required>
</div>
<div class="mb-1">
<label for="url_fb"
class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Facebook
URL</label>
<input type="text" name="url_fb" id="url_fb" value="{{ $user->url_fb }}"
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
required>
</div>
{{-- --}}
</div>
<div class="mb-2">
<label class="block text-sm text-gray-600" for="bio">Bio</label>
<textarea class="w-full bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" id="bio" name="bio" required="">{{ $user->bio }}</textarea>
</div>
<button class="px-4 py-1 text-white font-light tracking-wider bg-green-600 rounded">Update
Profile</button>
</form>
</div>
</main>
</div>
</x-admin-layout>
10 changes: 7 additions & 3 deletions resources/views/admin/layouts/admin.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,17 @@ class="absolute w-full upgrade-btn bottom-0 active-nav-link text-white flex item
<div x-data="{ isOpen: false }" class="relative w-1/2 flex justify-end">
<button @click="isOpen = !isOpen"
class="realtive z-10 w-12 h-12 rounded-full overflow-hidden border-4 border-gray-400 hover:border-gray-300 focus:border-gray-300 focus:outline-none">
<img src="https://source.unsplash.com/uJ8LNVCBjFQ/400x400">
@if ($user_avatar == null)
<img src="{{ asset('import/assets/profile-pic-dummy.png') }}">
@else
<img src="{{ asset('storage') . '/' . $user_avatar }}">
@endif
</button>
<button x-show="isOpen" @click="isOpen = false"
class="h-full w-full fixed inset-0 cursor-default"></button>
<div x-show="isOpen" class="absolute w-32 bg-white rounded-lg shadow-lg py-2 mt-16">
<a href="#" class="block px-4 py-2 account-link hover:text-white">Account</a>
<a href="#" class="block px-4 py-2 account-link hover:text-white">Support</a>
<a href="{{ route('admin.account.index') }}" class="block px-4 py-2 account-link hover:text-white">Account</a>
<a href="http://linkedin.com" class="block px-4 py-2 account-link hover:text-white">Support</a>
<form method="POST" action="{{ route('logout') }}">
@csrf
<button class="block px-4 py-2 account-link hover:text-white w-full text-left">Sign Out</button>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/admin/user/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<label for="role" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Role Name</label>
<select name="role_id" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" id="selectType">
@foreach ($roles as $role)
<option value="{{ $role->id }}">{{ $role->name }}</option>
<option value="{{ $role->id }}" {{ $role->name == $user->role->name ? 'selected' : '' }}>{{ $role->name }}</option>
@endforeach
</select>
</div>
Expand Down
6 changes: 3 additions & 3 deletions resources/views/layouts/blog.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ class="hover:bg-gray-400 rounded py-2 px-4 mx-2">{{ $category->name }}</a>
<div class="w-full bg-white shadow flex flex-col my-4 p-6">
<p class="text-xl font-semibold pb-5">About Us</p>
<p class="pb-2">{{ $setting->about }}</p>
<a href="#"
{{-- <a href="#"
class="w-full bg-blue-800 text-white font-bold text-sm uppercase rounded hover:bg-blue-700 flex items-center justify-center px-2 py-3 mt-4">
Get to know us
</a>
</a> --}}
</div>

<div class="w-full bg-white shadow flex flex-col my-4 p-6">
Expand All @@ -130,7 +130,7 @@ class="flex justify-center items-center m-1 font-medium py-1 px-2 bg-white round
</div>

<div class="w-full bg-white shadow flex flex-col my-4 p-6">
<p class="text-xl font-semibold pb-5">Top Writers</p>
<p class="text-xl font-semibold pb-5">Top 5 Writers</p>
{{-- --}}
<div class="content flex justify-between py-2 w-full">
<div class="px-2 justify-between">
Expand Down
4 changes: 3 additions & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use App\Http\Controllers\Admin\AccountController;
use App\Http\Controllers\Admin\AdminController;
use App\Http\Controllers\Admin\CategoryController;
use App\Http\Controllers\Admin\PageController;
Expand Down Expand Up @@ -50,14 +51,15 @@
Route::get('/post/slug-get', [PostController::class, 'getSlug'])->name('post.getslug');
Route::resource('/post', PostController::class);
Route::resource('/tag', TagController::class);
Route::resource('/account', AccountController::class, ['only' => ['index', 'update']]);
// Special To Admin Role Only
Route::middleware(['can:admin-only'])->group(function () {
Route::get('/category/slug-get', [CategoryController::class, 'getSlug'])->name('category.getslug');
Route::resource('/category', CategoryController::class);
Route::get('/page/slug-get', [PageController::class, 'getSlug'])->name('page.getslug');
Route::resource('/user', UserController::class, ['except' => ['create', 'store', 'show']]);
Route::resource('/page', PageController::class);
Route::resource('/role', RoleController::class, ['only' => ['index']]);
Route::resource('/user', UserController::class, ['except' => ['create', 'store', 'show']]);
Route::resource('/setting', SettingController::class, ['only' => ['index', 'update']]);
});
});
Expand Down

0 comments on commit ae3cd37

Please sign in to comment.