Middleware Rating Create

Ada comment // UPDATE CLIENT DEVIVE FOR RATING itu updatannya
mail@pastecode.io avatar
unknown
php
2 years ago
1.5 kB
2
Indexable
Never
<?php

namespace App\Http\Middleware\Api\Rating;

use App\Http\Middleware\BaseMiddleware;
use App\Models\Rating;
use Carbon\Carbon;
use Illuminate\Support\Facades\Validator;

class Create extends BaseMiddleware
{
    public function initiate() {
        $this->Model->Rating = new Rating();
        $this->Model->Rating->rating_val = $this->_Request->input('rating_val');
        $this->Model->Rating->rating_comment = " ";
        $this->Model->Rating->user_name = $this->_Request->Me->USERNAME;
        $this->Model->Rating->rating_date = Carbon::now();
        $this->Model->Rating->NAME = $this->_Request->Me->USERNAME;
        $this->Model->Rating->stat = 1;
        $this->Model->Rating->qa_rating_id = 14;
        $this->Model->Rating->rating_periode = 14;
        // UPDATE CLIENT DEVICE FOR RATING
        $origin = $this->_Request->header('Client-Device');
        if (isset($origin)) {
          $this->Model->Rating->origin = $origin;
        } else {
          $this->Model->Rating->origin = 'app';
        }
        
        
    }

    public function validation(): bool {
        $validator = Validator::make($this->_Request->all(), [
            "rating_val" => ["required", "numeric"]
        ]);

        if ($validator->fails()) {
            $this->Json::set('errors', $validator->errors()->jsonSerialize());
            $this->Json::set('response.code', 400);
            return false;
        }
        
        return true;
    }
}