mirror of https://github.com/4xmen/xshop.git
added question controller
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> </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
|
Loading…
Reference in New Issue