Current File : /home/tradevaly/www/app/Http/Controllers/Admin/EmailController.php |
<?php
namespace App\Http\Controllers\admin;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Mail;
use Illuminate\Support\Facades\Notification;
use App\Notifications\admin\email\SendMessage;
use App\Models\User;
use Brian2694\Toastr\Facades\Toastr;
class EmailController extends Controller
{
public $data;
public function index()
{
return view('backend.pages.email.index');
}
public function sent(Request $request)
{
$users = User::all();
$sellers = User::where('type','seller')->get();
$buyers = User::where('type','buyer')->get();
[
'email_subject'=>'required',
'email_body'=> 'required'
];
if($request->user_type == 'seller')
{
foreach ($sellers as $seller) {
if (filter_var($seller->email, FILTER_VALIDATE_EMAIL)){
Notification::send($seller, new SendMessage($request));
}
}
}
elseIf($request->user_type == 'buyer')
{
foreach ($buyers as $buyer) {
if (filter_var($buyer->email, FILTER_VALIDATE_EMAIL)){
Notification::send($buyer, new SendMessage($request));
}
}
}
elseIf($request->user_type == 'all')
{
foreach ($users as $user) {
if (filter_var($user->email, FILTER_VALIDATE_EMAIL)){
Notification::send($user, new SendMessage($request));
}
}
}
Toastr::success('Email Sent Successfully!', '', ['progressBar' => true, 'closeButton' => true, 'positionClass' => 'toast-top-right']);
return back();
}
}