我在更新与 graphQL 查询重命名的关系时遇到问题。
以下是相关的架构和Laravel模型:
拉拉维尔模型
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class Lead extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
// protected $fillable = [
// 'lead_type_id',
// ];
protected $guarded = [];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
//
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
// 'created_at' => 'timestamp',
// 'updated_at' => 'timestamp'
];
/**
* Get the LeadActions for the Lead.
*/
public function leadActions()
{
return $this->hasMany(\App\Models\LeadAction::class);
}
/**
* Get the clients for the Lead.
*/
public function clients(): BelongsToMany
{
return $this->belongsToMany(Client::class);
}
/**
* Get the LeadType for the Lead.
*/
public function leadType(): BelongsTo
{
return $this->belongsTo(\App\Models\LeadType::class, 'lead_type_id');
}
}
?>
<?php
namespace App\Models;
use App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class LeadType extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name'
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
//
];
我遵循了Laravel命名约定,并将列命名为lead_type_id在潜在客户表上。如果我删除将lead_type关系重命名为 leadType,我可以成功运行更新突变,但我无法弄清楚如何让它使用列的正确名称(lead_type_id),同时保持关系重命名。
任何帮助都非常感谢。
万千封印