|
Server : Apache/2.4.41 (Ubuntu) System : Linux vmi1525618.contaboserver.net 5.4.0-105-generic #119-Ubuntu SMP Mon Mar 7 18:49:24 UTC 2022 x86_64 User : www-data ( 33) PHP Version : 8.2.12 Disable Function : NONE Directory : /var/www/leadai/webmaster.leadai.co.in/app/Http/Controllers/ |
Upload File : |
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Plan;
use Illuminate\Support\Facades\Validator;
class PlanController extends Controller
{
private $admin_id,$allData,$data,$res,$validator;
public function __construct()
{
$this->middleware(function ($request, $next)
{
// fetch session and use it in entire class with constructor
if(session()->get('loggedIn')['user_type'] == 'superadmin')
{
$this->admin_id = session()->get('loggedIn')['id'];
}
else
{
$this->admin_id = session()->get('loggedIn')['admin_id'];
}
return $next($request);
});
}
public function export()
{
// Export Data
$filename = "employee.xlsx";
return Excel::download(new EmployeeExport($this->admin_id), $filename);
}
public function import(Request $request)
{
$file = $request->file('excel_file');
Excel::import(new EmployeeImport, $file);
return response()->json(["message"=>"success"],200);
}
public function index()
{
$this->data['mainMenu'] = 'settings';
$this->data['subMenu'] = 'plan-list';
$search = isset($_GET["search"]) ? $_GET["search"] : null;
$name = isset($_GET["name"]) ? $_GET["name"] : null;
$mobile = isset($_GET["mobile"]) ? $_GET["mobile"] : null;
$email = isset($_GET["email"]) ? $_GET["email"] : null;
$city = isset($_GET["city"]) ? $_GET["city"] : null;
$start_date = isset($_GET["start_date"]) ? $_GET["start_date"] : null;
$end_date = isset($_GET["end_date"]) ? $_GET["end_date"] : null;
$query = Plan::query();
if ($search) {
$query->where('name', 'LIKE', '%' . $search . '%');
}
if ($name) {
$query->where('name', 'LIKE', '%' . $name . '%');
}
if ($mobile) {
$query->where('mobile', 'LIKE', '%' . $mobile . '%');
}
if ($email) {
$query->where('email', 'LIKE', '%' . $email . '%');
}
if ($city) {
$query->where('city', 'LIKE', '%' . $city . '%');
}
if($start_date && $end_date)
{
$query->WhereBetween('created_at', [$start_date, $end_date]);
}
$this->data["plans"]= $query->orderBy("created_at","desc")->paginate(10);
return view('plans.list',$this->data);
}
public function addPlan()
{
$this->data['mainMenu'] = 'settings';
$this->data['subMenu'] = 'plan-list';
return view('plans.add',$this->data);
}
public function storePlan(Request $request)
{
$this->allData = $request->all();
$this->validator = Validator::make($this->allData, [
'plan_name' => "required",
'lead_limit' => "required",
'organization_limit' => 'required',
"contact_limit" => 'required',
'lead_type' => "required",
'contact_type'=>"required",
]
);
if ($this->validator->fails())
{
return back()->withErrors($this->validator)->withInput();
}
else
{
$this->res = Plan::create($this->allData);
if($this->res)
{
return back()->with("success","Plan create successfully !");
}
else
{
return back()->with("error","Failed !");
}
}
}
public function edit($id)
{
$this->data['mainMenu'] = 'settings';
$this->data['subMenu'] = 'plan-list';
$this->data['plan'] = Plan::where('id',$id)->first();
return view('plans.edit',$this->data);
}
public function update(Request $request)
{
$this->allData = $request->all();
$this->validator = Validator::make($this->allData, [
'plan_name' => "required",
'lead_limit' => "required",
'organization_limit' => 'required',
"contact_limit" => 'required',
'lead_type' => "required",
'contact_type'=>"required",
]
);
if ($this->validator->fails())
{
return back()->withErrors($this->validator)->withInput();
}
else
{
unset($this->allData["plan_id"]);
unset($this->allData["_token"]);
$this->res = Plan::where("id",$request->plan_id)->update($this->allData);
if($this->res)
{
return back()->with("success","Plan Update successfully !");
}
else
{
return back()->with("error","Failed !");
}
}
}
public function delete(Request $request)
{
$this->res = Plan::where('id',$request->plan_id)->delete();
if($this->res)
{
return "success";
}
else
{
return "failed";
}
}
}