小编use*_*349的帖子

Laravel通知电子邮件门面排队多个用户

这是我的代码,致力于向多个用户发送通知电子邮件

$users = User::whereIn('id', $userIds)->get();
\Notification::send($users, new DealPublished($deal));
Run Code Online (Sandbox Code Playgroud)

它有效,但如果我想延迟它那样

$users = User::whereIn('id', $userIds)->get();

$when = Carbon::now()->addSecond();

\Notification::send($users, new DealPublished($deal))->when($when);
Run Code Online (Sandbox Code Playgroud)

错误是

FatalThrowableError in DealController.php line 226:
Call to a member function when() on null
Run Code Online (Sandbox Code Playgroud)

如何使用队列和通知外观向多个用户发送通知电子邮件?

感谢帮助

php queue notifications facade laravel

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

Laravel 5.3对sortBy集合的分页

为什么paginate方法不适用于此示例?

$shopIds = Follower::whereUserId($user->id)->orderBy('created_at','desc')->get()->pluck('shop_id')->toArray();
            $shops = Shop::whereIn('id',$shopIds)->with('deals')->with('deals.likes')->paginate($this->perPage)->sortBy(function($likes) {
                return $likes->count();
            });
            dd($shops);
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

感谢帮助 ;)

php mysql collections laravel eloquent

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

如何获取Laravel集合中的元素索引

如何检索集合中元素的索引?我的代码:

$users = User::has('posts')->withCount('posts')->orderBy('posts_count')->take(50)->get();

if($users->contains(Auth::id())){
    //get the index of auth user id
 }
Run Code Online (Sandbox Code Playgroud)

感谢帮助

php mysql collections laravel eloquent

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

Laravel 队列“Closure”序列化是不允许的

我需要帮助来使用 Laravel 分派作业,似乎系统在使用队列作业时尝试序列化闭包,因此出现此错误。

我该如何解决这个问题?我也尝试过这个包
https://github.com/jeremeamia/super_closure
但它在我的情况下不起作用。

这是我的代码:

在控制器 FacebookController 中:

public function getPosts(\SammyK\LaravelFacebookSdk\LaravelFacebookSdk $fb) //get all post of logged user
{
    dispatch(new SyncFacebook($fb));
}
Run Code Online (Sandbox Code Playgroud)

以及要调度的作业:

<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

use Session, DB, Carbon\Carbon, Auth;

use App\{
    User, Reaction, Post, Synchronisation
};

class SyncFacebook implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $fb;

    public function __construct($fb)
    {
        $this->fb = $fb;
    }

    public function handle()
    {
        set_time_limit(0);
        $user = Auth::user();

        try { …
Run Code Online (Sandbox Code Playgroud)

php queue closures laravel

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

作曲家更新时找不到类'Carbon\Laravel\ServiceProvider'

当我在 Laravel 项目中尝试 composer update 时,终端上出现此错误

In ProviderRepository.php line 208:

Class 'Carbon\Laravel\ServiceProvider' not found
Run Code Online (Sandbox Code Playgroud)

任何建议表示赞赏。

php laravel composer-php

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