Support the ongoing development of Laravel.io →
Eloquent Testing

Hello, This is my first attempt at writing a server provider. Any help would be deeply appreciated. I am trying to extend a vendor model located in TCG\Voyager\src\Models\Post I am adding methods to the new model.

I created a service provider in my providers folder named VoyagerpostServiceProvider.php

<?php
namespace App\Providers;
use TCG\Voyager\src\Models\Post;
use Illuminate\Support\ServiceProvider;

class VoyagerpostServiceProvider extends ServiceProvider
{
  public function boot()
  {
  }

  public function register()
  {
    $this->app['post'] = $this->app->share(function($app)
    {
        return new \App\PostTwo(); 
    });
  }
}

 
?>

This is my new model

<?php

namespace App;

//use TCG\Voyager\src\Models\Post; 


class PostTwo extends TCG\Voyager\src\Models\Post
{
    public function authorId()
    {
        return $this->belongsTo(User::class);
    }

    
    
    public function clientId(){
        return $this->belongsTo(\App\Client::class); 
    }
}


I still get an error:

RelationNotFoundException in RelationNotFoundException.php line 20:
Call to undefined relationship [clientId] on model [TCG\Voyager\Models\Post].
Last updated 3 years ago.
0

You can extend all you want, but that packages code is still using their classes as they are most likely not resolving instances from the container. How does their code know about your extended class?

0

lagbox said:

You can extend all you want, but that packages code is still using their classes as they are most likely not resolving instances from the container. How does their code know about your extended class?

I think that is where I need help. I am sure how to get the vendor to use my extended class.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

dirk2099 dirk2099 Joined 6 Sep 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.