mirror of https://github.com/4xmen/xshop.git
added evaluation to project
parent
5eff6259d9
commit
9ceeb619a6
@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\XController;
|
||||
use App\Http\Requests\EvaluationSaveRequest;
|
||||
use App\Models\Access;
|
||||
use App\Models\Evaluation;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Helper;
|
||||
use function App\Helpers\hasCreateRoute;
|
||||
|
||||
class EvaluationController extends XController
|
||||
{
|
||||
|
||||
// protected $_MODEL_ = Evaluation::class;
|
||||
// protected $SAVE_REQUEST = EvaluationSaveRequest::class;
|
||||
|
||||
protected $cols = ['title'];
|
||||
protected $extra_cols = ['id'];
|
||||
|
||||
protected $searchable = ['title'];
|
||||
|
||||
protected $listView = 'admin.evaluations.evaluation-list';
|
||||
protected $formView = 'admin.evaluations.evaluation-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(Evaluation::class, EvaluationSaveRequest::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $evaluation Evaluation
|
||||
* @param $request EvaluationSaveRequest
|
||||
* @return Evaluation
|
||||
*/
|
||||
public function save($evaluation, $request)
|
||||
{
|
||||
|
||||
$evaluation->title = $request->title;
|
||||
if ($request->evaluationable_type == null || $request->evaluationable_type == '') {
|
||||
$evaluation->evaluationable_type = null;
|
||||
}else{
|
||||
$evaluation->evaluationable_type = $request->evaluationable_type ;
|
||||
}
|
||||
if ($request->evaluationable_id == null || $request->evaluationable_id == '') {
|
||||
$evaluation->evaluationable_id = null;
|
||||
}else{
|
||||
$evaluation->evaluationable_id = $request->evaluationable_id ;
|
||||
|
||||
}
|
||||
$evaluation->save();
|
||||
return $evaluation;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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(Evaluation $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;
|
||||
/**restore*/
|
||||
case 'restore':
|
||||
$msg = __(':COUNT items restored successfully', ['COUNT' => count($ids)]);
|
||||
foreach ($ids as $id) {
|
||||
$this->_MODEL_::withTrashed()->find($id)->restore();
|
||||
}
|
||||
break;
|
||||
/*restore**/
|
||||
default:
|
||||
$msg = __('Unknown bulk action : :ACTION', ["ACTION" => $action]);
|
||||
}
|
||||
|
||||
return $this->do_bulk($msg, $action, $ids);
|
||||
}
|
||||
|
||||
public function destroy(Evaluation $item)
|
||||
{
|
||||
return parent::delete($item);
|
||||
}
|
||||
|
||||
|
||||
public function update(Request $request, Evaluation $item)
|
||||
{
|
||||
return $this->bringUp($request, $item);
|
||||
}
|
||||
|
||||
/**restore*/
|
||||
public function restore($item)
|
||||
{
|
||||
return parent::restoreing(Evaluation::withTrashed()->where('id', $item)->first());
|
||||
}
|
||||
/*restore**/
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class EvaluationSaveRequest 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 [
|
||||
'title' => ['required', 'string','min:2'],
|
||||
];
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Spatie\Translatable\HasTranslations;
|
||||
|
||||
class Evaluation extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes, HasTranslations;
|
||||
|
||||
public $translatable = ['title'];
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Evaluation>
|
||||
*/
|
||||
class EvaluationFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('evaluations', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('title');
|
||||
$table->nullableMorphs('evaluationable');
|
||||
$table->softDeletes();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('evaluations');
|
||||
}
|
||||
};
|
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Category;
|
||||
use App\Models\Evaluation;
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class EvaluationSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
//
|
||||
$e = new Evaluation();
|
||||
$e->title = __('Quality');
|
||||
$e->save();
|
||||
|
||||
|
||||
$e = new Evaluation();
|
||||
$e->title = __('Packing');
|
||||
$e->evaluationable_type = Category::class;
|
||||
$e->evaluationable_id = 1;
|
||||
$e->save();
|
||||
}
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
@extends('admin.templates.panel-form-template')
|
||||
@section('title')
|
||||
@if(isset($item))
|
||||
{{__("Edit evaluation")}} [{{$item->title}}]
|
||||
@else
|
||||
{{__("Add new evaluation")}}
|
||||
@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>
|
||||
{{__("Leave model ID empty to apply all items")}}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="col-lg-9 ps-xl-1 ps-xxl-1">
|
||||
<div class="general-form ">
|
||||
|
||||
<h1>
|
||||
@if(isset($item))
|
||||
{{__("Edit evaluation")}} [{{$item->title}}]
|
||||
@else
|
||||
{{__("Add new evaluation")}}
|
||||
@endif
|
||||
</h1>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12 mt-3">
|
||||
<div class="form-group">
|
||||
<label for="title">
|
||||
{{__('Title')}}
|
||||
</label>
|
||||
<input name="title" type="text"
|
||||
class="form-control @error('title') is-invalid @enderror"
|
||||
placeholder="{{__('Title')}}" value="{{old('title',$item->title??null)}}"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6 mt-3">
|
||||
<div class="form-group">
|
||||
<label for="model">
|
||||
{{__("Model")}}
|
||||
</label>
|
||||
<select name="evaluationable_type" id="model" class="form-control">
|
||||
<option value=""> {{__("All")}} </option>
|
||||
<option value="{{\App\Models\User::class}}" @if(\App\Models\User::class == old('evaluationable_type',$item->evaluationable_type??null)) selected @endif> {{__("User")}} </option>
|
||||
<option value="{{\App\Models\Customer::class}}" @if(\App\Models\Customer::class == old('evaluationable_type',$item->evaluationable_type??null)) selected @endif> {{__("Customer")}} </option>
|
||||
<option value="{{\App\Models\Post::class}}" @if(\App\Models\Post::class == old('evaluationable_type',$item->evaluationable_type??null)) selected @endif> {{__("Post")}} </option>
|
||||
<option value="{{\App\Models\Product::class}}" @if(\App\Models\Product::class == old('evaluationable_type',$item->evaluationable_type??null)) selected @endif> {{__("Product")}} </option>
|
||||
<option value="{{\App\Models\Category::class}}" @if(\App\Models\Category::class == old('evaluationable_type',$item->evaluationable_type??null)) selected @endif> {{__("Category")}} </option>
|
||||
<option value="{{\App\Models\Group::class}}" @if(\App\Models\Group::class == old('evaluationable_type',$item->evaluationable_type??null)) selected @endif> {{__("Group")}} </option>
|
||||
<option value="{{\App\Models\Invoice::class}}" @if(\App\Models\Invoice::class == old('evaluationable_type',$item->evaluationable_type??null)) selected @endif> {{__("Invoice")}} </option>
|
||||
<option value="{{\App\Models\Ticket::class}}" @if(\App\Models\Ticket::class == old('evaluationable_type',$item->evaluationable_type??null)) selected @endif> {{__("Tickets")}} </option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6 mt-3">
|
||||
<div class="form-group">
|
||||
<label for="mid">
|
||||
{{__("Model ID")}}
|
||||
</label>
|
||||
<input name="evaluationable_id" type="text"
|
||||
id="mid"
|
||||
class="form-control @error('evaluationable_id') is-invalid @enderror"
|
||||
placeholder="{{__('Model ID')}}" value="{{old('evaluationable_id',$item->evaluationable_id??null)}}"/>
|
||||
</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,15 @@
|
||||
@extends('admin.templates.panel-list-template')
|
||||
|
||||
@section('list-title')
|
||||
<i class="ri-user-3-line"></i>
|
||||
{{__("Evaluations list")}}
|
||||
@endsection
|
||||
@section('title')
|
||||
{{__("Evaluations list")}} -
|
||||
@endsection
|
||||
@section('filter')
|
||||
{{-- Other filters --}}
|
||||
@endsection
|
||||
@section('bulk')
|
||||
{{-- <option value="-"> - </option> --}}
|
||||
@endsection
|
Loading…
Reference in New Issue