我有两个桌子。 RTAList和RTARegCompany。 RTARegCompany包含引用RTAList的外键rta_id。
Schema::create('rta_list', function (Blueprint $table) {
$table->increments('rta_id');
$table->string('rta_name');
$table->string('rta_address');
$table->string('rta_phone');
$table->string('rta_email')->unique();
$table->integer('count');
$table->timestamps();
});
Schema::create('rta_reg_company', function (Blueprint $table) {
$table->increments('company_id');
$table->integer('rta_id')->unsigned();
$table->foreign('rta_id')
->references('id')
->on('rta_lists')
->onDelete('cascade');
$table->string('company_name');
$table->string('company_isin');
$table->string('company_script');
$table->string('company_address');
$table->string('company_phone');
$table->string('company_email');
$table->timestamps();
});
我必须为RTAList和RTARegCompany建模。
protected $table = 'rta_list';
protected $fillable = ['rta_name', 'rta_address','rta_phone','rta_email'];
protected $table = 'rta_reg_company';
protected $fillable = ['rta_id', 'company_name','company_isin','company_script','company_address','company_phone','company_email'];
public function rtaname(){
return $this->belongsTo(RTAList::class);
}
现在,我想在添加RTA注册公司时显示rta_name。但是我收到错误消息“试图获取标称属性;
在RTARegController中,我已经编写了这段代码。
$rta = RTAList::where('rtaname')->get();
在add_company.blade.php中,我想显示rta_name
<input type="text" name="rta_id" id="rta_id" value="{{ $rta->rtaname->rta_name }}" disabled>
帮我解决这个问题...