我使用Laravel 5.3.
我有2张桌子:
Articles
---------
id
cat_id
title
Run Code Online (Sandbox Code Playgroud)
和
Category
---------
id
parent_id
title
Run Code Online (Sandbox Code Playgroud)
我在模特中定义了我的关系:
// Article model
public function category()
{
    return $this->belongsTo(Category::class);
}
// Category model
public function children() 
{
    return $this->hasMany(Category::class, 'parent_id', 'id');
}   
Run Code Online (Sandbox Code Playgroud)
有没有一种简单的方法可以使用Eloquent来列出包含文章数量的类别.困难在于我想将类别分组在哪里id_parent = 0,即我想仅显示具有儿童文章数量的父类别.
我试过这样的事情:
    $category = new \App\Models\Category();
    $categoryTable = $category->getTable();
    return $category->leftJoin('article', 'article.cat_id', '=', 'category.id')
        ->whereIn('article.cat_id', function($query)
            {
                $query->select('cat_id')
                    ->from('categories')
                    ->where('categories.parent_id', ???)
                    ->orWhere($this->tableName .'.cat_id', $id);
            })
        ->groupBy('cat_id');
Run Code Online (Sandbox Code Playgroud)
但我迷路了......
我尝试将 nodeJS 中的视频插入到 Youtube,但出现此错误:
{ 错误:[ { 域:'youtube.quota',原因:'quotaExceeded',消息:'请求无法完成,因为您已超出配额。' ], code: 403, message: '请求无法完成,因为您已超出配额。' }
编辑:这是当我将 Auth 与现有令牌一起使用时,我从https://developers.google.com/oauthplayground/获取令牌并在我的代码中使用它。我尝试使用不同的帐户,无法上传视频,但例如我可以在播放列表中插入项目。
这是我的代码(nodeJS):
var req = Youtube.videos.insert({
    "resource": {
        // Video title and description
        "snippet": {
            "title": "Test",
            "description": "Test video upload via YouTube API"
        },
        "status": {
            "privacyStatus": "private"
        }
    }, 
    "part": "snippet,status,id", 
    "media": {
        "body": fs.createReadStream('./test.mp4')
    }
}, function (err, data) {
....
Run Code Online (Sandbox Code Playgroud)
视频是 600 Ko... 我如何查看或更新配额?我使用 OAuth 身份验证,例如我可以毫无问题地在播放列表中插入元素,但我无法上传视频。我需要什么吗?
谢谢。
使用 Symfony 5.2 和 PhpUnit 最新版本,我的功能测试出现此错误
LogicException: You cannot create the client used in functional tests if the "framework.test" config is not set to true.
Run Code Online (Sandbox Code Playgroud)
内容config/packages/test/framework.yaml:
framework:
    test: true
    session:
        storage_id: session.storage.mock_file
Run Code Online (Sandbox Code Playgroud)
我的 PHP 部分phpunit.xml.dist:
<php>
    <ini name="error_reporting" value="-1"/>
    <server name="APP_ENV" value="test" force="true"/>
    <server name="SHELL_VERBOSITY" value="-1"/>
    <env name="BOOTSTRAP_CLEAR_CACHE_ENV" value="test"/>
</php>
Run Code Online (Sandbox Code Playgroud)
这是我的测试内容:
class JWTTokenAuthenticatorTest extends WebTestCase
{
    public function test_authentication_token()
    {
        $client = static::createClient();
        $client->request(
            'POST',
            '/authentication_token',
            [],
            [],
            ['CONTENT_TYPE' => 'application/json'],
            '{"email":"api@api.com","password":"api"}'
        );
        $this->assertResponseIsSuccessful();
        $this->assertMatchesRegularExpression('/{"token":"(.*)"}/i', $client->getResponse()->getContent()); …Run Code Online (Sandbox Code Playgroud) 我使用 NuxtJS 2,并且需要有 2 个或更多具有不同配置的 axios 实例。
在 VueJS / JS classic 中,我可以创建一个新实例axios:
var axiosElasticSearch = axios.create({
  baseURL: 'https://elastic.com/',
  timeout: 1000,
  headers: {'X-Custom-Header': 'foobar'}
});
Run Code Online (Sandbox Code Playgroud)
但在 Nuxt 中,由于 SSR 层,他们应用自己的配置来处理这个问题。
在我的 Nuxt 配置中,我有这个:
axios: {
    baseUrl: process.env.API_URL,
    browserBaseUrl: process.env.BROWSER_API_URL,
    withCredentials: true,
    headers: {
      common: {
        Accept: 'application/json',
        Authorization: 'Bearer ' + process.env.API_TOKEN
      }
    }
  },
Run Code Online (Sandbox Code Playgroud)
然后,我可以轻松地注射它。
可以在 Nuxt 中管理吗?我查看了代理选项,但我认为这不是我想要的。
我有一个字符串:
12121212
我只想得到1111,第一个字母,然后是第三个字母,然后是第五个字母......两个字母一个字母.
这有什么功能吗?我正在使用str_split然后我拿了我的数组的第一个字母,但它不是很干净.谢谢.
这是我现在的代码,但它不是很灵活:
function loop_n_letter($string, $n)
{
    $return = '';
    $array = str_split($string);
    foreach ($array as $i => $row)
    {
       if ($i % $n == 0)
       {
           $return .= $row[0];
       }
    }
    return $return;
}
Run Code Online (Sandbox Code Playgroud) 我在我的项目中使用 Svelte i18n,它在我的 Svelte 组件中完美运行。
但我有一些 JS 文件(例如常量),我想使用 i18n 来翻译一些键,例如 (in /services/constants.js) :
import { _ } from 'svelte-i18n'
export const STATUS_OK = 1;
export const STATUS_PENDING = 2;
export const STATUS_ERROR = 3;
export const STATUS_INACTIVE = 4;
export const STATUS_PRICE_NOT_FOUND = 5;
export const STATUTES = {
  [STATUS_OK]: {
    text: _('urls.statutes.ok'),
    class: 'text-green-500',
  },
Run Code Online (Sandbox Code Playgroud)
但我得到一个错误,我可以_在 JS 文件中使用函数吗?或者我应该创建一种简洁的组件来处理我的常量?
我正在使用Twig,我遇到了问题.
当我想为对象使用变量索引时,我遇到了问题.
这是我的代码:
{% for label, field in params.fields %}
    {{ dump(data.field) }}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
data是一个包含{'email':'test@test.fr','name':'John'}的对象.
Field是包含['email','name']的字符串数组
我不能动态地显示我的对象的价值.
{{dump(data.email)}}有效.
我如何使用动态索引?谢谢.
我使用 Laravel 5.6,我有 3 个模型:
该地区有很多商店:
public function stores()
{
    return $this->hasMany('Beproxy\App\Models\Store');
}
Run Code Online (Sandbox Code Playgroud)
商店属于一个商家:
public function merchant()
{
    return $this->belongsTo('Beproxy\App\Models\Merchant');
}
Run Code Online (Sandbox Code Playgroud)
在我的Merchant中,我有一个 tinyInt 来定义该 Merchant 是否处于活动状态(状态)
我可以在区域模型中编写一个新函数来获取属于活跃商家的所有商店吗?
通过hasMany关系,我可以使用:
public function storesWithProducts()
{
    return $this->hasMany('App\Models\Store')->has('products');
}
Run Code Online (Sandbox Code Playgroud)
但我不知道如何使用belongsTo的条件,我在我的Area中尝试过,但它加载了所有内容:
public function storesWithMerchantActive()
{
    return $this->hasMany('App\Models\Store')
        ->with(['merchant' => function($query) {
            $query->where('state', '=', 1);
        }])
        ->has('products');
}
Run Code Online (Sandbox Code Playgroud) 使用Bootstrap CSS 3.3.1,输入带有插件和帮助块时出现了一些问题.
只看小提琴:https://jsfiddle.net/L8cyqoL1/1/
在Firefox/Chrome上测试过.标记错了吗?我尝试了"输入组"......作为课程没有成功
这是标记:
<div class="form-group">
    <label for="title" class="control-label col-md-3">Titre de la page</label>
    <div class="col-md-9 input-group">
        <div class="input-group-addon">
            @
        </div>
        <input type="text" value="Value test" class="form-control input-xxlarge" id="title" name="title" size="46" />
            <span class="help-block">Help Lorem Ipsum</span>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud) 使用Symfony 4和Webpack + Encore + Yarn,我想在我的模板中处理图像,而我真的不知道如何实现这一点.
我把我的图像放在我的/assets/img/logo.png文件夹中,并在我的文件夹中使用webpack.config.js:
.addEntry('logo', './assets/img/logo.png')
Run Code Online (Sandbox Code Playgroud)
在我跑完之后:
yarn run encore dev
Run Code Online (Sandbox Code Playgroud)
哪个生成/public/build/logo.js和/public/build/images/logo.aez323a.png文件.
我的问题是,有没有办法将Symfony asset()函数与文件名中的哈希链接到文件名?或者我应该使用其他方式在我的模板中使用图像?