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].
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?
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.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community