小编Seb*_*ski的帖子

带有时间戳的Laravel 5.1雄辩的::: attach()方法

我似乎有时间戳问题-试图连接时User,以Lectures通过favorites透视表-没有日期的更新。

这是我的迁移:

Schema::create('favorites', function (Blueprint $table) {

    $table->integer('lecture_id')->unsigned();
    $table->integer('user_id')->unsigned();
    $table->timestamps();

    $table->primary(['lecture_id', 'user_id']);

});
Run Code Online (Sandbox Code Playgroud)

讲座关系:

public function favorites()
{
    return $this->belongsToMany(User::class, 'favorites');
}
Run Code Online (Sandbox Code Playgroud)

用户关系:

public function favorites()
{
    return $this->belongsToMany(Lecture::class, 'favorites')
                ->withTimestamps();
}
Run Code Online (Sandbox Code Playgroud)

每当我附上:

$event->lecture->favorites()->attach($this->user->id);
Run Code Online (Sandbox Code Playgroud)

两个字段created_atupdated_at都设置为0000-00-00 00:00:00

知道我做错了什么吗?

laravel eloquent laravel-5.1

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

Vue Js:带有作用域的插槽和IE11的问题

我的组件看起来像这样:

<template>
    <div>
        <div v-if="!loaded">
            <p><i class="fas fa-spinner fa-spin"></i> Loading feed</p>
        </div>

        <div v-else>

            <div data-slider ref="feedSlider" v-if="length > 0">
                <div class="swiper-wrapper">
                    <div class="slide" v-for="record in records" :key="record.id">
                        <slot :record="record"></slot>
                    </div>
                </div>
            </div>

            <div v-else>
                <p>There are no records available.</p>
            </div>

        </div>

    </div>
</template>
<script>
    import Swiper from 'swiper';
    import AjaxCaller from '../../mixins/AjaxCaller';
    export default {
        mixins: [AjaxCaller],
        data() {
            return {
                loaded: false,
                records: [],
                length: 0,
            }
        },
        mounted() {
            this.makeCall(this.success, this.failure);
        },
        methods: {
            success(response) {
                this.loaded …
Run Code Online (Sandbox Code Playgroud)

javascript internet-explorer vue.js vue-component vuejs2

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

Vue组件循环自身:无法安装组件:模板或渲染函数未定义

似乎无法弄清楚这一点。我有一个主包装组件,它使用另一个组件来呈现导航结构。

导航可以是多层次的,因此需要动态生成。

包装看起来像这样:

<template>
    <nav v-if="this.navigation.length">
        <link-role :collection="navigation"></link-role>
    </nav>
</template>
<script>
    import LinkRole from './Formats/LinkRole';
    export default {
        components: {
            'link-role': LinkRole,
        },
        props: {
            navigation: {
                type: Object,
                default: () => { return {} }
            }
        }
    }
</script>
Run Code Online (Sandbox Code Playgroud)

LinkRole像这样的组件:

<template>
    <ul>
        <li v-for="(item, index) in collection" :key="index">
            <a v-if="item.url" :href="item.url" v-text="item.name"></a>
            <span v-else v-text="item.name"></span>
            <link-role v-if="item.items" :collection="item.items"></link-role>
        </li>
    </ul>
</template>
<script>
    import LinkRole from './LinkRole';
    export default {
        components: {
            'link-role': LinkRole,
        },
        props: {
            collection: …
Run Code Online (Sandbox Code Playgroud)

javascript vue.js vue-component

3
推荐指数
1
解决办法
1992
查看次数

Vue 组件使用 mixin 的计算属性

我有一个使用 mixin 的简单组件,该组件在具有相似功能的多个组件之间共享。

当我运行它时,我似乎得到了

属性或方法“activeClass”未在实例上定义,而是在渲染期间引用。

这是我的混合

<script>
    export default {
        data() {
            return {
                opened: false,
                identity: ''
            }
        },
        computed: {
            activeClass() {
                return {
                    active: this.opened
                };
            }
        },
        created() {
            window.EventHandler.listen(this.identity + '-toggled', opened => this.opened = opened);
        },
        methods: {
            toggle() {
                window.EventHandler.fire('toggle-' + this.identity);
            }
        }
    }
</script>
Run Code Online (Sandbox Code Playgroud)

和我的组件

<template>
    <span class="pointer" :class="activeClass" @click="toggle"><i class="fas fa-search"></i></span>
</template>
<script>
    import Trigger from '../../mixins/Trigger';
    export default {
        data() {
            return {
                mixins: [Trigger],
                data() {
                    return { …
Run Code Online (Sandbox Code Playgroud)

javascript vue.js vue-component vuejs2

2
推荐指数
1
解决办法
7654
查看次数