Current File : /home/tradevaly/new.tradevaly.com.bd/app/Http/Controllers/Frontend/ContactController.php |
<?php
namespace App\Http\Controllers\Frontend;
use App\Http\Controllers\Controller;
use App\Models\Contact;
use App\Models\Help;
use App\Models\User;
use App\Models\Company;
use Auth;
use App\Models\Banner;
use Brian2694\Toastr\Facades\Toastr;
use Illuminate\Http\Request;
use Mail;
class ContactController extends Controller
{
public function contact(Request $request){
if($request->isMethod('post')){
$request->validate([
'question'=> 'required',
'name'=> 'required',
'phone'=> 'required',
'company'=> 'required',
'country_id'=> 'required',
'category_id'=> 'required',
'role'=> 'required',
'g-recaptcha-response' => 'required|capctcha',
]);
$info= new Contact;
$info->question=$request['question'];
$info->name=$request['name'];
$info->phone=$request['phone'];
$info->email=$request['email'];
if(!filter_var($request['email'], FILTER_VALIDATE_EMAIL)){
Toastr::error('Invalid Email ID!','Got it');
return redirect()->back();
}
$info->company=$request['company'];
$info->category_id=$request['category_id'];
$info->role=$request['role'];
$info->save();
$user = new User();
$user->name = $request->name;
$user->category_id = $request->category_id;
$user->email = $request->email;
if($request->username){
$request->username;
}else{
$user->username = $request->name;
}
$user->type = $request->role;
$user->image = 'image.jpg';
$user->password = bcrypt($request->name.'123');
$user->country_id = $request->country_id;
$user->package_id = 1;
$user->next_pay = date('Y-m-d',strtotime("+25000 days"));
if(User::where('email', $request->email)->first() != null){
Toastr::success('Email Already Exists', '', ['progressBar' => true, 'closeButton' => true, 'positionClass' => 'toast-top-right']);
return redirect()->back();
}
if($user->save()){
$company = new Company();
$company->user_id = $user->id;
$company->name = $request->company;
$company->category_id = $request->category_id;
$company->image = 'image.jpg';
$company->phone = $request->phone;
$user->password =$request->name.'123';
if($company->save()){
Mail::to($request->email)->send(new \App\Mail\RegistrationComfirm($user));
Toastr::success('Registration Successfull Please Check Your Email !!', '', ['progressBar' => true, 'closeButton' => true, 'positionClass' => 'toast-top-right']);
return view('thankyou');
}
}
return redirect()->back();
}
}
public function view($id){
$massage=Contact::find($id);
$msgs=Contact::all();
return view('backend.pages.massage')->with(compact('massage','msgs'));
}
public function delete($id){
$massage=Contact::find($id)->delete();
Toastr::success('Deleted!','Got it');
return redirect('b2b/dashboard');
return view('backend.pages.massage')->with(compact('massage','msgs'));
}
// Contact us section
public function help(Request $request){
$info= new Help();
if($request->isMethod('post')){
$request->validate([
'f_name' => 'required',
'l_name' => 'required',
'u_name' => 'required',
'phone' => 'required',
'email' => 'required',
'c_name' => 'required',
'message' => 'required',
'g-recaptcha-response' => 'required|captcha',
]);
$info->f_name=$request['f_name'];
$info->l_name=$request['l_name'];
$info->u_name=$request['u_name'];
$info->phone=$request['phone'];
$info->email=$request['email'];
$info->c_name=$request['c_name'];
$info->message=$request['message'];
if(empty($request['f_name']) || empty($request['l_name']) || empty($request['u_name']) || empty($request['email']) || empty($request['message']) || empty($request['phone'])){
Toastr::error('One Or More Required Field Left Empty!','Got it');
return redirect()->back();
}
$info->save();
Mail::to('office.mollameehedi@gmail.com')->send(new \App\Mail\ContactMessage($info));
Toastr::success('We will response soon!','Got it');
return redirect()->back();
}
$data['banners'] = Banner::where('position','contact-banner')->latest()->get();
return view('frontend.pages.contact')->with($data);
}
public function index(){
$data['helps']=Help::latest()->get();
return view('backend.pages.help.index')->with($data);
}
public function show($id){
$help=Help::findOrFail($id);
return view('backend.pages.help.show')->with(compact('help'));
}
public function c_delete($id){
$massage=Help::find($id)->delete();
Toastr::success('Deleted Successfully!','Success.');
return back();
}
}