Current File : /home/tradevaly/public_html/app/Http/Controllers/Admin/AdvertismentController.php |
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\Banner;
use Brian2694\Toastr\Facades\Toastr;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Intervention\Image\Facades\Image;
use Auth;
use App\Models\Category;
use App\Models\AdvertiserOrder;
use App\Models\User;
use Mail;
use Illuminate\Support\Facades\Notification;
use App\Notifications\admin\advertisment\ActiveAdvertisment;
class AdvertismentController extends Controller
{
public function index(){
$data['advertisments'] = Banner::latest()->paginate(12);
return view('backend.pages.advertisment.index')->with($data);
}
public function active(){
$data['advertisments'] = Banner::where('isActive', 1)
->whereNotNull('link')
->whereNotNull('image')
->whereNotNull('user_id')
->whereDate('end', '>=', Carbon::now())
->latest()
->paginate(12);
return view('backend.pages.advertisment.active')->with($data);
}
public function pending(){
$data['advertisments'] = Banner::where('isActive', 0)
->whereNotNull('link')
->whereNotNull('image')
->whereNotNull('user_id')
->latest()
->paginate(12);
return view('backend.pages.advertisment.pending')->with($data);
}
public function status($status,$id){
$banner = Banner::find($id);
$advertisment = AdvertiserOrder::where('banner_id',$id)->where('status','pending')->first();
$message = 'Advertisement is active and extended by 1month to add duration!.';
$user = User::find($banner->user_id);
$banner->isActive = 1;
if ($banner->end <= Carbon::now()) {
$banner->end = Carbon::now()->addMonth(1);
$message = 'Advertisement is activeted successfully !!.';
}
if($banner && $advertisment){
if($status == 'active'){
$banner->isActive = 1;
$banner->start = Carbon::now();
$banner->end = Carbon::now()->addMonth($advertisment->duration);
$advertisment->status = 'active';
$message = 'Advertisement is active and extended by '.$advertisment->duration.'month to add duration!';
}
else if($status == 'reject'){
$banner->isActive = 2;
$message = 'Advertisment Rejected Successfully !!';
}
$advertisment->save();
}
Notification::send($user, new ActiveAdvertisment($user));
Notification::route('mail', 'tradevalyb2b@gmail.com')->notify(new ActiveAdvertisment($user));
$banner->save();
Toastr::success($message);
return back();
}
public function inActive($id){
$banner = Banner::find($id);
$banner->isActive=0;
$banner->save();
Toastr::success('In active Successfully');
return back();
}
public function details($id){
$data['banner'] = Banner::findOrFail($id);
return view('backend.pages.advertisment.details')->with($data);
}
public function expired()
{
$data['advertisments'] = Banner::whereNotNull('link')
->whereNotNull('image')
->whereNotNull('user_id')
->whereDate('end', '<=', Carbon::now())
->latest()
->paginate(12);
return view('backend.pages.advertisment.expired')->with($data);
}
public function adminActive($id)
{
$banner = Banner::findOrFail($id);
$banner->start = Carbon::now();
$banner->end = Carbon::now()->addMonth(1);
$banner->isActive=1;
$banner->save();
Toastr::success('Active For 1 month');
return back();
}
}