在 VueJS 中,我试图用 axios 返回一个布尔值
allContactsSaved() {
let promise = axios.get('/contacts');
console.log(promise.then(function (response) {
response.data.data.forEach(function(contact) {
if (!contact.saved) {
return false;
}
});
return true;
}));
}
Run Code Online (Sandbox Code Playgroud)
console.log 刚刚返回
承诺{[[PromiseStatus]]:“待定”,[[PromiseValue]]:未定义}
但我想要 true 或 false 作为回报。
我正在通过 iFrame 加载 Laravel 应用程序。Session 是用 Laravel 的 StartSession 中间件启动的(放在 中app/Http/Kernel.php):
protected $middleware = [
...
\Illuminate\Session\Middleware\StartSession::class,
];
Run Code Online (Sandbox Code Playgroud)
在应用程序中,我像这样保存会话变量:
Session::put('mode', true);
Session::save();
Run Code Online (Sandbox Code Playgroud)
如果我直接访问我的应用程序以及在我嵌入 iFrame 的网站上但仅在Firefox 中访问,它们就会得到保存。
在Chrome 和 Safari 中,不会保存会话。
也许缺少导致该问题的标题?
我试图resources/lang/en用我的包中的语言覆盖默认的 laravel 英语语言包。
该包只是将自己的语言文件发布到eg resources/lang/vendor/*package-name*/de,并且其中包含与laravel标准lang文件相同的文件,例如validation.php或auth.php。
有没有办法告诉 Laravel 使用这些包翻译?
我正在尝试根据他们发布内容的类别以及直接通过搜索字符串的用户来过滤我的用户:
$users = User::when($search, function ($query) use ($request) {
$query->where('name', 'like', '%' . $request['search'] . '%')
->orWhere('email', 'like', '%' . $request['search'] . '%');
return $query;
})
->when($categories, function ($query) use ($request) {
return $query->whereHas('posts.category', function ($query) use ($request) {
$query->whereIn('name', $request['categories']);
});
})
->select('id', 'name', 'email')
->paginate(10);
Run Code Online (Sandbox Code Playgroud)
当我只过滤类别(没有$search)时,它按预期工作,但只要我输入搜索字符串,结果就会被搜索字符串过滤,$request['search']但完全忽略类别过滤。
例如:
名为“Jon”的用户在“生活方式”类别中有一个帖子。
另一个名为“Jonn”的用户在“体育”类别中有一个帖子。
现在,如果我只过滤“体育”类别,我会得到正确的结果 - >“乔恩”。
但是,如果我使用搜索字符串“Jon”进行额外过滤,结果是 ->“Jon”和“Jonn”,这不是预期的结果,因为它应该过滤“Sports”并命名为“%Jon%”,因此结果应该再次只是“乔恩”。
我不知道我怎么能实现该过滤器组合where()和whereHas()。
我试图循环具有特定类的元素并向它们附加一个 ID。
\n\nvar items = document.getElementsByClassName("item");\nfor(var i = 0; i < items.length; i++)\n{\n items[i].id = "item_" + i;\n}\n\nconsole.log(items);\nRun Code Online (Sandbox Code Playgroud)\n\n如果我运行它,我会收到错误Cannot set property \'id\' of undefined
但是,那console.log(items)返回了正确的项目集合:
HTMLCollection\xc2\xa0[]\n 0: div.item\n 1: div.item\n length: 2\n __proto__: HTMLCollection\nRun Code Online (Sandbox Code Playgroud)\n\n但一旦我尝试获取索引,console.log(testimonials[0])它就是undefined。
HTML:
\n\n<div class="slider">\n <div class="item">\n Item 1\n </div>\n</div>\n<div class="slider">\n <div class="item">\n Item 2\n </div>\n</div>\nRun Code Online (Sandbox Code Playgroud)\n