鉴于以下 10 月 CMS 插件模型:
Schema::create('iaff106_cellphone_cellphones', function($table){
$table->engine = 'InnoDB';
$table->increments('id');
$table->integer('user_id')->unsigned()->nullable()->index();
$table->string('label');
$table->string('phone')->nullable()->index();
$table->integer('provider_id')->nullable();
$table->boolean('is_txtable')->default(true);
$table->boolean('is_published')->default(false);
$table->timestamps();
});
Schema::create('iaff106_cellphone_providers', function($table){
$table->engine = 'InnoDB';
$table->increments('id');
$table->string('name');
$table->string('slug')->index();
$table->string('mail_domain')->nullable();
$table->timestamps();
});
提供者的关系:
public $belongsToMany = ['IAFF106\CellPhone\Models\Cellphone', 'foreignKey' => 'provider_id'];
手机关系:
public $hasOne = ['IAFF106\CellPhone\Models\Provider'];
我想选择一个手机和相关的服务提供商来获取“电话”和“姓名”字段。
在我的组件中,我尝试过:
public function onRun()
{
$this->cellphone = $this->page['cellphone'] = $this->loadCell();
}
protected function loadCell()
{
$slug = $this->propertyOrParam('idParam');
$cellphone = Cellphone::isPublished()->where('id', '=', $slug)->first();
$this->provider = $this->page['provider'] = $cellphone->provider;
return $cellphone;
}
$this->cellphone 有我想要的电话数据,但我不知道如何访问提供者“名称”信息。
如何从视图中的两个模型加载和访问数据?
在我看来,我已经尝试过:
<ul>
<li>{{ cellphone.phone }} {{ provider.name }} </li>
<li>Try Again </li>
<li>{{ cellphone.phone }} {{ cellphone.provider.name }} </li>
</ul>
{{ cellphone.phone }} 显示正常,但我无法获取提供商名称。