Я пытаюсь создать модель запроса, в которой каждый раз, когда отправляется запрос, конкретные пользователи уведомляются по почте, а их записи уменьшаются на 1. Почта работает нормально, но уменьшение происходит на количество идентифицированных пользователей, а не на 1.
Пробовали разные P&C.
$exclusive = DB::table('user_plans')
->leftJoin('companies', 'companies.id' , '=', 'user_plans.user_id')
->select('user_plans.*')
->where('user_plans.service_id' , '=', $input['project'])
->where('user_plans.lead_type' , '=', 2)
->where('user_plans.count' , '>', 0)
->limit(5)
->get();
$shared = DB::table('user_plans')
->leftJoin('companies', 'companies.id' , '=', 'user_plans.user_id')
->select('user_plans.*')
->where('user_plans.service_id' , '=', $input['project'])
->where('user_plans.lead_type' , '=', 1)
->where('user_plans.count' , '>', 0)
->limit(500)
->get();
$project = DB::table('services')
->select('services.*')
->where('services.id' , '=', $input['project'])
->get();
if (count($exclusive) > 0) {
foreach ($exclusive as $exclusive) {
Mail::send('emails.exclusive', array(
'name' => $input['name'],
'email' => $input['email'],
'phone' => $input['phone'],
'detail' => $input['detail'],
'project' => $project[0]->name,
'budget' => $input['budget']
), function($message) use ($exclusive) {
$message
->to($exclusive->lead_email)
->subject('CXO Forest Contact Us!');
});
//This part is not working
$deduct = DB::table('user_plans')
->where('user_plans.user_id' , '=', $exclusive->user_id)
->where('user_plans.count' , '>', 0)
->where('user_plans.type' , '=', 2)
//->get();
->decrement('count', 1);
}
} else {
if (count($shared) > 0) {
foreach ($shared as $shared) {
Mail::send('emails.exclusive', array(
'name' => $input['name'],
'email' => $input['email'],
'phone' => $input['phone'],
'detail' => $input['detail'],
'project' => $project[0]->name,
'budget' => $input['budget']
), function($message) use ($shared) {
$message
->to($shared->lead_email)
->subject('CXO Forest Contact Us!');
});
$deductx = DB::table('user_plans')
->where('user_plans.user_id' , '=', $shared->user_id)
->where('user_plans.count' , '>', 0)
->where('user_plans.type' , '=', 2)
->decrement('count', 1);
}
} else {
Mail::send('emails.exclusive', array(
'name' => $input['name'],
'email' => $input['email'],
'phone' => $input['phone'],
'detail' => $input['detail'],
'project' => $project[0]->name,
'budget' => $input['budget']
), function($message) use ($shared) {
$message
->to('[email protected]')
->subject('Urgent: This lead does not have any takers');
});
}
}
Каждый раз, когда код запускается, вычитание должно уменьшать user_plans на 1, а не количество отправленных писем.
Спасибо, ребята, за помощь.






Вот часть, которая не работает, попробуйте это:
DB::table('user_plans') ->where('user_plans.user_id' , '=', $exclusive->user_id) ->where('user_plans.count' , '>', 0) ->where('user_plans.type' , '=', 2) ->take(1)->delete();