Laravel 8无法从创建的模型';扩展枢轴&x27;

Laravel 8无法从创建的模型';扩展枢轴&x27;,laravel,eloquent,laravel-8,Laravel,Eloquent,Laravel 8,有问题 无法从创建的模型中获取id。我检查正常创建的数据库行 $productStoreLink = ProductStoreLink::create([ 'product_id' => $item->id, 'store_id' => $store['id'], 'code' => $store['code'] ]); $productStoreLink->id; 在数组dd($productStoreLink) 我有

有问题 无法从创建的模型中获取id。我检查正常创建的数据库行

    $productStoreLink = ProductStoreLink::create([
      'product_id' => $item->id,
      'store_id' => $store['id'],
      'code' => $store['code']
]);
$productStoreLink->id;
在数组
dd($productStoreLink)

我有模式。是的,这个模型扩展了Pivot,但这是为了更困难的操作。 问题: 我想在创建模型后从集合中接收id<第一个代码块中的代码>$productStoreLink->id。 真的要从这个模型中获取id吗

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\Pivot;
use Illuminate\Database\Eloquent\SoftDeletes;

class ProductStoreLink extends Pivot
{
    use HasFactory;
    use SoftDeletes;
    protected $fillable = [
        'id',
        'store_id',
        'product_id',
        'store_id',
        'code',
        'created_at',
        'updated_at',
        'deleted_at',
    ];
    public function price()
    {
        return $this->hasOne('App\Models\ProductStorePrices','product_store_link_id','id');
    }
    public function prices()
    {
        return $this->hasMany('App\Models\ProductStorePrices','product_store_link_id','id');
    }
}


请分享更多详细信息。你到底有什么问题?你所说的“Real从这个模型中获取id”是什么意思?@NicoHaase我想在创建模型后从集合中获取id<第一个代码块中的代码>$productStoreLink->id
。现在我收到空的
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\Pivot;
use Illuminate\Database\Eloquent\SoftDeletes;

class ProductStoreLink extends Pivot
{
    use HasFactory;
    use SoftDeletes;
    protected $fillable = [
        'id',
        'store_id',
        'product_id',
        'store_id',
        'code',
        'created_at',
        'updated_at',
        'deleted_at',
    ];
    public function price()
    {
        return $this->hasOne('App\Models\ProductStorePrices','product_store_link_id','id');
    }
    public function prices()
    {
        return $this->hasMany('App\Models\ProductStorePrices','product_store_link_id','id');
    }
}