Не нашел в документации Laravel как передать переменную из контроллера TestController через сервиспровайдер в конструктор класса-реализацию PostRepository, выбирающего посты из БД. Привожу только наиболее значимый код
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'));
}
Ошибка:
Unresolvable dependency resolving [$parameter] in class {$parameter->getDeclaringClass()->getName()}