added rate list to panel

added last rate history
improved security of rates
pull/49/head
A1Gard 3 months ago
parent c49bfe7565
commit d518446aef

@ -8,6 +8,7 @@ use App\Models\Area;
use App\Models\Part;
use App\Models\Menu;
use App\Models\Product;
use App\Models\Rate;
use Illuminate\Support\Facades\Route;
use GuzzleHttp\Client;
@ -1366,3 +1367,30 @@ function buildTOC($items) {
$html .= '</ul>';
return $html;
}
/**
* detect last rate of customer
* @param $type
* @param $id
* @param $evaluation
* @return int|mixed
*/
function detectRateCustomer($type,$id,$evaluation)
{
if (!auth('customer')->check()){
return 0;
}
$rate = Rate::where('rater_id',auth('customer')->id())
->where('rater_type', \App\Models\Customer::class)
->where('rateable_type',$type)
->where('rateable_id',$id)
->where('evaluation_id',$evaluation);
if ($rate->count() == 0){
return 0;
}else{
return $rate->first()->rate;
}
}

@ -0,0 +1,108 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Http\Controllers\XController;
use App\Http\Requests\RateSaveRequest;
use App\Models\Access;
use App\Models\Rate;
use Illuminate\Http\Request;
use App\Helper;
use function App\Helpers\hasCreateRoute;
class RateController extends XController
{
// protected $_MODEL_ = Rate::class;
// protected $SAVE_REQUEST = RateSaveRequest::class;
protected $cols = ['rateable_type', 'rateable_id', 'rater_type', 'rater_id', 'rate','evaluation_id'];
protected $extra_cols = ['id'];
protected $searchable = ['rate','rateable_type','rateable_id', 'rater_type', 'rater_id'];
protected $listView = 'admin.rates.rate-list';
protected $formView = 'admin.rates.rate-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(Rate::class, RateSaveRequest::class);
}
/**
* @param $rate Rate
* @param $request RateSaveRequest
* @return Rate
*/
public function save($rate, $request)
{
$rate->save();
return $rate;
}
/**
* 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(Rate $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;
default:
$msg = __('Unknown bulk action : :ACTION', ["ACTION" => $action]);
}
return $this->do_bulk($msg, $action, $ids);
}
public function destroy(Rate $item)
{
return parent::delete($item);
}
public function update(Request $request, Rate $item)
{
return $this->bringUp($request, $item);
}
}

@ -705,7 +705,7 @@ class ClientController extends Controller
} else {
$rate = new Rate();
}
if ($rt != 0) {
if ($rt > 0 && $rt < 5) {
$rate->rater_type = Customer::class;
$rate->rater_id = auth('customer')->id();
$rate->rateable_type = $request->rateable_type;

@ -0,0 +1,28 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class RateSaveRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return false;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
//
];
}
}

@ -8,4 +8,8 @@ use Illuminate\Database\Eloquent\Model;
class Rate extends Model
{
use HasFactory;
public function evaluation(){
return $this->belongsTo(Evaluation::class);
}
}

@ -356,6 +356,7 @@
"Questions": "سوالات",
"Questions list": "فهرست سوالات",
"RTL": "راست به چپ",
"Rate": "امتیاز",
"Read more": "اطلاعات بیشتر",
"Recent posts": "واپسین نوشته‌ها",
"Recommends": "توصیه‌ها",
@ -514,6 +515,8 @@
"Your message for this order...": "پیام شما ویژه این سفارش ...",
"Your message has been successfully sent.": "پیام شما با موفقیت ارسال شد",
"Your message...": "پیام شما...",
"Your rate registered": "امتیاز شما ثبت شد",
"Your rate updated": "امتیاز شما به‌روز شد",
"a minute ago": "یک دقیقه پیش",
"action": "فعالیت",
"address updated": "نشانی به روز شد",

@ -70,7 +70,7 @@
<label for="mid">
{{__("Model ID")}}
</label>
<input name="evaluationable_id" type="text"
<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)}}"/>

@ -0,0 +1,42 @@
@extends('admin.templates.panel-form-template')
@section('title')
@if(isset($item))
{{__("Edit rate")}} [{{$item->id}}]
@else
{{__("Add new rate")}}
@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>
</div>
<div class="col-lg-9 ps-xl-1 ps-xxl-1">
<div class="general-form ">
<h1>
@if(isset($item))
{{__("Edit rate")}} [{{$item->id}}]
@else
{{__("Add new rate")}}
@endif
</h1>
</div>
</div>
</div>
@endsection

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

@ -229,6 +229,15 @@
{{__("Removed")}}
@endif
@break
@case('evaluation_id')
@if($item->evaluation != null)
<a href="{{route('admin.evaluation.edit',$item->evaluation_id)}}">
{{ $item->evaluation?->title??'-' }}
</a>
@else
{{__("Removed")}}
@endif
@break
@case('expire')
@case('created_at')
@case('updated_at')
@ -244,6 +253,8 @@
@endif
@elseif(gettype($item->$col) == 'integer')
{{number_format($item->$col)}}
@elseif(strpos($col,'_type'))
{{str_replace('App\\Models\\', '' , $item->$col)}}
@else
{{$item->$col}}
@endif

@ -6,7 +6,7 @@
<i class="ri-home-smile-fill"></i>
</a>
</li>
@if( auth()->user()->hasAnyAccesses(['customer','invoice','discount']) )
@if( auth()->user()->hasAnyAccesses(['customer','invoice','discount','rate']) )
<li data-bs-toggle="tooltip" data-bs-placement="auto" data-bs-custom-class="custom-tooltip"
data-bs-title="{{__("Shopping card")}}">
<a href="#card">
@ -38,6 +38,14 @@
</a>
</li>
@endif
@if( auth()->user()->hasAnyAccess( 'rate' ))
<li>
<a href="{{ route('admin.rate.index') }}">
<i class="ri-star-half-line"></i>
{{__('Rate')}}
</a>
</li>
@endif
</ul>
</li>
@endif

@ -162,7 +162,7 @@
<input type="hidden" name="rateable_id" value="{{$product->id}}">
<input type="hidden" name="rateable_type" value="{{\App\Models\Product::class}}">
@foreach($product->evaluations() as $e)
<rate-input xtitle="{{$e->title}}" xname="rate[{{ $e->id }}]"></rate-input>
<rate-input xtitle="{{$e->title}}" xname="rate[{{ $e->id }}]" :xvalue="{{detectRateCustomer(\App\Models\Product::class,$product->id,$e->id)}}"></rate-input>
<hr>
@endforeach
<button class="btn btn-primary w-100">

@ -20,6 +20,7 @@ Route::prefix(config('app.panel.prefix'))->name('admin.')->group(
Route::post('ckeditor/upload', [\App\Http\Controllers\Admin\CkeditorController::class, 'upload'])->name('ckeditor.upload');
Route::get('adminlogs', [\App\Http\Controllers\Admin\AdminLogController::class, 'index'])->name('adminlog.index');
Route::get('rates', [\App\Http\Controllers\Admin\RateController::class, 'index'])->name('rate.index');
Route::get('adminlogs/{user}', [\App\Http\Controllers\Admin\AdminLogController::class, 'log'])->name('adminlog.show');
Route::post('images/store/{gallery}', [\App\Http\Controllers\Admin\ImageController::class, 'store'])->name('image.store');
Route::get('images/destroy/{image}', [\App\Http\Controllers\Admin\ImageController::class, 'destroy'])->name('image.destroy');

Loading…
Cancel
Save