Current File : //home/tradevaly/demo.tradevaly.com.bd/app/Rules-bk/Required.php
<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
use Cookie;

class Required implements Rule
{
    /**
     * Create a new rule instance.
     *
     * @return void
     */
    private  $tableModelName;
    private  $fieldLabelTextEn;
    private  $fieldLabelTextBn;
    private  $columnName;
    private  $editId;
    public function __construct($tableModelName, $columnName, $fieldLabelTextEn, $fieldLabelTextBn, $editId)
    {
        //dd($editId);
        $this->tableModelName = $tableModelName;
        $this->columnName = $columnName;
        $this->fieldLabelTextEn = $fieldLabelTextEn;
        $this->fieldLabelTextBn = $fieldLabelTextBn;
        $this->editId = $editId;
    }

    /**
     * Determine if the validation rule passes.
     *
     * @param  string  $attribute
     * @param  mixed  $value
     * @return bool
     */
    public function passes($attribute, $value)
    {
        dd('pppp');
        //$langId = Cookie::get('langId');
        $langId = 1;
        if($langId == 2){
            $value = cv_bn_to_en($value);
        }
        $conditions = [];
        $conditions = $this->columnName;
        
        if( !empty($this->editId) ){
            
            $existsData = $this->tableModelName::where('id', $editId)
            ->first();
            dd($existsData);

            if( empty($existsData[$columnName]) ){
                return false;
            }
        }
        //dd($conditions);
       
        
      
        return true;
    }

    /**
     * Get the validation error message.
     *
     * @return string
     */
    public function message()
    {
        //$langId = Cookie::get('langId');
        $langId = 1;
        $msg = '';
        if($langId ==1){
           $msg = 'The'. $this->fieldLabelTextEn.' field is required.';
        }else{
            $msg =  $this->fieldLabelTextBn.' ফিল্ড অবশ্যয় পূরণ করতে হবে ।';
        }

        return $msg;
        
    }
}