Current File : //home/tradevaly/www/app/Http/Controllers/Admin/AdvertiserController.php |
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\User;
use App\Models\AdvertiserOrder;
use App\Models\GeneralInfo;
use Brian2694\Toastr\Facades\Toastr;
use Illuminate\Http\Request;
use App\Models\Category;
use Carbon\Carbon;
use Illuminate\Support\Facades\Storage;
use Intervention\Image\Facades\Image;
use Illuminate\Support\Facades\Auth;
use Str;
class AdvertiserController extends Controller
{
public function advertiser_banner(Request $request){
$data= Logo::first();
$categories = Category::where('parent_id' , 0)->latest()->get();
if($request->isMethod('post')){
$data->top_banner = $request->top_banner;
$data->classic_banner = $request->classic_banner;
$data->bottom_banner = $request->bottom_banner;
$data->top_category_banner = $request->top_category_banner;
$data->bottom_category_banner = $request->bottom_category_banner;
$data->top_buyer_banner = $request->top_buyer_banner;
$data->bottom_buyer_banner = $request->bottom_buyer_banner;
$data->top_company_banner = $request->top_company_banner;
$data->bottom_company_banner = $request->bottom_company_banner;
$data->top_product_banner = $request->top_product_banner;
$data->bottom_product_banner = $request->bottom_product_banner;
$data->top_manufacture_banner = $request->top_manufacture_banner;
$data->bottom_manufacture_banner = $request->bottom_manufacture_banner;
$data->top_banner_discount = $request->top_banner_discount;
$data->classic_banner_discount = $request->classic_banner_discount;
$data->bottom_banner_discount = $request->bottom_banner_discount;
$data->top_buyer_banner_discount = $request->top_buyer_banner_discount;
$data->bottom_buyer_banner_discount = $request->bottom_buyer_banner_discount;
$data->top_product_banner_discount = $request->top_product_banner_discount;
$data->bottom_product_banner_discount = $request->bottom_product_banner_discount;
$data->top_company_banner_discount = $request->top_company_banner_discount;
$data->bottom_company_banner_discount = $request->bottom_company_banner_discount;
$data->top_manufacture_banner_discount = $request->top_manufacture_banner_discount;
$data->bottom_manufacture_banner_discount = $request->bottom_manufacture_banner_discount;
$data->contact_banner_discount = $request->contact_banner_discount;
$data->top_category_banner_discount = $request->top_category_banner_discount;
$data->bottom_category_banner_discount = $request->bottom_category_banner_discount;
$data->contact_banner = $request->contact_banner;
$data->update();
Toastr::success('Success!','Information Updated Successfully!');
return back();
}
return view('backend.pages.users.advertiser',compact('data'));
}
public function index(){
$data['advertisers'] = AdvertiserOrder::where('payment_status','paid')->latest()->get();
return view('backend.pages.advertiser.index')->with($data);
}
public function pending_advertiser(){
$data['advertisers'] = AdvertiserOrder::where('payment_status','unpaid')->latest()->get();
return view('backend.pages.advertiser.pending')->with($data);
}
public function others_advertiser(){
$data['advertisers'] = AdvertiserOrder::latest()->get();
return view('backend.pages.advertiser.pending')->with($data);
}
public function status(Request $request, $id){
$advertiser = AdvertiserOrder::findOrFail($id);
if($advertiser->status == 'active'){
$advertiser->status = 'unactive';
}else{
$advertiser->status = 'active';
}
$advertiser->start_date = $request->start_date;
$advertiser->expire_date = $request->expire_date;
$advertiser->status = 'active';
$advertiser->save();
Toastr::success('Success!','Advertiser Status Updated Successfully!');
return back();
}
public function unactive_status($id){
$advertiser = AdvertiserOrder::findOrFail($id);
$advertiser->status = 'unactive';
$advertiser->save();
Toastr::error('Success!','Advertiser Status Updated Successfully!');
return back();
}
public function pushIntoEnv($key, $value)
{
$path = base_path('.env');
if (file_exists($path)) {
$lines = explode("\n", file_get_contents($path));
$settings = collect($lines)
->filter()
->transform(function ($item) {
return explode("=", $item, 2);
})->pluck(1, 0);
$settings[$key] = $value;
$rebuilt = $settings->map(function ($value, $key) {
return "$key=$value";
})->implode("\n");
file_put_contents($path, $rebuilt);
}
}
public function destroy_advertiser($id){
$advertiser = AdvertiserOrder::findOrFail($id);
$advertiser->delete();
Toastr::success('Success!','Advertiser Order Deleted Successfully!');
return back();
}
public function show_advertiser($id){
$invoice = AdvertiserOrder::with('user:id,name,industry,email,package_id,type,address,products,country_id')->where('id', $id)->firstOrFail();
return view('backend.pages.advertiser.invoice',compact('invoice'));
}
public function advertiserInvoiceDetails($id)
{
$invoice = AdvertiserOrder::with('user:id,name,industry,email,package_id,type,address,products,country_id')->where('id', $id)->firstOrFail();
return view('backend.pages.advertiser.invoice',compact('invoice'));
}
public function advertiserMoneyReceipt($id)
{
$money_receipt = AdvertiserOrder::where('id', $id)->with(['transaction' => function ($query){
$query->select('payment_method','order_id','total_amount','payment_type','transaction_id');
} ])->firstOrFail();
return view('backend.pages.advertiser.money_receipt',compact('money_receipt'));
}
}