Guest User

Untitled

a guest
Mar 23rd, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.69 KB | None | 0 0
  1. @extends('layouts.app')
  2.  
  3. @section('content')
  4. <link rel="stylesheet" href="{{ elixir('css/petsbook.css') }}">
  5. <meta name="csrf-token" content="{{ csrf_token() }}">
  6.  
  7. <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
  8.  
  9. <div class="col-md-6 col-lg-6 col-md-offset-3 col-lg-offset-3">
  10. <div class="panel panel-primary ">
  11. <div class="col-lg-6 col-lg-offset-3">
  12. <div class="wrapper">
  13.  
  14. <form id="form">
  15. <input class="input" type="text" name="search" id="search" class="form-control pull-left" placeholder="Search Exercise...">
  16.  
  17.  
  18. </form>
  19. </div>
  20. </div>
  21.  
  22. <div class="panel-body">
  23.  
  24. <h1 class="hidden">List of Exercise </h1>
  25. <ul class="list-group">
  26. @foreach($pets as $pet)
  27. <li class="list-group-item" id="data">
  28.  
  29. <a id="name" href="/pets/{{ $pet->id }}" > {{ $pet->name }}</a></li>
  30. @endforeach
  31. </ul>
  32.  
  33.  
  34. </div>
  35. </div>
  36. </div>
  37.  
  38.  
  39. <h1 class="hidden">The search </h1>
  40.  
  41. <script type ="text/javascript">
  42. $(document).ready(function()
  43. {
  44. $.ajaxSetup({
  45. headers:{
  46. 'X-CSRF-TOKEN' : $('meta[name="csrf-token"]').attr('content')
  47. }
  48. });
  49.  
  50.  
  51. $('#form').on('input',function(e)
  52. {
  53. e.preventDefault();
  54. data = $(this).serialize();
  55. $.post('/getSearch', data, function(search)
  56. {
  57. $('#data').html('');
  58. $.each(search, function (key,val){
  59. $('#data').append(''+
  60. '<li class="list-group-item" id="data"> <a id="name" href="/pets/{{ $pet->id }}" >'+val.name+'</a></li>'+
  61.  
  62.  
  63.  
  64. '');
  65.  
  66. });
  67.  
  68. });
  69. });
  70. });
  71.  
  72. </script>
  73.  
  74.  
  75.  
  76. @endsection
  77.  
  78. @extends('layouts.app')
  79.  
  80. @section('content')
  81. <link rel="stylesheet" href="{{ elixir('css/petsbook.css') }}">
  82.  
  83.  
  84.  
  85. <div class="row col-md-9 col-lg-9 col-sm-9 pull-left ">
  86. <h1 class="hidden">Exercise </h1>
  87.  
  88. <div class="show" >
  89.  
  90. <h1>{{ $pet->name }}</h1>
  91.  
  92. </div>
  93.  
  94. <div class="row col-md-12 col-lg-12 col-sm-12" >
  95. <p class="lead">{{ $pet->description }}</p>
  96. </div>
  97.  
  98.  
  99. </div>
  100.  
  101.  
  102. @endsection
  103.  
  104. return view('pets.index', ['pets'=> $pets]);
  105. }
  106. return view('auth.login');
  107.  
  108.  
  109.  
  110. }
  111.  
  112.  
  113. /**
  114. * Show the form for creating a new resource.
  115. *
  116. * @return IlluminateHttpResponse
  117. */
  118. public function create( $family_id = null )
  119. {
  120. //
  121. $families = null;
  122. if(!$family_id){
  123. $families = Family::where('user_id', Auth::user()->id)->get();
  124. }
  125.  
  126. return view('pets.create',['family_id'=>$family_id, 'families'=>$families]);
  127. }
  128.  
  129. /**
  130. * Store a newly created resource in storage.
  131. *
  132. * @param IlluminateHttpRequest $request
  133. * @return IlluminateHttpResponse
  134. */
  135. public function store(Request $request)
  136. {
  137. //
  138.  
  139. if(Auth::check()){
  140. $pet = Pet::create([
  141. 'name' => $request->input('name'),
  142. 'description' => $request->input('description'),
  143. 'family_id' => $request->input('family_id'),
  144. 'user_id' => Auth::user()->id
  145. ]);
  146.  
  147.  
  148. if($pet){
  149. return redirect()->route('pets.show', ['pets'=> $pet->id])
  150. ->with('success' , 'You have an other pet');
  151. }
  152.  
  153. }
  154.  
  155. return back()->withInput()->with('errors', 'Error creating new pet');
  156.  
  157. }
  158.  
  159.  
  160. /**
  161. * Display the specified resource.
  162. *
  163. * @param Apppet $pet
  164. * @return IlluminateHttpResponse
  165. */
  166. public function show(Pet $pet)
  167. {
  168. //
  169.  
  170. // $pet = Pet::where('id', $pett->id )->first();
  171. $pet = Pet::find($pet->id);
  172.  
  173.  
  174. }
  175.  
  176. /**
  177. * Show the form for editing the specified resource.
  178. *
  179. * @param Apppet $pet
  180. * @return IlluminateHttpResponse
  181. */
  182. public function edit(Pet $pet)
  183. {
  184. //
  185. $pet = Pet::find($pet->id);
  186.  
  187. return view('pets.edit', ['pet'=>$pet]);
  188. }
  189.  
  190. /**
  191. * Update the specified resource in storage.
  192. *
  193. * @param IlluminateHttpRequest $request
  194. * @param Apppet $pet
  195. * @return IlluminateHttpResponse
  196. */
  197. public function update(Request $request, pet $pet)
  198. {
  199.  
  200. //save data
  201.  
  202. $petUpdate = Pet::where('id', $pet->id)
  203. ->update([
  204. 'name'=> $request->input('name'),
  205. 'description'=> $request->input('description')
  206. ]);
  207.  
  208. if($petUpdate){
  209. return redirect()->route('pets.show', ['pet'=> $pet->id])
  210. ->with('success' , 'Yey An other Pet');
  211. }
  212. //redirect
  213. return back()->withInput();
  214.  
  215.  
  216.  
  217. }
  218.  
  219. /**
  220. * Remove the specified resource from storage.
  221. *
  222. * @param Apppet $pet
  223. * @return IlluminateHttpResponse
  224. */
  225. public function destroy(Pet $pet)
  226. {
  227. //
  228.  
  229. $findpet = Pet::find( $pet->id);
  230. if($findpet->delete()){
  231.  
  232. //redirect
  233. return redirect()->route('pets.index')
  234. ->with('success' , 'The Pet is not longer here');
  235. }
  236.  
  237. return back()->withInput()->with('error' , 'we can not say bye bye Pet');
  238.  
  239.  
  240. }
  241.  
  242. public function search(Request $req)
  243. {
  244. $pets= Pet::all();
  245. return view ('search', compact ('pets'));
  246. }
  247.  
  248.  
  249. public function getSearch (Request $req)
  250. {
  251. if($req->ajax())
  252. {
  253. $find= Pet::where('name', 'LIKE','%' .$req->search. '%' )->get();
  254. return response()->json($find);
  255.  
  256. }
  257. }
  258.  
  259.  
  260. }
Add Comment
Please, Sign In to add comment