Illuminate\Database\Eloquent\Model::hasManyThrough PHP Method

hasManyThrough() public method

Define a has-many-through relationship.
public hasManyThrough ( string $related, string $through, string | null $firstKey = null, string | null $secondKey = null, string | null $localKey = null ) : Illuminate\Database\Eloquent\Relations\HasManyThrough
$related string
$through string
$firstKey string | null
$secondKey string | null
$localKey string | null
return Illuminate\Database\Eloquent\Relations\HasManyThrough
    public function hasManyThrough($related, $through, $firstKey = null, $secondKey = null, $localKey = null)
    {
        $through = new $through();
        $firstKey = $firstKey ?: $this->getForeignKey();
        $secondKey = $secondKey ?: $through->getForeignKey();
        $localKey = $localKey ?: $this->getKeyName();
        $instance = new $related();
        if (!$instance->getConnectionName()) {
            $instance->setConnection($this->connection);
        }
        return new HasManyThrough($instance->newQuery(), $this, $through, $firstKey, $secondKey, $localKey);
    }
Model