Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @extends('layouts.app')
- @section('content')
- <link rel="stylesheet" href="{{ elixir('css/petsbook.css') }}">
- <meta name="csrf-token" content="{{ csrf_token() }}">
- <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
- <div class="col-md-6 col-lg-6 col-md-offset-3 col-lg-offset-3">
- <div class="panel panel-primary ">
- <div class="col-lg-6 col-lg-offset-3">
- <div class="wrapper">
- <form id="form">
- <input class="input" type="text" name="search" id="search" class="form-control pull-left" placeholder="Search Exercise...">
- </form>
- </div>
- </div>
- <div class="panel-body">
- <h1 class="hidden">List of Exercise </h1>
- <ul class="list-group">
- @foreach($pets as $pet)
- <li class="list-group-item" id="data">
- <a id="name" href="/pets/{{ $pet->id }}" > {{ $pet->name }}</a></li>
- @endforeach
- </ul>
- </div>
- </div>
- </div>
- <h1 class="hidden">The search </h1>
- <script type ="text/javascript">
- $(document).ready(function()
- {
- $.ajaxSetup({
- headers:{
- 'X-CSRF-TOKEN' : $('meta[name="csrf-token"]').attr('content')
- }
- });
- $('#form').on('input',function(e)
- {
- e.preventDefault();
- data = $(this).serialize();
- $.post('/getSearch', data, function(search)
- {
- $('#data').html('');
- $.each(search, function (key,val){
- $('#data').append(''+
- '<li class="list-group-item" id="data"> <a id="name" href="/pets/{{ $pet->id }}" >'+val.name+'</a></li>'+
- '');
- });
- });
- });
- });
- </script>
- @endsection
- @extends('layouts.app')
- @section('content')
- <link rel="stylesheet" href="{{ elixir('css/petsbook.css') }}">
- <div class="row col-md-9 col-lg-9 col-sm-9 pull-left ">
- <h1 class="hidden">Exercise </h1>
- <div class="show" >
- <h1>{{ $pet->name }}</h1>
- </div>
- <div class="row col-md-12 col-lg-12 col-sm-12" >
- <p class="lead">{{ $pet->description }}</p>
- </div>
- </div>
- @endsection
- return view('pets.index', ['pets'=> $pets]);
- }
- return view('auth.login');
- }
- /**
- * Show the form for creating a new resource.
- *
- * @return IlluminateHttpResponse
- */
- public function create( $family_id = null )
- {
- //
- $families = null;
- if(!$family_id){
- $families = Family::where('user_id', Auth::user()->id)->get();
- }
- return view('pets.create',['family_id'=>$family_id, 'families'=>$families]);
- }
- /**
- * Store a newly created resource in storage.
- *
- * @param IlluminateHttpRequest $request
- * @return IlluminateHttpResponse
- */
- public function store(Request $request)
- {
- //
- if(Auth::check()){
- $pet = Pet::create([
- 'name' => $request->input('name'),
- 'description' => $request->input('description'),
- 'family_id' => $request->input('family_id'),
- 'user_id' => Auth::user()->id
- ]);
- if($pet){
- return redirect()->route('pets.show', ['pets'=> $pet->id])
- ->with('success' , 'You have an other pet');
- }
- }
- return back()->withInput()->with('errors', 'Error creating new pet');
- }
- /**
- * Display the specified resource.
- *
- * @param Apppet $pet
- * @return IlluminateHttpResponse
- */
- public function show(Pet $pet)
- {
- //
- // $pet = Pet::where('id', $pett->id )->first();
- $pet = Pet::find($pet->id);
- }
- /**
- * Show the form for editing the specified resource.
- *
- * @param Apppet $pet
- * @return IlluminateHttpResponse
- */
- public function edit(Pet $pet)
- {
- //
- $pet = Pet::find($pet->id);
- return view('pets.edit', ['pet'=>$pet]);
- }
- /**
- * Update the specified resource in storage.
- *
- * @param IlluminateHttpRequest $request
- * @param Apppet $pet
- * @return IlluminateHttpResponse
- */
- public function update(Request $request, pet $pet)
- {
- //save data
- $petUpdate = Pet::where('id', $pet->id)
- ->update([
- 'name'=> $request->input('name'),
- 'description'=> $request->input('description')
- ]);
- if($petUpdate){
- return redirect()->route('pets.show', ['pet'=> $pet->id])
- ->with('success' , 'Yey An other Pet');
- }
- //redirect
- return back()->withInput();
- }
- /**
- * Remove the specified resource from storage.
- *
- * @param Apppet $pet
- * @return IlluminateHttpResponse
- */
- public function destroy(Pet $pet)
- {
- //
- $findpet = Pet::find( $pet->id);
- if($findpet->delete()){
- //redirect
- return redirect()->route('pets.index')
- ->with('success' , 'The Pet is not longer here');
- }
- return back()->withInput()->with('error' , 'we can not say bye bye Pet');
- }
- public function search(Request $req)
- {
- $pets= Pet::all();
- return view ('search', compact ('pets'));
- }
- public function getSearch (Request $req)
- {
- if($req->ajax())
- {
- $find= Pet::where('name', 'LIKE','%' .$req->search. '%' )->get();
- return response()->json($find);
- }
- }
- }
Add Comment
Please, Sign In to add comment