内部config/logging.php:
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['single', 'mongo'],
],
'mongo' => [
'driver' => 'monolog',
'handler' => \Monolog\Handler\MongoDBHandler::class,
'handler_with' => [
'mongo' => new MongoDB\Client(),
'database' => 'logs',
'collection' => 'test'
]
]
],
Run Code Online (Sandbox Code Playgroud)
.env: LOG_CHANNEL=stack
我确信MongoDB数据库也logs存在,test收集也是如此.
我正在尝试记录内部的一些数据php artisan tinker:
Log::info('test');
Run Code Online (Sandbox Code Playgroud)
我有例外
期望$文档有类型"数组或对象"但找到"字符串"
即使我尝试php artisan config:cache我得到这个例外.
有什么不对?
更新:
'mongo' => MongoDB\Client::class,导致相同的错误.顺便说一句,文档中没有任何关于在类中传递类实例的文章handler_with.
这个配置
'mongo' => [
'driver' => 'monolog', …Run Code Online (Sandbox Code Playgroud) 我有什么:
我想要什么:在加载应用程序之前(在解析路由器之前)向服务器发送请求以axios检查用户的身份验证状态。
router.js:
import Vue from 'vue'
import Router from 'vue-router'
import store from './store'
Vue.use(Router)
const router = new Router({
...
routes: [
{
path: '/',
name: 'home',
component: Home
},
{
path: '/account',
name: 'account',
component: () => import(/* webpackChunkName: "account" */ './views/Account.vue'),
meta: {
requiresAuth: true
}
}
]
})
router.beforeEach((to, from, next) => {
if (to.matched.some(route => route.meta.requiresAuth)) {
if (store.state.authStatus)
next()
else
next({name: 'home'})
} else { …Run Code Online (Sandbox Code Playgroud) 我使用命令创建了一个项目 composer create-project symfony/website-skeleton my_project_name
我想安装symfony/profiler-pack. 为什么?因此,探查器中没有“调试”选项卡。
我试过使用composer require --dev symfony/profiler-pack,输出是
Using version ^1.0 for symfony/profiler-pack
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Restricting packages listed in "symfony/symfony" to "5.1.*"
Package operations: 1 install, 0 updates, 0 removals
As there is no 'unzip' command installed zip files are being unpacked using the PHP zip extension.
This may cause invalid reports of corrupted archives. Besides, any UNIX permissions (e.g. executable) …Run Code Online (Sandbox Code Playgroud) 有什么方法可以使用Insomnia或Postman客户端通过API请求将Recaptcha响应令牌作为标头值传递?
我知道响应令牌是在装入recaptcha小部件并与用户进行交互之后生成的。每次加载模块后都会刷新响应令牌。
也许有一些针对这些REST客户端的插件,它们可以基于公共Recaptcha密钥生成响应令牌?或具有这些功能的其他REST客户端。
PS现在,我必须对负责服务器端重新验证的代码块进行注释。
更新:还有其他方法可以测试此类API端点吗?
我有什么:
services.yaml:
app.foo.bar:
class: App\Foo\Bar
arguments: #[ ... ]
Run Code Online (Sandbox Code Playgroud)
控制器:
app.foo.bar:
class: App\Foo\Bar
arguments: #[ ... ]
Run Code Online (Sandbox Code Playgroud)
它有效。
但由于Symfony\Bundle\FrameworkBundle\Controller\Controller已被弃用,我试图扩展Symfony\Bundle\FrameworkBundle\Controller\AbstractController并且我得到了
找不到服务“some_bundle.some_service”:即使它存在于应用程序的容器中,“App\Controller\MyController”中的容器是一个较小的服务定位器,只知道“doctrine”、“http_kernel”、“parameter_bag”, “request_stack”、“router”、“serializer”和“session”服务。尝试改用依赖注入。
我可以get()以某种方式使用AbstractController吗?AbstractController使用ControllerTrait,我想知道为什么会发生错误。
我正在使用 Docker 并且安装了 xdebug。
如果我运行以下命令,我可以确定 xdebug 不会影响测试执行吗?
php -d xdebug.default_enable=0 -d pcov.enabled=1 path/to/phpunit --coverage-text
Run Code Online (Sandbox Code Playgroud)
我读到pcov 可能更快,但据我所知 xdebug 必须被禁用。
是否最好执行以下操作来实现最快的覆盖率而不是运行上述命令?
运行测试
php -d pcov.enabled=1 path/to/phpunit --coverage-text
Run Code Online (Sandbox Code Playgroud)恢复 xdebug 配置
我想用 json POST 发送一个 cookie:
public function testAccessCookie()
{
$response = $this->json('POST', route('publications'))->withCookie(Cookie::create('test'));
//some asserts
}
Run Code Online (Sandbox Code Playgroud)
发布路线有一些中间件:
public function handle($request, Closure $next)
{
Log::debug('cookie', [$request->cookies]);
//cookie validation
return $next($request);
}
Run Code Online (Sandbox Code Playgroud)
但是在运行时testAccessCookie(),[null]里面有日志。没有附加饼干。
怎么了?
真正的(浏览器内)请求没有这样的问题。
我有一个Go应用,正在尝试将其作为systemctl服务运行(Ubuntu 18.04)。
我正在使用godotenv:
func init() {
var env map[string]string
env, err := godotenv.Read()
if err != nil {
panic(err)
}
}
Run Code Online (Sandbox Code Playgroud)
我的.env文件位于可执行文件所在的目录中。
我创建了一个service文件:
[Unit]
Description=my go app
Requires=local-fs.target
After=rsyslog.service
[Service]
Type=forking
GuessMainPID=no
StandardInput=null
ExecStart=/var/path/to/my/app/main
[Install]
WantedBy=default.target
Run Code Online (Sandbox Code Playgroud)
执行完sudo systemctl start my-go-app.service之后sudo systemctl status my-go-app.service,我将这些记录在日志中:
正在启动我的应用程序...
恐慌:打开.env:没有此类文件或目录
怎么了?
main直接执行时,不存在此类问题。
我有一个收藏。
$items = Item:where('count' , '>' , 5)->get();
Run Code Online (Sandbox Code Playgroud)
我有一组 id。
$ids = [2 , 4 , 7 , 8];
Run Code Online (Sandbox Code Playgroud)
在我的 Laravel 刀片中,我想根据 ids 数组在 $items 上显示每个。我做了这样的事情:
@foreach($ids as $id)
<a href="#">
{{ $items->where('id' ,$id)->first()->name }}
</a>
@endforeach
Run Code Online (Sandbox Code Playgroud)
它工作得很好。问题是,我向数据库发送了多少查询?以下是否在运行新查询?
$items->where('id' ,$id)->first()->name
Run Code Online (Sandbox Code Playgroud)
因为我已经get()从数据库中的项目。另一个问题是,如何在显示视图/刀片时找出有多少查询被发送到数据库?
php ×2
phpunit ×2
axios ×1
composer-php ×1
database ×1
eloquent ×1
go ×1
insomnia ×1
laravel ×1
laravel-5.6 ×1
laravel-5.7 ×1
monolog ×1
pcov ×1
postman ×1
recaptcha ×1
sql ×1
symfony ×1
symfony-flex ×1
symfony4 ×1
symfony5 ×1
systemctl ×1
vue-router ×1
vue.js ×1
vuex ×1
xdebug ×1