这是我的代码,致力于向多个用户发送通知电子邮件
$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)
如何使用队列和通知外观向多个用户发送通知电子邮件?
感谢帮助
为什么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)
感谢帮助 ;)
如何检索集合中元素的索引?我的代码:
$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)
感谢帮助
我需要帮助来使用 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) 当我在 Laravel 项目中尝试 composer update 时,终端上出现此错误
In ProviderRepository.php line 208:
Class 'Carbon\Laravel\ServiceProvider' not found
Run Code Online (Sandbox Code Playgroud)
任何建议表示赞赏。
laravel ×5
php ×5
collections ×2
eloquent ×2
mysql ×2
queue ×2
closures ×1
composer-php ×1
facade ×1