HomeController.php_2 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\DMCities;
  4. use App\Restaurants;
  5. use App\User;
  6. use Illuminate\Http\Request;
  7. use Illuminate\Support\Facades\Hash;
  8. use Illuminate\Support\Str;
  9. use Session;
  10. use Auth;
  11. use File;
  12. use Image;
  13. use Brian2694\Toastr\Facades\Toastr;
  14. use Illuminate\Support\Facades\Redis;
  15. class HomeController extends Controller
  16. {
  17. /**
  18. * Create a new controller instance.
  19. *
  20. * @return void
  21. */
  22. public function __construct()
  23. {
  24. $this->middleware('auth');
  25. }
  26. public function marketings(){
  27. return view('marketing.marketings');
  28. }
  29. public function test_redis(){
  30. Redis::set("user:mujtaba","It is testing code");
  31. dd(Redis::get('user:mujtaba'));
  32. }
  33. public function create_link(Request $request){
  34. $campaign_name = $request->campaign_name;
  35. $campaign_date = $request->campaign_date;
  36. $campaign_type = $request->campaign_type;
  37. $site_url = $request->site_url;
  38. $link = '?a='.$campaign_type.'&c='.Str::slug($campaign_name).'&cd='.$campaign_date;
  39. return $site_url.($link);
  40. }
  41. public function make_slug(){
  42. $resto = Restaurants::all();
  43. foreach($resto as $r){
  44. $rr = Restaurants::find($r->id);
  45. $rr->resto_unique_name = Str::slug($r->name);
  46. $rr->save();
  47. }
  48. }
  49. /**
  50. * Show the application dashboard.
  51. *
  52. * @return \Illuminate\Contracts\Support\Renderable
  53. */
  54. public function index()
  55. {
  56. return view('auth.login');
  57. }
  58. public function dashboard(){
  59. if(Auth::user()->role=="administrator")
  60. return view('dashboards.admin_dashboard');
  61. return view('dashboards.resto_dashboard');
  62. }
  63. public function getLogout()
  64. {
  65. Session::flush();
  66. Auth::logout();
  67. return redirect('/');
  68. }
  69. public function change_password(){
  70. return view('password');
  71. }
  72. public function update_password(Request $request){
  73. $old_password = $request->old_password;
  74. $new_password = $request->password;
  75. $confirm_password = $request->confirm_password;
  76. $user = Auth::user();
  77. if ($user && Hash::check($old_password, $user->password)) {
  78. if($new_password==$confirm_password){
  79. $u = User::find($user->id);
  80. $u->password = Hash::make($new_password);
  81. $u->save();
  82. echo json_encode(array('type'=>'success','message'=>'Password changed successfully.'));
  83. }else{
  84. echo json_encode(array('type'=>'error','message'=>'new password and confirm password are not matched.'));
  85. exit;
  86. }
  87. }else{
  88. echo json_encode(array('type'=>'error','message'=>'Old password is incorrect, enter correct password.'));
  89. exit;
  90. }
  91. }
  92. public function download_image(Request $request){
  93. $data = $request->data;
  94. $data = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $data));
  95. file_put_contents(public_path('/uploads/qrcode/qrcode.png'), $data);
  96. $this->image_recreate(public_path('/uploads/qrcode/qrcode.png'));
  97. echo env('APP_PUBLIC_URL').'uploads/qrcode/qrcode.png';
  98. }
  99. public function image_recreate($sourceFile){
  100. $orig_filename = $sourceFile;
  101. $new_filename = $orig_filename;
  102. list($orig_w, $orig_h) = getimagesize($orig_filename);
  103. $orig_img = imagecreatefromstring(file_get_contents($orig_filename));
  104. $output_w = 2200;
  105. $output_h = 2200;
  106. // determine scale based on the longest edge
  107. if ($orig_h > $orig_w) {
  108. $scale = $output_h/$orig_h;
  109. } else {
  110. $scale = $output_w/$orig_w;
  111. }
  112. $scale = $scale-0.1;
  113. // calc new image dimensions
  114. $new_w = ($orig_w * $scale);
  115. $new_h = ($orig_h * $scale);
  116. // determine offset coords so that new image is centered
  117. $offest_x = (($output_w - $new_w) / 2);
  118. $offest_y = (($output_h - $new_h) / 2);
  119. // create new image and fill with background colour
  120. $new_img = imagecreatetruecolor($output_w, $output_h);
  121. $bgcolor = imagecolorallocate($new_img, 255, 255, 255); // red
  122. imagefill($new_img, 0, 0, $bgcolor); // fill background colour
  123. // copy and resize original image into center of new image
  124. imagecopyresampled($new_img, $orig_img, $offest_x, $offest_y, 0, 0, $new_w, $new_h, $orig_w, $orig_h);
  125. //save it
  126. imagejpeg($new_img, $new_filename, 80);
  127. }
  128. public function resizeMainRecipeImages(){
  129. $path = public_path('uploads/main_image');
  130. ini_set('max_execution_time', '300');
  131. $files = File::allfiles($path);
  132. foreach($files as $file){
  133. $pth = ($file->getRealPath());
  134. $file_name = $file->getFileName();
  135. echo "Main Image: ".$file_name."<br />";
  136. $destinationPath = public_path('/uploads/main_image/');
  137. if($file->getExtension()!="jfif") {
  138. $img = Image::make($destinationPath . '/' . $file_name)->resize(85, null, function ($constraint) {
  139. $constraint->aspectRatio();
  140. });
  141. $img->save($destinationPath . '/thumbnails/' . $file_name);
  142. }
  143. }
  144. }
  145. public function resizeLogo(){
  146. $path = public_path('uploads/logo');
  147. ini_set('max_execution_time', '300');
  148. $files = File::allfiles($path);
  149. foreach($files as $file){
  150. $pth = ($file->getRealPath());
  151. $file_name = $file->getFileName();
  152. echo "Main Image: ".$file_name."<br />";
  153. $destinationPath = public_path('/uploads/logo/');
  154. if($file->getExtension()!="jfif") {
  155. $img = Image::make($destinationPath . '/' . $file_name)->resize(50, null, function ($constraint) {
  156. $constraint->aspectRatio();
  157. });
  158. $img->save($destinationPath . '/thumbnails/' . $file_name);
  159. }
  160. }
  161. }
  162. public function resizeGalleryRecipeImages(){
  163. $path = public_path('uploads/resto-gallery');
  164. $files = File::allfiles($path);
  165. foreach($files as $file){
  166. $pth = ($file->getRealPath());
  167. $file_name = $file->getFileName();
  168. echo "Gallery: ".$file_name."<br />";
  169. $destinationPath = public_path('/uploads/resto-gallery/');
  170. if($file->getExtension()!="jfif"){
  171. $img = Image::make($destinationPath . '/' . $file_name)->resize(800, null, function ($constraint) {
  172. $constraint->aspectRatio();
  173. });
  174. $img->save($destinationPath . '/thumbnails/' . $file_name);
  175. }
  176. }
  177. }
  178. public function resizeGalleryRecipeImagesToGallery(){
  179. $path = public_path('uploads/resto-gallery');
  180. $files = File::allfiles($path);
  181. foreach($files as $file){
  182. $pth = ($file->getRealPath());
  183. $file_name = $file->getFileName();
  184. echo "Gallery: ".$file_name."<br />";
  185. $destinationPath = public_path('/uploads/resto-gallery/');
  186. if($file->getExtension()!="jfif"){
  187. $img = Image::make($destinationPath . '/' . $file_name)->resize(800, null, function ($constraint) {
  188. $constraint->aspectRatio();
  189. });
  190. $img->save($destinationPath . '/gallery-resized/' . $file_name);
  191. }
  192. }
  193. }
  194. public function load_json(){
  195. $jsonString = file_get_contents("https://api.chatfood.io/api/v1/businesses/ceeba7a3-5dd4-48a7-9a07-96111efab2e4/areas");
  196. $data = json_decode($jsonString, true);
  197. // dd($data);
  198. foreach($data as $city){
  199. foreach($city as $cc){
  200. // dump($cc);
  201. $c = new DMCities();
  202. $c->city_name = $cc['name'];
  203. $c->city_unique_id = $cc['id'];
  204. $c->save();
  205. }
  206. /* */
  207. }
  208. }
  209. }