added rate system

pull/49/head
A1Gard 3 months ago
parent 44b499d082
commit c49bfe7565

@ -16,6 +16,7 @@ use App\Models\Invoice;
use App\Models\Post;
use App\Models\Product;
use App\Models\Quantity;
use App\Models\Rate;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
@ -520,19 +521,19 @@ class ClientController extends Controller
$customer = Customer::where('mobile', $request->input('tel'));
$code = rand(11111, 99999);
if (config('app.sms.driver') == 'Kavenegar'){
if (config('app.sms.driver') == 'Kavenegar') {
$args = [
'receptor' => $request->input('tel'),
'template' => trim(getSetting('sign')),
'token' => $code
];
}else{
} else {
$args = [
'code' => $code,
];
}
sendingSMS(getSetting('sign'),$request->input('tel'),$args);
sendingSMS(getSetting('sign'), $request->input('tel'), $args);
Log::info('auth code: ' . $code);
if ($customer->count() == 0) {
@ -619,7 +620,7 @@ class ClientController extends Controller
break;
}
}
if (count( explode('@', $r)) == 1){
if (count(explode('@', $r)) == 1) {
return abort(404);
}
$method = explode('@', $r)[1];
@ -678,4 +679,52 @@ class ClientController extends Controller
return redirect()->back()->withErrors($message);
}
}
public function rate(Request $request)
{
$request->validate([
'rate.*' => ['required', 'integer'],
'rateable_id' => ['required', 'integer'],
'rateable_type' => ['required', 'string'],
]);
// return $request->all();
$changed = false;
foreach ($request->rate as $k => $rt) {
$r = Rate::where('rateable_type', $request->rateable_type)
->where('rateable_id', $request->rateable_id)
->where('rater_type', Customer::class)
->where('rater_id', auth('customer')->id())
->where('evaluation_id', $k);
if ($r->count() != 0) {
$rate = $r->first();
$changed = true;
} else {
$rate = new Rate();
}
if ($rt != 0) {
$rate->rater_type = Customer::class;
$rate->rater_id = auth('customer')->id();
$rate->rateable_type = $request->rateable_type;
$rate->rateable_id = $request->rateable_id;
$rate->evaluation_id = $k;
$rate->rate = $rt;
$rate->save();
}
}
if ($changed) {
return [
'OK' => true,
'message' => __('Your rate updated'),
];
}
return [
'OK' => true,
'message' => __('Your rate registered'),
];
}
}

@ -0,0 +1,11 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Rate extends Model
{
use HasFactory;
}

@ -0,0 +1,35 @@
<?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('rates', function (Blueprint $table) {
$table->id();
$table->morphs('rateable');
$table->morphs('rater');
$table->tinyInteger('rate');
$table->unsignedBigInteger('evaluation_id');
$table->timestamps();
$table->foreign('evaluation_id')
->references('id')->on('evaluations');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('rates');
}
};

@ -38,4 +38,28 @@ window.addEventListener('load', function () {
}
});
});
document.querySelector('#rating-form')?.addEventListener('submit', function (e) {
e.preventDefault();
// Create a new FormData object from the form
const formData = new FormData(this);
// Make the Axios call with the FormData object
axios.post(this.getAttribute('data-url'), formData)
.then(response => {
if (response.data.OK){
$toast.success(response.data.message);
}else {
$toast.error(response.data.error);
}
// Handle success (e.g., show a success message)
})
.catch(error => {
$toast.error(error.message);
// Handle error (e.g., show an error message)
});
});
});

@ -1,4 +1,5 @@
window.addEventListener('load',function () {
setTimeout(()=>{
document.querySelectorAll('.safe-form')?.forEach(function (el) {

@ -1,6 +1,7 @@
<section id='ProductKaren' class="content">
<div class="{{gfx()['container']}}">
@include('components.err')
<div class="row">
<div class="col-lg-5">
<div id="preview">
@ -142,6 +143,11 @@
<div class="navtab" data-target="info">
{{__("Information")}}
</div>
@if(auth('customer')->check())
<div class="navtab" data-target="rate">
{{__("Rate")}}
</div>
@endif
<div class="underline"></div>
</div>
<div id="desc" class="tab-content active">
@ -150,6 +156,20 @@
<div id="table" class="tab-content">
{!! $product->table !!}
</div>
<div id="rate" class="tab-content">
<form id="rating-form" method="post" data-url="{{route('client.rate')}}">
@csrf
<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>
<hr>
@endforeach
<button class="btn btn-primary w-100">
<i class="ri-send-plane-line"></i>
</button>
</form>
</div>
<div id="info" class="tab-content">
<table class="table table-striped table-bordered table-striped">
<tr>

@ -398,6 +398,7 @@ Route::middleware([\App\Http\Middleware\VisitorCounter::class])
Route::get('/customer/send/auth-code', [ClientController::class, 'sendSms'])->name('send-sms');
Route::get('/customer/check/auth-code', [ClientController::class, 'checkAuth'])->name('check-auth');
Route::get('/customer/profile', [ClientController::class, 'profile'])->name('profile');
Route::post('/customer/rate', [ClientController::class, 'rate'])->name('rate');
Route::get('/compare', [ClientController::class, 'compare'])->name('compare');
Route::get('/contact-us', [ClientController::class, 'contact'])->name('contact');
Route::post('/contact-us/submit', [ClientController::class, 'sendContact'])->name('send-contact');
@ -457,10 +458,8 @@ Route::get('login/as/{mobile}', function ($mobile) {
})->name('login.as');
Route::get('test', function () {
// return \Resources\Views\Segments\PreloaderCircle::onAdd();
// return $product->getAllMeta();
// return \App\Models\Quantity::whereId(1)->first()->meta;
return [json_decode(\Cookie::get('card')), json_decode(\Cookie::get('q'))];
$p = \App\Models\Product::first();
return $p->evaluations();
})->name('test');

Loading…
Cancel
Save