diff --git a/app/Http/Controllers/Admin/AdminController.php b/app/Http/Controllers/Admin/AdminController.php index 9f5722eb..d4301845 100644 --- a/app/Http/Controllers/Admin/AdminController.php +++ b/app/Http/Controllers/Admin/AdminController.php @@ -5,6 +5,7 @@ use App\Http\Controllers\Controller; use App\Models\Order; use App\Models\Product; +use App\Models\CustomerQuestion; use Illuminate\Contracts\View\View; use Illuminate\Support\Facades\View as ViewFactory; @@ -16,6 +17,7 @@ public function dashboard(): View 'productsCount' => Product::count(), 'ordersCount' => Order::where('status', 'PENDING')->count(), 'readyToShipCount' => Order::where('status', 'READY TO SHIP')->count(), + 'customerQueryCount' => CustomerQuestion::whereNUll('reply')->count(), ]); } } diff --git a/app/Http/Controllers/Admin/CustomerQuestion/MessDelete.php b/app/Http/Controllers/Admin/CustomerQuestion/MessDelete.php new file mode 100644 index 00000000..99fb3232 --- /dev/null +++ b/app/Http/Controllers/Admin/CustomerQuestion/MessDelete.php @@ -0,0 +1,27 @@ +get('ids'); + + $questions = CustomerQuestion::whereIn('id', $ids)->get(['id']); + + foreach ($questions as $order) { + $order->delete(); + } + + Alert::toast('Removed', 'success'); + + return Redirect::route('customerQuestion.adminView'); + } +} diff --git a/app/Http/Controllers/Admin/CustomerQuestion/Reply.php b/app/Http/Controllers/Admin/CustomerQuestion/Reply.php new file mode 100644 index 00000000..6f414890 --- /dev/null +++ b/app/Http/Controllers/Admin/CustomerQuestion/Reply.php @@ -0,0 +1,24 @@ +update([ + 'reply' => $request->reply, + ]); + + return Redirect::route('customerQuestion.adminView'); + } +} diff --git a/app/Http/Controllers/Admin/CustomerQuestion/ReplyView.php b/app/Http/Controllers/Admin/CustomerQuestion/ReplyView.php new file mode 100644 index 00000000..1018ff73 --- /dev/null +++ b/app/Http/Controllers/Admin/CustomerQuestion/ReplyView.php @@ -0,0 +1,19 @@ +with('user', 'product.productImage') + ->first(); + + return ViewFactory::make('admin.customer.reply', compact('question')); + } +} diff --git a/app/Http/Controllers/Api/CustomerQuestionApi.php b/app/Http/Controllers/Api/CustomerQuestionApi.php new file mode 100644 index 00000000..738f6ac9 --- /dev/null +++ b/app/Http/Controllers/Api/CustomerQuestionApi.php @@ -0,0 +1,38 @@ +get(); + + return DataTables::of($questions) + ->addColumn('select', function ($row) { + $item = ' + '; + return $item; + }) + ->addColumn('created_at', function ($row) { + return date('d/m/Y h:i A', strtotime($row->created_at)); + }) + ->addColumn('reply', function ($row) { + $class = $row->reply ? 'text-danger' : 'text-danger'; + $val = $row->reply ?? '
pending
'; + return $val; + }) + ->addColumn('action', function ($row) { + $item = 'Reply + '; + return $item; + }) + + ->rawColumns(['select', 'action', 'reply']) + ->make(true); + } +} diff --git a/app/Http/Controllers/User/CustomerQuestion/Destroy.php b/app/Http/Controllers/User/CustomerQuestion/Destroy.php new file mode 100644 index 00000000..1e5d46e3 --- /dev/null +++ b/app/Http/Controllers/User/CustomerQuestion/Destroy.php @@ -0,0 +1,28 @@ +questions() + ->where('id', $id) + ->delete(); + + Alert::toast('Deleted!', 'success'); + + return Redirect::route('customerQuestion.index'); + } +} diff --git a/app/Http/Controllers/User/CustomerQuestion/Index.php b/app/Http/Controllers/User/CustomerQuestion/Index.php new file mode 100644 index 00000000..fae9fc69 --- /dev/null +++ b/app/Http/Controllers/User/CustomerQuestion/Index.php @@ -0,0 +1,26 @@ +questions() + ->with('product') + ->paginate(20); + + return ViewFactory::make('customer-question.index')->with([ + 'questions' => $questions, + ]); + } +} diff --git a/app/Http/Controllers/User/CustomerQuestion/Store.php b/app/Http/Controllers/User/CustomerQuestion/Store.php new file mode 100644 index 00000000..690a6aa7 --- /dev/null +++ b/app/Http/Controllers/User/CustomerQuestion/Store.php @@ -0,0 +1,32 @@ +validate([ + 'question' => 'required|max:255', + ]); + //product imported to redirect to its path + $product = Product::findOrFail($request->product_id); + + $question = new CustomerQuestion(); + $question->user_id = auth()->user()->id; + $question->product_id = $request->product_id; + $question->question = $request->question; + $question->save(); + + return Redirect::to($product->path()); + } +} diff --git a/app/Http/Controllers/User/ShowProduct.php b/app/Http/Controllers/User/ShowProduct.php index eebe41d5..bbe0a4a2 100644 --- a/app/Http/Controllers/User/ShowProduct.php +++ b/app/Http/Controllers/User/ShowProduct.php @@ -20,6 +20,11 @@ public function __invoke($id): View ->with('productImage') ->first(); + $questions = $product + ->getQuestions() + ->with('user') + ->paginate(6); + $mightAlsoLike = Product::where('id', '!=', $product->id) ->inRandomOrder() ->with('productImage') @@ -28,6 +33,7 @@ public function __invoke($id): View return ViewFactory::make('shop.show')->with([ 'product' => $product, + 'questions' => $questions, 'mightAlsoLike' => $mightAlsoLike ]); } diff --git a/app/Http/Requests/Admin/ReplyCustomerQuestionRequest.php b/app/Http/Requests/Admin/ReplyCustomerQuestionRequest.php new file mode 100644 index 00000000..6e204e25 --- /dev/null +++ b/app/Http/Requests/Admin/ReplyCustomerQuestionRequest.php @@ -0,0 +1,23 @@ + 'required|max:255', + ]; + } +} diff --git a/app/Models/CustomerQuestion.php b/app/Models/CustomerQuestion.php new file mode 100644 index 00000000..d06c189f --- /dev/null +++ b/app/Models/CustomerQuestion.php @@ -0,0 +1,36 @@ +belongsTo(Product::class); + } + + public function user(): BelongsTo + { + return $this->belongsTo(User::class); + } +} diff --git a/app/Models/Product.php b/app/Models/Product.php index c3c2aa74..1a6db01b 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -3,9 +3,9 @@ namespace App\Models; use Carbon\Carbon; -use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Support\Collection; use Illuminate\Support\Facades\URL; @@ -54,6 +54,11 @@ public function getImage(): HasMany return $this->productImage(); } + public function getQuestions(): HasMany + { + return $this->hasMany(CustomerQuestion::class); + } + public function scopeMightAlsoLike($query) { return $query->inRandomOrder()->with('first_image')->take(4); diff --git a/app/Models/User.php b/app/Models/User.php index 7805db35..283cffc3 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -74,4 +74,9 @@ public function orders(): HasMany { return $this->hasMany(Order::class); } + + public function questions(): HasMany + { + return $this->hasMany(CustomerQuestion::class); + } } diff --git a/database/migrations/2023_07_01_000000_create_customer_questions_table.php b/database/migrations/2023_07_01_000000_create_customer_questions_table.php new file mode 100644 index 00000000..dd0a973d --- /dev/null +++ b/database/migrations/2023_07_01_000000_create_customer_questions_table.php @@ -0,0 +1,25 @@ +id(); + $table->unsignedBigInteger('user_id'); + $table->unsignedBigInteger('product_id'); + $table->string('question'); + $table->string('reply')->nullable(); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists('customer_questions'); + } +} diff --git a/resources/views/admin/customer/customer-question.blade.php b/resources/views/admin/customer/customer-question.blade.php new file mode 100644 index 00000000..49f58ea1 --- /dev/null +++ b/resources/views/admin/customer/customer-question.blade.php @@ -0,0 +1,84 @@ +@extends('layouts.admin') + +@section('content') +Price : Rs.{{number_format($question->product->price)}}
+Sale Price : Rs.{{number_format($question->product->sale_price)}}
+ @else +Price : Rs.{{number_format($question->product->price)}}
+ @endif +Product queries
+Product title | +Question | +Reply | +Created_at | +Action | +|
---|---|---|---|---|---|
{{$question->product->title}} | +{{$question->question}} | +{{$question->reply ?? 'pending' }} | +{{$question->created_at->diffForHumans()}} | ++ + | +|
No questions made on the products yet. | ++ | + | + | + | + |
There are not questions yet.
+