doc中的示例:
DB::table('users')
->whereExists(function($query)
{
$query->select(DB::raw(1))
->from('orders')
->whereRaw('orders.user_id = users.id');
})
->get();
Run Code Online (Sandbox Code Playgroud)
但是如果我需要像这样使用外部变量呢:
->where('city_id', '=', $this->city->id)
->where(function($query)
{
$query->where('name', 'LIKE', '%'.$searchQuery.'%')
->orWhere('address', 'LIKE', '%'.$searchQuery.'%')
})
Run Code Online (Sandbox Code Playgroud)
现在我创建了新属性并通过它访问了$this->,但还有更方便的方法吗?
我有:
$myarr['DB'] = new DB();
$myarr['config'] = new config();
Run Code Online (Sandbox Code Playgroud)
我可以以某种方式让PHPStorm知道究竟是什么内部的钥匙?现在我只看到变量和类属性,但不是数组键.
Swagger 文档说你可以这样做:
https://swagger.io/docs/specification/grouping-operations-with-tags/
但不幸的是 drf-yasg 没有实现这个功能:
https://github.com/axnsan12/drf-yasg/issues/454
据说,我可以添加自定义生成器类,但这是一个非常笼统的答案。现在我看到了drf_yasg.openapi.Swaggerget infoblock 并且我有想法,这可能是将全局tags部分作为附加 init 参数的正确位置,但它比自定义生成器类更深入,而且我对此模块缺乏了解
有没有人有解决这个特定问题的方法,或者至少可能是某种教程的链接,如何正确自定义生成器类?
我有这样的基类:
class BaseAPI
{
public function __construct(Client $client, CacheInterface $cache, $apiBaseUri)
{
$this->client = $client;
$this->apiBaseUri = $apiBaseUri;
$this->cache = $cache;
}
}
Run Code Online (Sandbox Code Playgroud)
然后在提供者:
class APIServiceProvider extends ServiceProvider
{
public function register()
{
$this->app
->when(BaseAPI::class)
->needs('$apiBaseUri')
->give(env('DEFAULT_API_URI',''));
}
}
Run Code Online (Sandbox Code Playgroud)
那很有效.但是当我做祖先的时候:
class GetLocations extends BaseAPI
{
protected $apiMethodName = 'locations';
protected $type = 'get';
}
Run Code Online (Sandbox Code Playgroud)
我收到了错误.当然我可以手动为每个祖先编写代码,但是它们有很多,所以问题是:是否有任何绑定的继承机制?这样的事情:https: //symfony.com/doc/current/service_container/parent_services.html