Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

boldstar's avatar

How To "Implements" Vendor File

So I am trying to apply a Billable trait to a model. However when I call this model in my controller and attempt to perform a method on it. I get the following alarm.

"Declaration of App\Models\System\Hostname::website() must be compatible with Hyn\Tenancy\Contracts\Hostname::website(): Illuminate\Database\Eloquent\Relations\BelongsTo"

Any ideas?

This is the model file Hostname.php

<?php

namespace App\Models\System;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Hyn\Tenancy\Contracts\Hostname as Contract;
use Laravel\Cashier\Billable;


class Hostname extends Authenticatable implements Contract
{
    use Billable;

    protected $fillable = [
        'id', 'stripe_id'
    ];


    public function website() {
        return $this->belongsTo('Hyn\Tenancy\Contracts\Website');
    }

}

this is the file that it implements

namespace Hyn\Tenancy\Contracts;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
 * @property int $id
 * @property string $fqdn
 * @property string $redirect_to
 * @property bool $force_https
 * @property Carbon $under_maintenance_since
 * @property Carbon $created_at
 * @property Carbon $updated_at
 * @property Carbon $deleted_at
 * @property int $website_id
 * @property Website $website
 */
interface Hostname
{
    public function website(): BelongsTo;

}

This is the controller where I am attempting to grab the model

public function subscribe(Request $request)
    {
        // $request->validate($request->all());

        $host = Hostname::first();

        $host->newSubscription('main', 'monthly')->create($request->secretToken);

        return response('Success');
    }
0 likes
2 replies
michapietsch's avatar

Hi,

you have implements Contract and interface Hostname. Shouldn't it be implements Hostname?

boldstar's avatar
boldstar
OP
Best Answer
Level 2

So instead of extending the interface I switch to extending the model. My final code looks like this now

<?php

namespace App\Models\System;

use Illuminate\Database\Eloquent\Model;
use Hyn\Tenancy\Models\Hostname as Contract;
use Laravel\Cashier\Billable;

class Hostname extends Contract
{
    use Billable;

}

Please or to participate in this conversation.