小编fro*_*man的帖子

使用 Laravel 每月接收数据

我正在尝试创建一个显示每月数据的 morrisJS 折线图。所以我每个月都会得到这样的数据:

        $intakes = Intakes::whereYear('created_at', '=', 2018)
        ->orWhere(function ($query) {
            $query->whereMonth('created_at', '=', 1)
                ->whereMonth('created_at', '=', 2)
                ->whereMonth('created_at', '=', 3)
                ->whereMonth('created_at', '=', 4)
                ->whereMonth('created_at', '=', 5)
                ->whereMonth('created_at', '=', 6)
                ->whereMonth('created_at', '=', 7)
                ->whereMonth('created_at', '=', 8)
                ->whereMonth('created_at', '=', 9)
                ->whereMonth('created_at', '=', 10)
                ->whereMonth('created_at', '=', 11)
                ->whereMonth('created_at', '=', 12);
        })
        ->get();
Run Code Online (Sandbox Code Playgroud)

但这将返回从第 1 个月到第 12 个月范围内的所有记录。但我想要的是每月的数据,除了像这样创建多个变量之外,这是否可以实现?

          $intakesMonth1 = Intakes::whereYear('created_at', '=', 2018)
            ->whereMonth('created_at', '=', 1)
            ->get();

          $intakesMonth2 = Intakes::whereYear('created_at', '=', 2018)
            ->whereMonth('created_at', '=', 2)
            ->get();
Run Code Online (Sandbox Code Playgroud)

我希望我足够清楚并且有人知道更好的解决方案。

javascript php jquery laravel morris.js

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

Vue.js 在特定元素上添加类

所以我创建了一个基本的任务列表,我想在<li>点击时将它们设置为完成。当它被点击时,我希望将一个类添加到<li>点击的那个中。我无法通过文档弄清楚这一点,所以我希望有人可以帮助我:D

我已经拥有的代码:

        <transition-group name="list">
            <li  class="list-item list-group-item"  v-for="(task, index) in list" :key="task.id" v-on:click="finishTask(task.id)" >
                @{{ task.text }}
                <button @click="removeTask(task.id)" class="btn btn-danger btn-xs pull-right">Delete</button>
            </li>
        </transition-group>



    </ul>

</div>
Run Code Online (Sandbox Code Playgroud)

    // get the csrf token from the meta
var csrf_token = $('meta[name="csrf-token"]').attr('content');

export default {
    data() {
        return {
            list: [],
            taskInput: {
                id: '',
                text: ''
            }
        };
    },

    // So the tasks will show when the page is loaded
    created() {
        this.allTasks();
    },

    methods: {
        // get …
Run Code Online (Sandbox Code Playgroud)

laravel vue.js

3
推荐指数
2
解决办法
2万
查看次数

Laravel 5.5 BelongsToMany返回空

我正在尝试使用belongsToMany关系,我从来没有遇到任何问题,但由于某种原因它返回空.

我在Store模型中建立了我的关系,如下所示:

    public function images()
    {
        return $this->belongsToMany('App\Images', 'images_stores', 'image_id', 'store_id');
    }
Run Code Online (Sandbox Code Playgroud)

当我测试关系时,它只返回一个空集合没有错误,尽管它不是.这是我访问数据的方式:

    public function edit($id)
    {
        $store = Store::find($id);
        dd($store->images);

        return view('admin.pages.store.edit', compact('store'));
    }
Run Code Online (Sandbox Code Playgroud)

但它只会返回一个空集合,我希望有人可以帮我解决这个问题.这些是我的迁移文件,但我认为问题不在迁移文件中.

    Schema::create('images', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->string('path');
        $table->timestamps();
    });
    // pivot table
    Schema::create('images_stores', function (Blueprint $table) {
        $table->increments('id');

        $table->integer('image_id')->unsigned()->nullable();
        $table->foreign('image_id')->references('id')->on('images')->onDelete('cascade');

        $table->integer('store_id')->unsigned()->nullable();
        $table->foreign('store_id')->references('id')->on('stores')->onDelete('cascade');

        $table->timestamps();
    });
    // store table
    Schema::create('stores', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->string('location');
        $table->string('email');
        $table->timestamps();
    });
Run Code Online (Sandbox Code Playgroud)

多谢你们.

php laravel eloquent laravel-5 laravel-5.5

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

无法打开流或文件“/vagrant/storage/logs/laravel-****-**-**.log”:无法打开流:权限被拒绝

我正拼命地尝试在我的 Windows 10 笔记本电脑上设置一台 Vagrant 机器来开始使用 Laravel 5.8,我知道网络和 stackoverflow 上有 100 个类似的问题,但似乎没有一个能解决我的问题。

The stream or file "/vagrant/storage/logs/laravel-****-**-**.log" could not be opened: failed to open stream: Permission denied当我输入网站网址时,我不断收到执行信息 。

这似乎不是权限问题,即使我将目录 chmod 为 777,它仍然无法工作。

我习惯了我的 MacBook,它几乎开箱即用。然而我无法让它在我的 Windows 机器上工作,这对我来说并不奇怪。 文件夹的权限

vagrant 文件同步文件夹

config.vm.synced_folder "./", "/vagrant", type: "smb", owner: "vagrant", group: "www-data"

我正在使用的盒子

config.vm.box = "ubuntu/bionic64"

config.vm.box_url = "https://app.vagrantup.com/ubuntu/boxes/bionic64/versions/20181211.0.0/providers/virtualbox.box"

希望有人可以帮助我,我不知道为什么会发生这种情况,因为一切看起来都很好。

laravel composer-php vagrantfile vagrant-windows

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