forked from nishangupta/Mart
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
748 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
app/Http/Controllers/Admin/CustomerQuestion/MessDelete.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Admin\CustomerQuestion; | ||
|
||
use App\Models\CustomerQuestion; | ||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Redirect; | ||
use RealRashid\SweetAlert\Facades\Alert; | ||
|
||
class MessDelete | ||
{ | ||
public function __invoke(Request $request): RedirectResponse | ||
{ | ||
$ids = $request->get('ids'); | ||
|
||
$questions = CustomerQuestion::whereIn('id', $ids)->get(['id']); | ||
|
||
foreach ($questions as $order) { | ||
$order->delete(); | ||
} | ||
|
||
Alert::toast('Removed', 'success'); | ||
|
||
return Redirect::route('customerQuestion.adminView'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Admin\CustomerQuestion; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Http\Requests\Admin\ReplyCustomerQuestionRequest; | ||
use App\Models\CustomerQuestion; | ||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Support\Facades\Redirect; | ||
|
||
/** | ||
* 管理者回應客戶的問題 | ||
*/ | ||
class Reply extends Controller | ||
{ | ||
public function __invoke(CustomerQuestion $question, ReplyCustomerQuestionRequest $request): RedirectResponse | ||
{ | ||
$question->update([ | ||
'reply' => $request->reply, | ||
]); | ||
|
||
return Redirect::route('customerQuestion.adminView'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Admin\CustomerQuestion; | ||
|
||
use App\Models\CustomerQuestion; | ||
use Illuminate\Contracts\View\View; | ||
use Illuminate\Support\Facades\View as ViewFactory; | ||
|
||
class ReplyView | ||
{ | ||
public function __invoke($id): View | ||
{ | ||
$question = CustomerQuestion::where('id', $id) | ||
->with('user', 'product.productImage') | ||
->first(); | ||
|
||
return ViewFactory::make('admin.customer.reply', compact('question')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Models\CustomerQuestion; | ||
use Yajra\DataTables\DataTables; | ||
|
||
class CustomerQuestionApi extends Controller | ||
{ | ||
public function __invoke() | ||
{ | ||
$questions = CustomerQuestion::latest()->get(); | ||
|
||
return DataTables::of($questions) | ||
->addColumn('select', function ($row) { | ||
$item = '<input type="checkbox" name="ids[]" class="selectbox" value="' . $row->id . '"> | ||
'; | ||
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 ?? '<p class="' . $class . '">pending</p>'; | ||
return $val; | ||
}) | ||
->addColumn('action', function ($row) { | ||
$item = '<a href="/admin/customer-question/' . $row->id . '/reply" class="btn btn-sm btn-success">Reply</a> | ||
'; | ||
return $item; | ||
}) | ||
|
||
->rawColumns(['select', 'action', 'reply']) | ||
->make(true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\User\CustomerQuestion; | ||
|
||
use App\Models\User; | ||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Support\Facades\Redirect; | ||
use RealRashid\SweetAlert\Facades\Alert; | ||
|
||
/** | ||
* DELETE /customer-question/{id} | ||
*/ | ||
class Destroy | ||
{ | ||
public function __invoke($id): RedirectResponse | ||
{ | ||
/** @var User $user */ | ||
$user = Auth::user(); | ||
$user->questions() | ||
->where('id', $id) | ||
->delete(); | ||
|
||
Alert::toast('Deleted!', 'success'); | ||
|
||
return Redirect::route('customerQuestion.index'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\User\CustomerQuestion; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Models\User; | ||
use Illuminate\Contracts\View\View; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Support\Facades\View as ViewFactory; | ||
|
||
class Index extends Controller | ||
{ | ||
public function __invoke(): View | ||
{ | ||
/** @var User $user */ | ||
$user = Auth::user(); | ||
|
||
$questions = $user->questions() | ||
->with('product') | ||
->paginate(20); | ||
|
||
return ViewFactory::make('customer-question.index')->with([ | ||
'questions' => $questions, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\User\CustomerQuestion; | ||
|
||
use App\Models\CustomerQuestion; | ||
use App\Models\Product; | ||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Redirect; | ||
|
||
/** | ||
* POST /customer-question | ||
*/ | ||
class Store | ||
{ | ||
public function __invoke(Request $request): RedirectResponse | ||
{ | ||
$request->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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests\Admin; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
/** | ||
* @property string reply | ||
*/ | ||
class ReplyCustomerQuestionRequest extends FormRequest | ||
{ | ||
public function authorize(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
public function rules(): array | ||
{ | ||
return [ | ||
'reply' => 'required|max:255', | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Carbon\Carbon; | ||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
|
||
/** | ||
* @property int id | ||
* @property int user_id | ||
* @property int product_id | ||
* @property string question | ||
* @property string reply | ||
* @property Carbon created_at | ||
* @property Carbon updated_at | ||
* @property Product product | ||
* @property User user | ||
*/ | ||
class CustomerQuestion extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $guarded = []; | ||
|
||
public function product(): BelongsTo | ||
{ | ||
return $this->belongsTo(Product::class); | ||
} | ||
|
||
public function user(): BelongsTo | ||
{ | ||
return $this->belongsTo(User::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
database/migrations/2023_07_01_000000_create_customer_questions_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class CreateCustomerQuestionsTable extends Migration | ||
{ | ||
public function up(): void | ||
{ | ||
Schema::create('customer_questions', function (Blueprint $table) { | ||
$table->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'); | ||
} | ||
} |
Oops, something went wrong.