added question controller

pull/44/head
A1Gard 6 months ago
parent 3d0f49be0c
commit 3bfdd29e17

@ -0,0 +1,118 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Http\Controllers\XController;
use App\Http\Requests\QuestionSaveRequest;
use App\Models\Access;
use App\Models\Question;
use Illuminate\Http\Request;
use App\Helper;
use function App\Helpers\hasCreateRoute;
class QuestionController extends XController
{
// protected $_MODEL_ = Question::class;
// protected $SAVE_REQUEST = QuestionSaveRequest::class;
protected $cols = ['body','product_id','status'];
protected $extra_cols = ['id'];
protected $searchable = ['body','answer'];
protected $listView = 'admin.questions.question-list';
protected $formView = 'admin.questions.question-form';
protected $buttons = [
'edit' =>
['title' => "Edit", 'class' => 'btn-outline-primary', 'icon' => 'ri-edit-2-line'],
// 'show' =>
// ['title' => "Detail", 'class' => 'btn-outline-light', 'icon' => 'ri-eye-line'],
'destroy' =>
['title' => "Remove", 'class' => 'btn-outline-danger delete-confirm', 'icon' => 'ri-close-line'],
];
public function __construct()
{
parent::__construct(Question::class, QuestionSaveRequest::class);
}
/**
* @param $question Question
* @param $request QuestionSaveRequest
* @return Question
*/
public function save($question, $request)
{
$question->body = $request->input('body');
$question->answer = $request->input('answer');
$question->status = $request->input('status');
$question->save();
return $question;
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
return view($this->formView);
}
/**
* Show the form for editing the specified resource.
*/
public function edit(Question $item)
{
//
return view($this->formView, compact('item'));
}
public function bulk(Request $request)
{
// dd($request->all());
$data = explode('.', $request->input('action'));
$action = $data[0];
$ids = $request->input('id');
switch ($action) {
case 'delete':
$msg = __(':COUNT items deleted successfully', ['COUNT' => count($ids)]);
$this->_MODEL_::destroy($ids);
break;
case 'publish':
$this->_MODEL_::whereIn('id', $request->input('id'))->update(['status' => 1]);
$msg = __(':COUNT items published successfully', ['COUNT' => count($ids)]);
break;
case 'draft':
$this->_MODEL_::whereIn('id', $request->input('id'))->update(['status' => 0]);
$msg = __(':COUNT items drafted successfully', ['COUNT' => count($ids)]);
break;
default:
$msg = __('Unknown bulk action : :ACTION', ["ACTION" => $action]);
}
return $this->do_bulk($msg, $action, $ids);
}
public function destroy(Question $item)
{
return parent::delete($item);
}
public function update(Request $request, Question $item)
{
return $this->bringUp($request, $item);
}
}

@ -0,0 +1,31 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class QuestionSaveRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return auth()->check();
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
//
'body' => ['required','string'],
'answer' => ['nullable','string'],
'status' => ['nullable','boolean'],
];
}
}

@ -0,0 +1,103 @@
@extends('admin.templates.panel-form-template')
@section('title')
@if(isset($item))
{{__("Edit question")}} [{{$item->id}}]
@else
{{__("Add new question")}}
@endif -
@endsection
@section('form')
<div class="row">
<div class="col-lg-3">
@include('components.err')
<div class="item-list mb-3">
<h3 class="p-3">
<i class="ri-message-3-line"></i>
{{__("Tips")}}
</h3>
<ul>
<li>
{{__("Recommends")}}
</li>
</ul>
</div>
@if(isset($item))
<div class="item-list mb-3">
<h3 class="p-3">
<i class="ri-info-i"></i>
{{__("Information")}}
</h3>
<ul>
<li>
{{__("Added by:")}}
<a href="{{route('admin.customer.edit',$item->customer->id)}}">
{{$item->customer->name}}
</a>
</li>
<li>
{{__("Question for:")}}
<a href="{{route('admin.product.edit',$item->product->id)}}">
{{$item->product->name}}
</a>
</li>
</ul>
</div>
@endif
</div>
<div class="col-lg-9 ps-xl-1 ps-xxl-1">
<div class="general-form ">
<h1>
@if(isset($item))
{{__("Edit question")}} [{{$item->id}}]
@else
{{__("Add new question")}}
@endif
</h1>
<div class="row">
<div class="col-md-12 mt-3">
<div class="form-group">
<label for="body" >
{{__('Question')}}
</label>
<textarea name="body" id="body" class="form-control @error('body') is-invalid @enderror" placeholder="{{__('Question')}}" >{{old('body',$item->body??null)}}</textarea>
</div>
</div>
<div class="col-md-12 mt-3">
<div class="form-group">
<label for="answer" >
{{__('Answer')}}
</label>
<textarea name="answer" id="answer" class="form-control @error('answer') is-invalid @enderror" placeholder="{{__('Answer')}}" >{{old('answer',$item->answer??null)}}</textarea>
</div>
</div>
<div class="col-md-12 mt-3">
<div class="form-group">
<label for="status">
{{__('Status')}}
</label>
<select name="status" id="status"
class="form-control @error('status') is-invalid @enderror">
<option value="1"
@if (old('status',$item->status??null) == '1' ) selected @endif >{{__("Published")}} </option>
<option value="0"
@if (old('status',$item->status??null) == '0' ) selected @endif >{{__("Draft")}} </option>
</select>
</div>
</div>
<div class="col-md-12">
<label> &nbsp;</label>
<input name="" type="submit" class="btn btn-primary mt-2" value="{{__('Save')}}"/>
</div>
</div>
</div>
</div>
</div>
@endsection

@ -0,0 +1,17 @@
@extends('admin.templates.panel-list-template')
@section('list-title')
<i class="ri-user-3-line"></i>
{{__("Questions list")}}
@endsection
@section('title')
{{__("Questions list")}} -
@endsection
@section('filter')
{{-- Other filters --}}
@endsection
@section('bulk')
{{-- <option value="-"> - </option> --}}
<option value="publish"> {{__("Publish")}} </option>
<option value="draft"> {{__("Draft")}} </option>
@endsection

@ -178,7 +178,7 @@
{{ $item->parent?->{$cols[0]}??'-' }} {{ $item->parent?->{$cols[0]}??'-' }}
@break @break
@case($col == 'status') @case($col == 'status')
<div class="model-status status-{{$item->status}}"></div> <div class="model-status status-{{$item->status}} float-start"></div>
@break @break
@case($col == 'user_id') @case($col == 'user_id')
<a href="{{route('admin.user.edit',$item->user?->email)}}"> <a href="{{route('admin.user.edit',$item->user?->email)}}">

@ -149,7 +149,7 @@
</a> </a>
<ul id="interaction"> <ul id="interaction">
<li> <li>
<a href=""> <a href="{{route('admin.question.index')}}">
<i class="ri-question-mark"></i> <i class="ri-question-mark"></i>
{{__('Questions')}} {{__('Questions')}}
</a> </a>

@ -77,6 +77,17 @@ Route::prefix(config('app.panel.prefix'))->name('admin.')->group(
Route::post('bulk', [\App\Http\Controllers\Admin\TransportController::class, "bulk"])->name('bulk'); Route::post('bulk', [\App\Http\Controllers\Admin\TransportController::class, "bulk"])->name('bulk');
Route::get('trashed', [\App\Http\Controllers\Admin\TransportController::class, "trashed"])->name('trashed'); Route::get('trashed', [\App\Http\Controllers\Admin\TransportController::class, "trashed"])->name('trashed');
}); });
Route::prefix('questions')->name('question.')->group(
function () {
Route::get('', [\App\Http\Controllers\Admin\QuestionController::class, 'index'])->name('index');
// Route::get('create', [\App\Http\Controllers\Admin\TransportController::class, 'create'])->name('create');
// Route::post('store', [\App\Http\Controllers\Admin\TransportController::class, 'store'])->name('store');
Route::get('edit/{item}', [\App\Http\Controllers\Admin\QuestionController::class, 'edit'])->name('edit');
Route::post('update/{item}', [\App\Http\Controllers\Admin\QuestionController::class, 'update'])->name('update');
Route::get('delete/{item}', [\App\Http\Controllers\Admin\QuestionController::class, 'destroy'])->name('destroy');
// Route::get('restore/{item}', [\App\Http\Controllers\Admin\QuestionController::class, 'restore'])->name('restore');
Route::post('bulk', [\App\Http\Controllers\Admin\QuestionController::class, "bulk"])->name('bulk');
});
Route::prefix('categories')->name('category.')->group( Route::prefix('categories')->name('category.')->group(
function () { function () {

Loading…
Cancel
Save