Because you declared that the Hostname class must implement the Hostname contract/interface, it needs to have this public function website(): BelongsTo method, but it doesn't. Implement the method on your Hostname class (not the interface) and you'll be good to go.
How To Properly Implement A Vendor Interface
So I am trying to implement a vendor file. I have been looking for something that would give me an idea of what is happening, but perhaps from lack of experience I am unable to make sense.
So this is the vendor file I am looking to implement Hostname.php
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;
}
Now according to there Instructions I can extend there model to a custom model however I am running into an issue with the public function website() method because I beliece I need to concretely instantiate the vendor file but I am unsure how should go about doing this.
- Do I need to register a service provider?
- What should I do in my custom model file?
This is the current structor of my custom model file
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 __construct(Hostname $hostname) {
$this->hostname = $hostname;
}
}
This is the alarm that I am currently getting
Class App\Models\System\Hostname contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Hyn\Tenancy\Contracts\Hostname::website)
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.