select count(*), sum(type = 'user'), sum(type = 'customer') from `users` where created_at <= `2019-07-12`
class Article
{
public function voters()
{
return $this->belongsToMany('App\Models\User')->withPivot('score');
}
}
$user
->with(['favorite', 'favorite' => function($query) use ($user) {
$query
->with('voters')
->where('user_id', $user->id);
}])
select count(*) as aggregate from `models` where `id` = ?
DB::transaction(function () use ($request) {
$user = User::where('id', Auth::user()->id)->lockForUpdate()->first();
if ($user->balance < $request->money) {
throw new \Exception('Insufficient funds');
}
//Снимаем деньги со счета пользователя
$user->decrement('balance', $request->money);
//Переводим деньги другому пользователю
User::where('id', $request->receiver_id)->increment('balance', $request->money);
//Добавляем в бд запись о транзакции
$transaction = MoneyTransaction::create($request->all() + ['sender_id' => $user->id, 'type_id' => 2]);
});
B2c_tires_address::where('b2c_tires_id', $userId)
->with('phones', 'photos')
->orderBy('priority')
->get();