added evaluation to project

pull/49/head
A1Gard 3 months ago
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');
}
};

@ -42,6 +42,7 @@ class DatabaseSeeder extends Seeder
MenuSeeder::class,
SliderSeeder::class,
PartSeeder::class,
EvaluationSeeder::class,
]
);
}

@ -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();
}
}

@ -34,9 +34,10 @@
"Add new contact": "افزودن یک تماس",
"Add new customer": "افزودن یک مشتری",
"Add new discount": "افزودن یک تخفیف",
"Add new evaluation": "افزودن یک ارزیابی",
"Add new gallery": "افزودن یک گالری",
"Add new group": "افزودن یک سرفصل",
"Add new invoice": "",
"Add new invoice": "افزودن یک صورت حساب",
"Add new language": "افزودن یک زبان جدید",
"Add new menu": "افزودن فهرست جدید",
"Add new post": "افزودن یک نوشته",
@ -66,6 +67,7 @@
"Advertise": "تبلیغ",
"Advs": "تبلیغات",
"Advs list": "فهرست تبلیغات",
"All": "همه",
"All products": "تمامی محصولات",
"Amount": "میزان",
"Answer": "پاسخ",
@ -179,6 +181,7 @@
"Edit contact": "ویرایش تماس",
"Edit customer": "ویرایش مشتری",
"Edit discount": "ویرایش تخفیف",
"Edit evaluation": "ویرایش ارزیابی",
"Edit gallery": "ویرایش گالری",
"Edit group": "ویرایش سرفصل",
"Edit invoice": "",
@ -197,12 +200,14 @@
"Email Address": "نشانی ایمیل",
"Email or password is incorrect": "نام رایانامه یا گذرواژه اشتباه است",
"Emoji": "ایموجی",
"Evaluations": "ارزیابی‌ها",
"Evaluations list": "فهرست ارزیابی‌ها",
"Excerpt": "خلاصه",
"Expire": "انقضا",
"Expire date": "تاریخ انقضا",
"Expire date": "تاریخ انقضا",
"Extra description": "توضیحات اضافه",
"Failed Invoices": "",
"Failed Invoices": "صورت حساب‌های ناموفق",
"False": "خیر",
"Favorites": "علاقه‌مندی‌ها",
"Feature image": "تصویر شاخص",
@ -274,6 +279,7 @@
"Latest ": "واپسین ",
"Latest products": "واپسین محصولات",
"Latitude": "عرض جغرافیایی",
"Leave model ID empty to apply all items": "اگر قصد دارید ارزیابی بر روی تمام موارد مدل اعمال شود آن‌را خالی رها کنید",
"Link": "پیوند",
"Login": "ورود",
"Logout": "خروج",
@ -295,6 +301,7 @@
"Message...": "پیام...",
"Mobile": "موبایل",
"Model": "ماژول",
"Model ID": "ID مدل",
"Name": "نام",
"Name and lastname": "نام و نام‌خانوادگی",
"Need process orders": "سفارشات نیازمند رسیدگی",
@ -463,6 +470,7 @@
"Upload images": "بارگزاری تصاویر",
"Upload new images": "بارگزاری تصاویر جدید",
"Use default": "استفاده از پیش فرض ها",
"User": "کاربر",
"User filter": "صافی کاربر",
"Users": "کاربران",
"Users list": "فهرست کاربران",
@ -520,6 +528,7 @@
"emoji": "ایموجی",
"error in payment.": "خطا در پرداخت",
"error in payment. contact admin.": "خطا در پرداخت با مدیر وبسایت تماس بگیرید",
"evaluation": "ارزیابی",
"image": "تصویر",
"invoice": "صورت حساب",
"jpg": "",

@ -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> &nbsp;</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

@ -42,7 +42,7 @@
</li>
@endif
@if( auth()->user()->hasAnyAccesses(['product','category','prop','transport']) )
@if( auth()->user()->hasAnyAccesses(['product','category','prop','transport','evaluation']) )
<li data-bs-toggle="tooltip" data-bs-placement="auto" data-bs-custom-class="custom-tooltip"
data-bs-title="{{__("Catalog")}}">
<a href="#catalog">
@ -81,6 +81,14 @@
</a>
</li>
@endif
@if( auth()->user()->hasAnyAccess( 'evaluation' ))
<li>
<a href="{{ route('admin.evaluation.index') }}">
<i class="ri-star-half-line"></i>
{{__('Evaluations')}}
</a>
</li>
@endif
</ul>
</li>

@ -66,6 +66,19 @@ Route::prefix(config('app.panel.prefix'))->name('admin.')->group(
Route::post('bulk', [\App\Http\Controllers\Admin\DiscountController::class, "bulk"])->name('bulk');
Route::get('trashed', [\App\Http\Controllers\Admin\DiscountController::class, "trashed"])->name('trashed');
});
Route::prefix('evaluations')->name('evaluation.')->group(
function () {
Route::get('', [\App\Http\Controllers\Admin\EvaluationController::class, 'index'])->name('index');
Route::get('create', [\App\Http\Controllers\Admin\EvaluationController::class, 'create'])->name('create');
Route::post('store', [\App\Http\Controllers\Admin\EvaluationController::class, 'store'])->name('store');
Route::get('edit/{item}', [\App\Http\Controllers\Admin\EvaluationController::class, 'edit'])->name('edit');
Route::post('update/{item}', [\App\Http\Controllers\Admin\EvaluationController::class, 'update'])->name('update');
Route::get('delete/{item}', [\App\Http\Controllers\Admin\EvaluationController::class, 'destroy'])->name('destroy');
Route::get('restore/{item}', [\App\Http\Controllers\Admin\EvaluationController::class, 'restore'])->name('restore');
Route::post('bulk', [\App\Http\Controllers\Admin\EvaluationController::class, "bulk"])->name('bulk');
Route::get('trashed', [\App\Http\Controllers\Admin\EvaluationController::class, "trashed"])->name('trashed');
});
Route::prefix('tags')->name('tag.')->group(
function () {
Route::get('', [\App\Http\Controllers\Admin\TagController::class, 'index'])->name('index');

Loading…
Cancel
Save