如何在Laravel中的规则请求中使数组唯一

问题描述

在我的Laravel-5.8项目中,我有以下模型:

class AppraisalMsf extends Model
{
    protected $table = 'appraisal_msfs';

    protected $primaryKey = 'id';

    protected $fillable = [
                  'id','appraisal_respondent_id','company_id',];

    public function appraisalrespondent()
    {
        return $this->belongsTo('App\Models\Appraisal\AppraisalRespondent','appraisal_respondent_id');
    }    
    
    public function appraisalmsfdetail(){
        return $this->hasMany('App\Models\Appraisal\AppraisalMsfDetail');
    }

}

class AppraisalmsfDetail extends Model
{
  protected $table = 'appraisal_msf_details';

  protected $fillable = [
                'appraisal_msf_id','appraisal_identity_id','appraisal_skill_id','appraisal_respondent_rating_id','comment',];
  
  
  protected $casts = [
   'data' => 'array',];

  public function appraisalmsf()
  {
      return $this->belongsTo('App\Models\Appraisal\AppraisalMsf');
  }
  
  public function company()
  {
      return $this->belongsTo('App\Models\Organization\OrgCompany','company_id');
  }  
  
  public function appraisalskill()
  {
      return $this->belongsTo('App\Models\Appraisal\AppraisalSkill','id' );
  }     

  public function appraisalrespondentrating()
  {
      return $this->belongsTo('App\Models\Appraisal\AppraisalRespondentrating','id' );
  } 

}

这是一对多的:AppraisalMsf有很多AppraisalMsfDetail

规则:

public function rules()
{
    return [
        'appraisal_respondent_id' => [
             'required',Rule::unique('appraisal_msf')->where(function ($query) {
           return $query->where('appraisal_respondent_id',$this->appraisal_respondent_id)
              ->where('company_id',$this->company_id);
        })                
        ],'appraisal_skill_id'           => 'required|array','appraisal_skill_id.*' => [
             'required',],'appraisal_respondent_rating_id'           => 'required|array','appraisal_respondent_rating_id.*' => [
             'required','comment'           => 'nullable|array','comment.*' => [
             'nullable',];
}

我正在处理动态输入字段:appraisal_skill_id,appraisal_respondent_rating_id和注释,它们来自AppraisalmsfDetail。

如上面的请求规则所示,appraisal_respondent_id对于company_id是唯一的

我之所以使用它,是因为appraisal_respondent_id不是数组:

        'appraisal_respondent_id' => [
             'required',

它有效

根据上面的规则请求,我该如何制作以下每个数组:

相对于appraisal_respondent_id,我如何使appraisal_skill_id和appraisal_respondent_rating_id唯一?

谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...