Advertisement
Guest User

Untitled

a guest
Jan 7th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.35 KB | None | 0 0
  1. public function index()
  2. {
  3. $clients = Client::where('business_id', '=', Auth::user()->business_id)->orderBy('updated_at', 'DESC')->get();
  4.  
  5. return Response::json([
  6. 'clients' => $this->transformClientCollection($clients)
  7. ], 200);
  8. }
  9.  
  10. public function transformClientCollection($clients)
  11. {
  12. return array_map([$this, 'transformClient'], $clients->toArray());
  13. }
  14.  
  15. public function transformClient($clients)
  16. {
  17.  
  18. return [
  19. 'clientid' => $clients['id'],
  20. 'first_name' => $clients['first_name'],
  21. 'last_name' => $clients['last_name'],
  22. 'address_1' => $clients['address_1'],
  23. 'address_2' => $clients['address_2'],
  24. 'city' => $clients['city'],
  25. 'state' => $clients['state'],
  26. 'postal_code' => $clients['postal_code'],
  27. 'phone_number_1' => $clients['phone_number_1'],
  28. 'phone_number_2' => $clients['phone_number_2'],
  29. 'email' => $clients['email']
  30. ];
  31. }
  32.  
  33. <div ng-app="instantsearch">
  34. <div ng-controller="instantSearchCtrl">
  35.  
  36. <div class="row">
  37. <div class="col-sm-12">
  38. <input type="text" class="form-control search" ng-model="searchString" placeholder="Enter your search terms" />
  39. </div>
  40. </div>
  41.  
  42. <div class="row data-ctrl" ng-repeat="i in items | filter:searchString | limitTo:20 ">
  43. <div class="col-sm-12">
  44. @{{ i.first_name }} @{{ i.last_name }} @{{ i.address_1 }} @{{ i.address_2 }} @{{ i.city }} @{{ i.state }} @{{ i.phone_number_1 }} @{{ i.phone_number_2 }} @{{ i.email }}
  45. </div>
  46. </div>
  47.  
  48. </div>
  49. </div>
  50.  
  51. var app = angular.module('instantsearch',[]);
  52.  
  53. app.controller('instantSearchCtrl',function($scope,$http,$location){
  54.  
  55. var urlapiclients = $location.protocol() + "://" + $location.host() + "/api/clients" ;
  56.  
  57. $http.get(urlapiclients).success(function(data, status, headers, config) {
  58. $scope.items = data.clients;
  59.  
  60. }).error(function(data, status, headers, config) {
  61. console.log("No data found..");
  62. });
  63. });
  64.  
  65.  
  66. app.filter('searchFor', function(){
  67. return function(arr, searchString){
  68. if(!searchString){
  69. return arr;
  70. }
  71. var result = [];
  72. searchString = searchString.toLowerCase();
  73. angular.forEach(arr, function(item){
  74. if(item.first_name.toLowerCase().indexOf(searchString) !== -1){
  75. result.push(item);
  76. }
  77. });
  78. return result;
  79. };
  80. });
  81.  
  82. "clients":[
  83. {
  84. "clientid":4981,
  85. "first_name":"Sid",
  86. "last_name":"Hodkiewicz",
  87. "address_1":"6659 Hackett Ways",
  88. "address_2":"",
  89. "city":"New Estherville",
  90. "state":"Tennessee",
  91. "postal_code":"27281-0870",
  92. "phone_number_1":"00700300842",
  93. "phone_number_2":"",
  94. "email":"hNitzsche@Stokes.biz"
  95. },
  96. {
  97. "clientid":4982,
  98. "first_name":"Braulio",
  99. "last_name":"Bechtelar",
  100. "address_1":"7558 Anne Land Suite 876",
  101. "address_2":"",
  102. "city":"Rauview",
  103. "state":"Alabama",
  104. "postal_code":"01837-9601",
  105. "phone_number_1":"1-017-001-8215",
  106. "phone_number_2":"",
  107. "email":"nBaumbach@gmail.com"
  108. },
  109. {
  110. "clientid":4983,
  111. "first_name":"Loma",
  112. "last_name":"Dibbert",
  113. "address_1":"805 Jones Fields Suite 411",
  114. "address_2":"",
  115. "city":"Lake Billychester",
  116. "state":"New Jersey",
  117. "postal_code":"69315-4595",
  118. "phone_number_1":"(691)511-6275x891",
  119. "phone_number_2":"",
  120. "email":"dHegmann@Bashirian.net"
  121. },
  122. {
  123. "clientid":4984,
  124. "first_name":"Verla",
  125. "last_name":"Schulist",
  126. "address_1":"89529 Bode Village Suite 344",
  127. "address_2":"",
  128. "city":"West Jessy",
  129. "state":"Virginia",
  130. "postal_code":"69116",
  131. "phone_number_1":"(248)211-3643",
  132. "phone_number_2":"",
  133. "email":"Friesen.Ruthie@Hand.biz"
  134. },
  135. {
  136. "clientid":4985,
  137. "first_name":"Jimmie",
  138. "last_name":"Fadel",
  139. "address_1":"4355 Marquardt Heights",
  140. "address_2":"",
  141. "city":"South Conrad",
  142. "state":"District of Columbia",
  143. "postal_code":"55751",
  144. "phone_number_1":"(414)901-2495",
  145. "phone_number_2":"",
  146. "email":"Koepp.Wayne@yahoo.com"
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement