小编Tom*_*ler的帖子

Laravel.在具有关系的模型中使用scope()

我有两个相关的模型:CategoryPost.

Post模型具有published范围(方法scopePublished()).

当我尝试获取该范围的所有类别时:

$categories = Category::with('posts')->published()->get();
Run Code Online (Sandbox Code Playgroud)

我收到一个错误:

调用未定义的方法 published()

类别:

class Category extends \Eloquent
{
    public function posts()
    {
        return $this->HasMany('Post');
    }
}
Run Code Online (Sandbox Code Playgroud)

帖子:

class Post extends \Eloquent
{
   public function category()
   {
       return $this->belongsTo('Category');
   }


   public function scopePublished($query)
   {
       return $query->where('published', 1);
   }

}
Run Code Online (Sandbox Code Playgroud)

laravel eloquent laravel-4

86
推荐指数
1
解决办法
6万
查看次数

将$ refs与Element UI的输入组件一起使用

是否有可能使用refel-input组件从元素的UI?我试图$refs在安装我的Vue实例时专注于输入.这是我的代码:

<div id="app">
    <el-input type="text" ref="test" placeholder="enter text"></el-input>
</div>
Run Code Online (Sandbox Code Playgroud)

在我的Vue实例中:

new Vue({
  el: "#app",
  mounted(){
    this.$refs.test.focus()
  }
})
Run Code Online (Sandbox Code Playgroud)

focus方法根本不起作用,即使我this.$refs.test.focus()进入一个方法并试图通过一个事件触发它.

vue.js vuejs2

7
推荐指数
1
解决办法
3061
查看次数

从短代码动态注入Vue 2组件

我在管理区域中有一个表单,用户可以在其中输入包含短代码的文本:

在[temp c = 200]加热烤箱

我想要的是temp在前端显示时要解析并转换为Vue 2组件的短代码.

这是一个简化的Temperature.vue组件:

<template>
    <span class="temperature">
        {{ celsius }}&deg;C
    </span>
</template>

<script>
    import { mapGetters, mapActions } from 'vuex'

    export default {
        props: ['celsius'],
        name: 'temperature'
    }
</script>
Run Code Online (Sandbox Code Playgroud)

这是一个简化的Instructions.vue组件,它将使用短代码解析和呈现文本:

<template>
    <div v-html="parseShortcodes(text)"></div>
</template>

<script>
    import ShortcodeParser from 'meta-shortcodes'
    import Temperature from 'Temperature.vue'

    export default {

        data: () => {
            return {
                text: 'Heat oven at [temp c=200]',
                parser: ShortcodeParser()
            }
        },
        components: [
            Temperature
        ],
        methods: {
            parseShortcodes(text) { …
Run Code Online (Sandbox Code Playgroud)

vue.js vuejs2

6
推荐指数
1
解决办法
5973
查看次数

Mandrill:在假设可传递性之前我要等多久?

我已经设置了一个Mandrill webhook,它会在电子邮件遭到硬弹跳或被拒绝时更新我的​​应用程序,因此我不会将该特定电子邮件地址保留在我的数据库中.它的工作方式是:用户给我一个地址,我发给他一个确认,如果我没有在30分钟内听到Mandrill的webhook,我认为没关系.

所以我用不存在的地址运行了一些测试,但它们并没有太顺利.在我认为他们没事的很长时间之后,他们中的大多数都出现了几个小时.

另外,我没有说明接收webhook批次的延迟.根据出站活动日志,一封邮件在下午2:01反弹,但是webhook历史记录显示批次仅在下午2:52发送.

我的问题是:为了让Mandrill有足够的时间来检测硬反弹/拒绝然后向我发送webhook批次,我应该延迟我的应用程序的可传递性假设多长时间?由于延迟处理高峰时间或其他特殊事件,我可以忍受大约5%的糟糕电子邮件,但看起来我的30分钟还不足以捕捉到任何东西......

email mandrill

5
推荐指数
1
解决办法
2884
查看次数

Laravel 5.2 Cron没有开发centos

当我试图在localhost(php版本:PHP 5.6.4-4ubuntu6.4(cli))上运行Task Schedular时,它运行正常.

crontab中

* * * * * php /home/aishatest/public_html/Aisha/Aisha/artisan schedule:run >> /dev/null 2>&1
Run Code Online (Sandbox Code Playgroud)

应用程序/软件/ Kernel.php

<?php

namespace App\Console;

use App\Console\Commands\CheckOutfitAvailibilityCommand;
use App\Http\Controllers\OutfitCronController;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        // Commands\Inspire::class,
        CheckOutfitAvailibilityCommand::class
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        \Log::error("Kernel");
        //$schedule->command('inspire') …
Run Code Online (Sandbox Code Playgroud)

cron php-5.6 centos6.5 laravel-5.2 taskscheduler

5
推荐指数
1
解决办法
969
查看次数

如何在Vue JS 2中间接拥有自嵌套组件?

我设法使用该name属性创建了直接自嵌套的组件,并且一切运行正常。

<template>
    <div>
        <span>Hi, I'm component A!</span>
        <component-a></component-a>
    </div>
</template>

<script>
    export default {
        name: 'component-a',
        components: {
            'component-a': this
        }
    }
</script>
Run Code Online (Sandbox Code Playgroud)

现在,我想创建间接的自嵌套组件。像这样:

ComponentA.vue:

<template>
    <div>
        <span>Hi, I'm component A!</span>
        <component-b v-if="hasItems" v-for="item in items" :item="item"></component-b>
    </div>
</template>

<script>
    import ComponentB from './ComponentB.vue'

    export default {
        name: 'component-a',
        components: {
            'component-b': ComponentB
        },
        props: ['items'],
        computed: {
            hasItems() {
                return this.items.length > 0
            }
        }
    }
</script>
Run Code Online (Sandbox Code Playgroud)

ComponentB.vue:

<template>
    <div>
        <span>Hi, I'm component B!</span>
        <component-a v-if="hasItems" :items="item.items"></component-a> …
Run Code Online (Sandbox Code Playgroud)

javascript vue.js vue-component

5
推荐指数
1
解决办法
1077
查看次数

如何使用Mysql在Laravel上使用和保存表情符号

我有一个使用Laravel 5.2构建的Web应用程序,我的问题是如何存储然后显示表情符号。当我使用iPhone上的表情符号时,例如,在保存数据库后返回fire?。我已经设置了'charset'='utf8mb4'; '排序规则'='utf8mb4_unicode_ci'

但仍然得到相同的结果。我需要安装软件包或其他东西吗?

mysql emoji laravel laravel-5.2

5
推荐指数
1
解决办法
3742
查看次数

Webpack:手动添加编译文件依赖项应强制重建

I'm using Webpack 2 (via Laravel Mix) to compile a Javascript asset in different languages, much like Webpack's own i18n plugin. I've built a custom implementation, though, which plays nicely with Mix's helpers. There is one final issue, though, which I cannot wrap my head around, which has to do with the watch process. Here's a summary of what is happening:

  • An app.js file has several dependencies which compose the actual logic
  • Mix is instructed to create a different …

webpack webpack-2 laravel-mix

5
推荐指数
1
解决办法
1145
查看次数

使用渲染功能时,Vue组件未显示子文本节点

我正在尝试使用Vue 2进行可编辑的组件.它应该contenteditable在任何标记中使用该属性,替换正常输入.我想给它一个占位符功能,以便在用户没有提供时显示一个值,但我似乎无法让它工作.

我正在观察组件的当前值,并设置data.isEmptytrue没有用户内容时.然后该组件应显示占位符值,但目前它不显示任何内容.

如果我console.logrender方法的结果,它将显示占位符子节点被正确实例化,但由于某种原因它只是不会显示在最终的HTML上.

这是一个JSFiddle:https://jsfiddle.net/dy27fa8t/

并为喜欢它的人提供了一个嵌入式代码:

Vue.component('editable-content', {
  props: {
    initial: {
      type: String
    },
    placeholder: {
      type: String,
      required: false
    }
  },
  data() {
    return {
      value: this.initial,
      isEmpty: this.initial === ''
    }
  },
  render: function(createElement) {
    const self = this
    return createElement(
      'div', {
        attrs: {
          contenteditable: true
        },
        on: {
          input: function(event) {
            self.value = event.target.innerHTML
            self.$emit('edited', event.target.value)
          }
        }
      },
      this.isEmpty ? this.placeholder : …
Run Code Online (Sandbox Code Playgroud)

javascript vue.js vue-component vuejs2

5
推荐指数
1
解决办法
772
查看次数

Laravel 连接表并连接行

所以我有两个表,组织和联系人。两个表都有“电子邮件”列,我需要做的是保留组织的名称,但在电子邮件列中连接所有电子邮件(组织+所有联系人电子邮件)。

这是我尝试过的一些版本,但没有成功

1)这个不分组:

$customers = DB::table('customers')
    ->whereRaw('LENGTH(customers.email) > 4')
    ->select([
        'customers.id',
        'customers.name',
        'customers.email'
    ]);

$contacts = DB::table('contacts')
    ->whereRaw('LENGTH(contacts.email) > 4')
    ->leftJoin('customers', 'contacts.customer_id', '=', 'customers.id')
    ->select([
        'customers.id',
        'customers.name',
        'contacts.email'
    ]);

return $customers
    ->union($contacts)
    ->select([
        'id',
        'name',
        DB::raw('GROUP_CONCAT(DISTINCT email, ", ") AS emails'),
    ])
    ->groupBy('id')
    ->get();
Run Code Online (Sandbox Code Playgroud)

2)这个实际上非常接近,但它不会过滤掉联系人或客户整体都没有的条目DB::raw('LENGTH(email) > 4')

return $customers = DB::table('customers')
                ->leftJoin('contacts', 'contacts.customer_id', '=', 'customers.id')
                ->select([
                    'customers.id',
                    'customers.name',
                    'registration',
                    DB::raw('GROUP_CONCAT(DISTINCT contacts.email, ", ") AS contact_emails'),
                    'customers.email'
                ])
                ->groupBy('customers.id')
                ->get();
Run Code Online (Sandbox Code Playgroud)

3)我尝试更接近子查询(我知道它只会过滤掉没有电子邮件的联系人)

3.1) 尝试子查询 1 会导致错误:JoinClause::whereRaw()不存在

return $customers = …
Run Code Online (Sandbox Code Playgroud)

mysql laravel laravel-5

4
推荐指数
1
解决办法
4285
查看次数