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, which selects posts from the database. I cite only the most significant code
PostRepository:
public $city; public function __construct($city){ $posts = DB::table('post')->where('city', $city)->get(); $this->posts=$posts; } PostServiceProvider:
public function register(){ $this->app->singleton('App\Repositories\PostRepository', function(){ return $posts; }); } TestController:
public function test(){ $city='1'; var_dump(app('App\Repositories\PostRepository')); } Mistake:
Unresolvable dependency resolving [$parameter] in class {$parameter->getDeclaringClass()->getName()}