Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.18 KB | None | 0 0
  1. public function update(StoreUserInfo $request, User $user)
  2. {
  3. if ( !($user->id == Auth::user()->id)) {
  4. abort(404);
  5. }
  6.  
  7. $request->validated();
  8.  
  9. $user->where('id', $user->id)->update(
  10. [
  11. 'first_name' => $request->first_name,
  12. 'last_name' => $request->last_name,
  13. 'email' => $request->email,
  14. 'city' => $request->city,
  15. 'type' => $request->type,
  16. 'updated_at' => Carbon::now()
  17. ]
  18. );
  19.  
  20.  
  21. // FROM HERE IS RELEVANT CODE!!!
  22.  
  23. $query = Property::query();
  24.  
  25. if ($request->has('propertyType1')) {
  26. $request->get('propertyType1');
  27. }
  28.  
  29. $propertyType1 = $request->input('propertyType1');
  30.  
  31. if (!empty($propertyType1)) {
  32. $query->whereHas('category', function ($query) use ($propertyType1) {
  33. $query->whereIn('category', $propertyType1);
  34. });
  35. }
  36.  
  37. $resultsFiltered = $query->where('active', 'Q')
  38. ->orWhere('active', 'A')
  39. ->orderBy('page_views', 'desc')
  40. ->with('user.photo', 'photos', 'category')->paginate(5);
  41.  
  42.  
  43. // TO HERE IS RELEVANT CODE!!!
  44.  
  45.  
  46. $photo = ($request->image[0] === ',') ?
  47. ltrim($request->image, ',') : $request->image;
  48. DB::table('photos')->where('filename', $photo)
  49. ->update(
  50. [
  51. 'user_id' => $user->id,
  52. 'model_type' => 'AppUser',
  53. 'model_id' => '',
  54. 'original_src' => "user/$user->id/gallery",
  55. 'primary' => '1',
  56. 'alt_attribute' => '',
  57. 'updated_at' => Carbon::now()
  58. ]
  59. );
  60.  
  61. $image_data = DB::table('photos')
  62. ->where('user_id', $user->id)
  63. ->where('alt_attribute', 'Delete')
  64. ->first();
  65.  
  66. if ($image_data) {
  67. Storage::delete(
  68. "public/$image_data->original_src/$image_data->filename"
  69. );
  70. DB::table('photos')
  71. ->where('filename', $image_data->filename)
  72. ->delete();
  73. }
  74.  
  75. Storage::exists("public/tmp/$photo") ?
  76. Storage::move(
  77. "public/tmp/$photo",
  78. "public/user/$user->id/gallery/$photo"
  79. ) : '';
  80.  
  81. return view('startpage', compact('resultsFiltered', 'category', 'request', 'user.photo', 'photos', 'propertyType'));
  82. }
  83.  
  84. <form id="form" method="POST" action="{{ route('user.update',['id'=>$user->id]) }}">
  85.  
  86. {{-- PREFERENCES !!!!! --}}
  87.  
  88. <div class="row page-hero d-flex align-items-center justify-content-center">
  89. <label for="preferences" class="text-center">Select your preferences</label>
  90. </div>
  91. <div class="row">
  92. <div class="col-md-1" style="margin-right:15px; margin-left:60px;">
  93. <div class="custom-control custom-checkbox">
  94. <input id="house" name="propertyType1[]" value="house" type="checkbox" class="custom-control-input">
  95. <label class="custom-control-label" for="house">House</label>
  96. </div>
  97. </div>
  98. <div class="col-md-1" style="margin-right:15px;">
  99. <div class="custom-control custom-checkbox">
  100. <input id="flat" name="propertyType1[]" value="flat" type="checkbox" class="custom-control-input">
  101. <label class="custom-control-label" for="flat">flat</label>
  102. </div>
  103. </div>
  104. <div class="col-md-1" style="margin-right:50px;">
  105. <div class="custom-control custom-checkbox">
  106. <input id="apartment" name="propertyType1[]" value="apartment" type="checkbox" class="custom-control-input">
  107. <label class="custom-control-label" for="apartment">apartment</label>
  108. </div>
  109. </div>
  110. <div class="col-md-1" style="margin-right:15px;">
  111. <div class="custom-control custom-checkbox">
  112. <input id="room" name="propertyType1[]" value="room" type="checkbox" class="custom-control-input">
  113. <label class="custom-control-label" for="room">room</label>
  114. </div>
  115. </div>
  116. <div class="col-md-1" style="margin-right:15px;">
  117. <div class="custom-control custom-checkbox">
  118. <input id="shop" name="propertyType1[]" value="shop" type="checkbox" class="custom-control-input">
  119. <label class="custom-control-label" for="shop">shop</label>
  120. </div>
  121. </div>
  122. <div class="col-md-1" style="margin-right:15px;">
  123. <div class="custom-control custom-checkbox">
  124. <input id="lot" name="propertyType1[]" value="lot" type="checkbox" class="custom-control-input">
  125. <label class="custom-control-label" for="lot">lot</label>
  126. </div>
  127. </div>
  128. <div class="col-md-1" style="margin-right:15px;">
  129. <div class="custom-control custom-checkbox">
  130. <input id="garage" name="propertyType1[]" value="garage" type="checkbox" class="custom-control-input">
  131. <label class="custom-control-label" for="garage">garage</label>
  132. </div>
  133. </div>
  134. </div>
  135.  
  136. {{-- END PREFERENCES !!!!! --}}
  137.  
  138. <button form="form" type="submit" class="btn btn-primary">
  139. Save changes
  140. /button>
  141.  
  142. </form>
  143.  
  144. <div class="col-md-3 justify-content-md-center">
  145. <h1>Prefered ads</h1>
  146.  
  147. @if (isset($resultsFiltered))
  148. @foreach ($resultsFiltered as $resultFiltered)
  149. <div class="row">
  150. <a href="{{route('property.show',['id'=>$resultFiltered->id])}}">
  151. @if ($resultFiltered->active == 'A')
  152. <button class="btn btn-success" disabled="dissabled">Verified</button>
  153. @endif
  154.  
  155. <img class="img-fluid" src="/storage/{{$resultFiltered->main_photo['original_src']}}/{{$resultFiltered->main_photo['filename']}}" alt="Card image cap">
  156. <button type="button" class="btn btn-lg btn-primary" disabled style="margin-top:10px;">{{$resultFiltered->price}} eur</button>
  157. <button type="button" class="btn btn-lg btn-primary" disabled style="margin-top:10px;">{{$resultFiltered->quadrature}} m<sup>2</sup></button>
  158. <button type="button" class="btn btn-lg btn-primary" disabled style="margin-top:10px; margin-bottom:10px;">{{$resultFiltered->city}}</button>
  159. <hr>
  160. </a>
  161. </div>
  162. @endforeach
  163. @endif
  164. </div>
  165.  
  166. Route::put('/user/{user}', 'UserController@update')->name('user.update');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement