Answer the question
In order to leave comments, you need to log in
How to pass a parameter through a service provider to the constructor of an implementation class?
I did not find in the Laravel documentation how to pass a variable from the TestController controller through the service provider to the constructor of the PostRepository implementation class that selects posts from the database. I give only the most significant
PostRepository code:
public $city;
public function __construct($city){
$posts = DB::table('post')->where('city', $city)->get();
$this->posts=$posts;
}
public function register(){
$this->app->singleton('App\Repositories\PostRepository', function(){
return $posts;
});
}
public function test(){
$city='1';
var_dump(app('App\Repositories\PostRepository'));
}
Unresolvable dependency resolving [$parameter] in class {$parameter->getDeclaringClass()->getName()}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question