123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302 |
- <?php
- namespace App\Http\Controllers;
- use App\DMCities;
- use App\Restaurants;
- use App\User;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Hash;
- use Illuminate\Support\Str;
- use Session;
- use Auth;
- use File;
- use Image;
- use Brian2694\Toastr\Facades\Toastr;
- use Illuminate\Support\Facades\Redis;
- class HomeController extends Controller
- {
- /**
- * Create a new controller instance.
- *
- * @return void
- */
- public function __construct()
- {
- $this->middleware('auth');
- }
- public function marketings(){
- return view('marketing.marketings');
- }
- public function test_redis(){
- Redis::set("user:mujtaba","It is testing code");
- dd(Redis::get('user:mujtaba'));
- }
- public function create_link(Request $request){
- $campaign_name = $request->campaign_name;
- $campaign_date = $request->campaign_date;
- $campaign_type = $request->campaign_type;
- $site_url = $request->site_url;
- $link = '?a='.$campaign_type.'&c='.Str::slug($campaign_name).'&cd='.$campaign_date;
- return $site_url.($link);
- }
- public function make_slug(){
- $resto = Restaurants::all();
- foreach($resto as $r){
- $rr = Restaurants::find($r->id);
- $rr->resto_unique_name = Str::slug($r->name);
- $rr->save();
- }
- }
- /**
- * Show the application dashboard.
- *
- * @return \Illuminate\Contracts\Support\Renderable
- */
- public function index()
- {
- return view('auth.login');
- }
- public function dashboard(){
- if(Auth::user()->role=="administrator")
- return view('dashboards.admin_dashboard');
- return view('dashboards.resto_dashboard');
- }
- public function getLogout()
- {
- Session::flush();
- Auth::logout();
- return redirect('/');
- }
- public function change_password(){
- return view('password');
- }
- public function update_password(Request $request){
- $old_password = $request->old_password;
- $new_password = $request->password;
- $confirm_password = $request->confirm_password;
- $user = Auth::user();
- if ($user && Hash::check($old_password, $user->password)) {
- if($new_password==$confirm_password){
- $u = User::find($user->id);
- $u->password = Hash::make($new_password);
- $u->save();
- echo json_encode(array('type'=>'success','message'=>'Password changed successfully.'));
- }else{
- echo json_encode(array('type'=>'error','message'=>'new password and confirm password are not matched.'));
- exit;
- }
- }else{
- echo json_encode(array('type'=>'error','message'=>'Old password is incorrect, enter correct password.'));
- exit;
- }
- }
- public function download_image(Request $request){
- $data = $request->data;
- $data = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $data));
- file_put_contents(public_path('/uploads/qrcode/qrcode.png'), $data);
- $this->image_recreate(public_path('/uploads/qrcode/qrcode.png'));
- echo env('APP_PUBLIC_URL').'uploads/qrcode/qrcode.png';
- }
- public function image_recreate($sourceFile){
- $orig_filename = $sourceFile;
- $new_filename = $orig_filename;
- list($orig_w, $orig_h) = getimagesize($orig_filename);
- $orig_img = imagecreatefromstring(file_get_contents($orig_filename));
- $output_w = 2200;
- $output_h = 2200;
- // determine scale based on the longest edge
- if ($orig_h > $orig_w) {
- $scale = $output_h/$orig_h;
- } else {
- $scale = $output_w/$orig_w;
- }
- $scale = $scale-0.1;
- // calc new image dimensions
- $new_w = ($orig_w * $scale);
- $new_h = ($orig_h * $scale);
- // determine offset coords so that new image is centered
- $offest_x = (($output_w - $new_w) / 2);
- $offest_y = (($output_h - $new_h) / 2);
- // create new image and fill with background colour
- $new_img = imagecreatetruecolor($output_w, $output_h);
- $bgcolor = imagecolorallocate($new_img, 255, 255, 255); // red
- imagefill($new_img, 0, 0, $bgcolor); // fill background colour
- // copy and resize original image into center of new image
- imagecopyresampled($new_img, $orig_img, $offest_x, $offest_y, 0, 0, $new_w, $new_h, $orig_w, $orig_h);
- //save it
- imagejpeg($new_img, $new_filename, 80);
- }
- public function resizeMainRecipeImages(){
- $path = public_path('uploads/main_image');
- ini_set('max_execution_time', '300');
- $files = File::allfiles($path);
- foreach($files as $file){
- $pth = ($file->getRealPath());
- $file_name = $file->getFileName();
- echo "Main Image: ".$file_name."<br />";
- $destinationPath = public_path('/uploads/main_image/');
- if($file->getExtension()!="jfif") {
- $img = Image::make($destinationPath . '/' . $file_name)->resize(85, null, function ($constraint) {
- $constraint->aspectRatio();
- });
- $img->save($destinationPath . '/thumbnails/' . $file_name);
- }
- }
- }
- public function resizeLogo(){
- $path = public_path('uploads/logo');
- ini_set('max_execution_time', '300');
- $files = File::allfiles($path);
- foreach($files as $file){
- $pth = ($file->getRealPath());
- $file_name = $file->getFileName();
- echo "Main Image: ".$file_name."<br />";
- $destinationPath = public_path('/uploads/logo/');
- if($file->getExtension()!="jfif") {
- $img = Image::make($destinationPath . '/' . $file_name)->resize(50, null, function ($constraint) {
- $constraint->aspectRatio();
- });
- $img->save($destinationPath . '/thumbnails/' . $file_name);
- }
- }
- }
- public function resizeGalleryRecipeImages(){
- $path = public_path('uploads/resto-gallery');
- $files = File::allfiles($path);
- foreach($files as $file){
- $pth = ($file->getRealPath());
- $file_name = $file->getFileName();
- echo "Gallery: ".$file_name."<br />";
- $destinationPath = public_path('/uploads/resto-gallery/');
- if($file->getExtension()!="jfif"){
- $img = Image::make($destinationPath . '/' . $file_name)->resize(800, null, function ($constraint) {
- $constraint->aspectRatio();
- });
- $img->save($destinationPath . '/thumbnails/' . $file_name);
- }
- }
- }
- public function resizeGalleryRecipeImagesToGallery(){
- $path = public_path('uploads/resto-gallery');
- $files = File::allfiles($path);
- foreach($files as $file){
- $pth = ($file->getRealPath());
- $file_name = $file->getFileName();
- echo "Gallery: ".$file_name."<br />";
- $destinationPath = public_path('/uploads/resto-gallery/');
- if($file->getExtension()!="jfif"){
- $img = Image::make($destinationPath . '/' . $file_name)->resize(800, null, function ($constraint) {
- $constraint->aspectRatio();
- });
- $img->save($destinationPath . '/gallery-resized/' . $file_name);
- }
- }
- }
- public function load_json(){
- $jsonString = file_get_contents("https://api.chatfood.io/api/v1/businesses/ceeba7a3-5dd4-48a7-9a07-96111efab2e4/areas");
- $data = json_decode($jsonString, true);
- // dd($data);
- foreach($data as $city){
- foreach($city as $cc){
- // dump($cc);
- $c = new DMCities();
- $c->city_name = $cc['name'];
- $c->city_unique_id = $cc['id'];
- $c->save();
- }
- /* */
- }
- }
- }
|