Skip to content

Commit 5725bf0

Browse files
committed
expert role done
1 parent 9a8bf6f commit 5725bf0

File tree

10 files changed

+137
-68
lines changed

10 files changed

+137
-68
lines changed

app/Http/Controllers/Backend/User/UserController.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function internalUsers()
5353
$user = Auth::user();
5454
$data = User::with('roles')
5555
->whereHas('roles', function(Builder $q){
56-
$q->where('name', '=', 'partner', 'or');
56+
$q->whereNot('name', 'partner', 'or');
5757
$q->whereNot('name', 'user');
5858
})
5959
->whereNot('id', auth()->id())->latest()->latest()->paginate(paginateCount());
@@ -99,11 +99,16 @@ public function store(Request $request)
9999
}
100100
$userData->save();
101101
$userData->assignRole($request->role_id);
102+
$userData->refresh();
102103

103104
$notification = [
104105
'message' => 'User Profile Created',
105106
'alert-type' => 'success',
106107
];
108+
if ($userData->role_name == 'expert') {
109+
return redirect(route('expert-profile.create')."?user_id=$userData->id")->with($notification);
110+
}
111+
107112
return back()->with($notification);
108113
}
109114

app/Http/Controllers/ExpertProfileController.php

+11-7
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,26 @@
22

33
namespace App\Http\Controllers;
44

5-
use App\Models\Map;
65
use App\Models\ExpertProfile;
76
use App\Models\ExpertCategory;
87
use App\Http\Requests\StoreExpertProfileRequest;
98
use App\Http\Requests\UpdateExpertProfileRequest;
9+
use App\Models\User;
1010

1111
class ExpertProfileController extends Controller
1212
{
13-
1413
public function __construct()
1514
{
1615
$this->middleware('can:read expert', [
1716
'only' => ['index', 'show']
1817
]);
19-
$this->middleware('can:create expert', [
18+
$this->middleware('can:create expert', [
2019
'only' => ['create', 'store']
2120
]);
22-
$this->middleware('can:update expert', [
21+
$this->middleware('can:update expert', [
2322
'only' => ['update', 'edit']
2423
]);
25-
$this->middleware('can:delete expert', [
24+
$this->middleware('can:delete expert', [
2625
'only' => ['destroy']
2726
]);
2827
}
@@ -41,7 +40,9 @@ public function index()
4140
public function create()
4241
{
4342
$expertCategories = ExpertCategory::get();
44-
return view("backend.expertProfile.createExpertProfile", compact('expertCategories'));
43+
$user = User::find(request()->query('user_id'));
44+
$users = User::role('expert')->get()->pluck('name', 'id');
45+
return view("backend.expertProfile.createExpertProfile", compact('expertCategories', 'user', 'users'));
4546
}
4647

4748
/**
@@ -51,6 +52,7 @@ public function store(StoreExpertProfileRequest $request)
5152
{
5253
$expert = new ExpertProfile();
5354
$expert->name = $request->name;
55+
$expert->user_id = $request->user_id;
5456
$expert->post = $request->post;
5557
$expert->bio = $request->bio;
5658
$expert->description = $request->description;
@@ -96,7 +98,9 @@ public function show(ExpertProfile $expertProfile)
9698
public function edit(ExpertProfile $expertProfile)
9799
{
98100
$expertCategories = ExpertCategory::get();
99-
return view("backend.expertProfile.editExpertProfile", compact('expertProfile', 'expertCategories'));
101+
$user = User::find(request()->query('user_id'));
102+
$users = User::role('expert')->get()->pluck('name', 'id');
103+
return view("backend.expertProfile.editExpertProfile", compact('expertProfile', 'expertCategories', 'user', 'users'));
100104
}
101105

102106
/**

app/Http/Controllers/Frontend/Page/PageController.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,11 @@ public function appointmentVirtual(Request $request, ?ExpertProfile $expertProfi
7878
{
7979
$office = !empty($request->query('office_id')) ? Map::find($request->query('office_id')) : null;
8080
$banners = getRecords('banners');
81+
$times = AppointmentTime::whereIn('user_id', User::role('super admin')->get()->pluck('id'))->pluck('time');
82+
8183
$infos1 = Info::where('section_id', 1)->latest()->get();
8284
$testimonials = \App\Models\Review::with('user')->latest()->limit(10)->latest()->get();
83-
return view('frontend.pages.appointment.makeAppointmentVirtual', compact('banners', 'expertProfile', 'testimonials', 'infos1', 'office'));
85+
return view('frontend.pages.appointment.makeAppointmentVirtual', compact('times','banners', 'expertProfile', 'testimonials', 'infos1', 'office'));
8486
}
8587
public function aboutPage()
8688
{

app/Http/Requests/StoreExpertProfileRequest.php

+1-8
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@
66

77
class StoreExpertProfileRequest extends FormRequest
88
{
9-
/**
10-
* Determine if the user is authorized to make this request.
11-
*/
12-
public function authorize(): bool
13-
{
14-
return true;
15-
}
169

1710
/**
1811
* Get the validation rules that apply to the request.
@@ -28,7 +21,7 @@ public function rules(): array
2821
"experience" => 'required',
2922
"join_date" => 'required',
3023
"availability" => 'required',
31-
"image" => 'required|mimes:png,jpg,webp,jpeg',
24+
"image" => 'required|image',
3225
];
3326
}
3427
}

app/Models/User.php

+7
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ class User extends Authenticatable implements MustVerifyEmail
4444
protected $casts = [
4545
'email_verified_at' => 'datetime',
4646
];
47+
public function getRoleNameAttribute()
48+
{
49+
return $this->roles->first()?->name;
50+
}
51+
public function expertProfile(){
52+
return $this->hasOne(ExpertProfile::class, 'user_id');
53+
}
4754

4855
public function commissionHistories()
4956
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::table('expert_profiles', function (Blueprint $table) {
15+
$table->foreignId('user_id')
16+
->nullable()
17+
->constrained()
18+
->cascadeOnDelete();
19+
20+
});
21+
}
22+
23+
/**
24+
* Reverse the migrations.
25+
*/
26+
public function down(): void
27+
{
28+
Schema::table('expert_profiles', function (Blueprint $table) {
29+
$table->dropForeign(['user_id']);
30+
});
31+
Schema::table('expert_profiles', function (Blueprint $table) {
32+
$table->dropColumn(['user_id']);
33+
});
34+
}
35+
};

resources/views/backend/expertProfile/createExpertProfile.blade.php

+13-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
'[{"_id":"bandarban","district":"Bandarban","coordinates":"21.8311, 92.3686","upazilla":["Ali Kadam","Thanchi","Lama","Bandarban Sadar","Rowangchhari","Naikhongchhari","Ruma"]},{"_id":"brahmanbaria","district":"Brahmanbaria","coordinates":"23.9608, 91.1115","upazilla":["Akhaura","Nasirnagar","Bancharampur","Sarail","Ashuganj","Bijoynagar","Nabinagar","Kasba","Brahmanbaria Sadar"]},{"_id":"chandpur","district":"Chandpur","coordinates":"23.2513, 90.8518","upazilla":["Haziganj","Faridganj","Matlab Dakshin","Chandpur Sadar","Kachua","Haimchar","Shahrasti","Matlab Uttar"]},{"_id":"chattogram","district":"Chattogram","coordinates":"22.5150, 91.7539","upazilla":["Rangunia","Sitakunda","Boalkhali","Patiya","Banshkhali","Karnaphuli","Lohagara","Hathazari","Mirsharai","Sandwip","Raozan","Chandanaish","Fatikchhari","Anwara","Satkania"]},{"_id":"cox\'s bazar","district":"Cox\'s Bazar","coordinates":"21.5641, 92.0282","upazilla":["Maheshkhali","Chakaria","Cox\'s Bazar Sadar","Ukhia","Pekua","Ramu","Teknaf","Kutubdia"]},{"_id":"cumilla","district":"Cumilla","coordinates":"23.4576, 91.1809","upazilla":["Titas","Monohargonj","Chandina","Cumilla Adarsha Sadar","Meghna","Nangalkot","Chauddagram","Barura","Cumilla Sadar Dakshin","Laksam","Daudkandi","Homna","Burichang","Debidwar","Muradnagar","Brahmanpara","Lalmai"]},{"_id":"feni","district":"Feni","coordinates":"22.9409, 91.4067","upazilla":["Fulgazi","Parshuram","Feni Sadar","Sonagazi","Daganbhuiyan","Chhagalnaiya"]},{"_id":"khagrachari","district":"Khagrachari","coordinates":"23.1322, 91.9490","upazilla":["Lakshmichhari","Panchhari","Mahalchhari","Dighinala","Manikchhari","Matiranga","Ramgarh","Khagrachhari Sadar"]},{"_id":"lakshmipur","district":"Lakshmipur","coordinates":"22.9447, 90.8282","upazilla":["Raipur","Ramganj","Lakshmipur Sadar","Ramgati","Kamalnagar"]},{"_id":"noakhali","district":"Noakhali","coordinates":"22.8724, 91.0973","upazilla":["Subarnachar","Hatiya","Kabirhat","Noakhali Sadar","Begumganj","Senbagh","Sonaimuri","Chatkhil","Companiganj"]},{"_id":"rangamati","district":"Rangamati","coordinates":"22.7324, 92.2985","upazilla":["Rajasthali","Kawkhali","Belaichhari","Kaptai","Barkal","Juraichhari","Naniyachar","Rangamati Sadar","Bagaichhari","Langadu"]}]';
1414
$jsonObject = json_decode($jsonString);
1515
$districts = collect($jsonObject);
16-
16+
1717
@endphp
1818
<x-backend.ui.breadcrumbs :list="['Peoples', 'Expert', 'Create']" />
1919

@@ -26,7 +26,16 @@
2626
<x-backend.form.image-input class="" label="Expert Avatar" name="image" />
2727
</div>
2828
<div class="col-sm-6 mt-3">
29-
<x-backend.form.text-input label="Name" required type="text" name="name">
29+
<div class="{{ request()->query('user_id') ? 'd-none' : '' }}">
30+
<x-backend.form.select-input id="expert-select" name="user_id" label="Select Expert"
31+
placeholder="Select Expert">
32+
@foreach ($users as $id => $name)
33+
<option value="{{ $id }}" @selected(request()->query('user_id') == $id)>{{ $name }}
34+
</option>
35+
@endforeach
36+
</x-backend.form.select-input>
37+
</div>
38+
<x-backend.form.text-input label="Name" required type="text" name="name" :value="$user?->name">
3039
</x-backend.form.text-input>
3140

3241
<div>
@@ -52,7 +61,7 @@
5261
</x-form.ck-editor>
5362
</div>
5463
<div class="col-md-6">
55-
<x-form.ck-editor id="ck-editor2" name="description" placeholder="description" label="Description">
64+
<x-form.ck-editor id="ck-editor2" required name="description" placeholder="description" label="Description">
5665
</x-form.ck-editor>
5766
</div>
5867
<div class="col-sm-6 col-lg-4">
@@ -101,7 +110,7 @@
101110
</x-form.ck-editor>
102111

103112
<div class="col-md-12">
104-
<x-backend.ui.button type="submit" class="btn-primary mb-3">Create</x-backend.ui.button>
113+
<x-backend.ui.button type="submit" class="btn-primary mb-3">Update</x-backend.ui.button>
105114
</div>
106115
</div>
107116
</form>

resources/views/backend/expertProfile/editExpertProfile.blade.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@
2828
<x-backend.form.image-input class="" label="Expert Avatar" name="image" :image="$expertProfile->image" />
2929
</div>
3030
<div class="col-sm-6 mt-3">
31+
<div class="{{ request()->query('user_id') ? 'd-none' : '' }}">
32+
<x-backend.form.select-input id="expert-select" name="user_id" label="Select Expert"
33+
placeholder="Select Expert">
34+
@foreach ($users as $id => $name)
35+
<option value="{{ $id }}" @selected(request()->query('user_id') == $id)>{{ $name }}
36+
</option>
37+
@endforeach
38+
</x-backend.form.select-input>
39+
</div>
3140
<x-backend.form.text-input label="Name" required type="text" name="name" :value="$expertProfile->name">
3241
</x-backend.form.text-input>
3342

@@ -61,7 +70,7 @@
6170
</x-form.ck-editor>
6271
</div>
6372
<div class="col-md-6">
64-
<x-form.ck-editor id="ck-editor2" name="description" placeholder="description" label="Description">
73+
<x-form.ck-editor id="ck-editor2" name="description" required placeholder="description" label="Description">
6574
{!! $expertProfile->description !!}
6675
</x-form.ck-editor>
6776
</div>

resources/views/backend/users/view-users.blade.php

+24-20
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<th>Admin Reference</th>
3737
<th>Created At</th>
3838
@canany(['create user', 'update user', 'delete user'])
39-
<th>Action</th>
39+
<th>Action</th>
4040
@endcanany
4141
</tr>
4242
</thead>
@@ -45,8 +45,8 @@
4545
@foreach ($data as $key => $user)
4646
<tr>
4747
<td>{{ ++$key }}</td>
48-
<td><img loading="lazy" src="{{ useImage($user->image_url) }}" alt="{{ $user->user_name }}"
49-
width="80px" loading="lazy"></td>
48+
<td><img loading="lazy" src="{{ useImage($user->image_url) }}"
49+
alt="{{ $user->user_name }}" width="80px" loading="lazy"></td>
5050
<td>{{ $user->name }}</td>
5151
<td>{{ $user->email }}</td>
5252
<td class="text-capitalize">
@@ -55,25 +55,29 @@ class="px-2 py-1 bg-soft-success text-success rounded rounded-3 fw-medium">{{ $u
5555
</td>
5656
<td>{{ $user->phone }}</td>
5757
<td>{!! $user->admin_ref !!}</td>
58-
<td>{{$user->created_at->format("F d, Y")}}</td>
58+
<td>{{ $user->created_at->format('F d, Y') }}</td>
5959
@canany(['update user', 'delete user'])
60-
<td>
61-
@can('update user')
62-
<a href="{{ route('users.edit', $user->id) }}"
63-
class="btn btn-info btn-sm">Edit</a>
64-
@endcan
65-
@can('delete user')
66-
<form action="{{ route('users.destroy', $user->id) }}" method="post"
67-
class="d-inline-block py-0">
68-
@csrf
69-
@method('DELETE')
70-
<x-backend.ui.button
71-
class="btn-danger btn-sm text-capitalize">Delete</x-backend.ui.button>
72-
</form>
73-
@endcan
74-
</td>
60+
<td>
61+
@can('update user')
62+
@if ($user->expertProfile)
63+
<a href="{{ route('expert-profile.edit', ['expert_profile' => $user->expertProfile->id]) . "?user_id=$user->id" }}"
64+
class="btn btn-primary btn-sm">Expert Profile</a>
65+
@endif
66+
<a href="{{ route('users.edit', $user->id) }}"
67+
class="btn btn-info btn-sm">Edit</a>
68+
@endcan
69+
@can('delete user')
70+
<form action="{{ route('users.destroy', $user->id) }}" method="post"
71+
class="d-inline-block py-0">
72+
@csrf
73+
@method('DELETE')
74+
<x-backend.ui.button
75+
class="btn-danger btn-sm text-capitalize">Delete</x-backend.ui.button>
76+
</form>
77+
@endcan
78+
</td>
7579
@endcanany
76-
80+
7781
</tr>
7882
@endforeach
7983
</tbody>

0 commit comments

Comments
 (0)