2016-09-29 2 views
-2

데이터베이스를 통해 체크 박스를 통해 값을 가져 오려는 프로젝트가 있습니다. 그러나 나는 이것을 할 수 없다. 내 컨트롤러 코드가laravel의 체크 박스를 통해 데이터를 검색 할 수 없습니다.

public function browseProfessionals() { 
     $userRoles = UserRole::whereIn('role_id', [2,3])->get(); 
     $users = array(); 
     $showUsers = array(); 

     foreach ($userRoles as $userRole) { 
      $users[] = User::find($userRole->user_id); 
     } 

     $valid_providers = array(); 
     $all_providers = array(); 
     $user_role_all_providers = UserRole::where('role_id', 2)->get(); 

     foreach ($user_role_all_providers as $user_role_all_provider) { 
      $all_providers[] = User::where('id', $user_role_all_provider->user_id)->first(); 
     } 

     foreach ($all_providers as $all_provider) { 
      $user = User::where('id', $all_provider->id)->first(); 
      $user_detail = UserDetail::where('user_id', $all_provider->id)->first(); 
      $user_meeting = UserMeeting::where('user_id', $all_provider->id)->first(); 
      $user_time = UserTime::where('user_id', $all_provider->id)->first(); 

      if (!empty($user_detail->avatar) && !empty($user_meeting->meeting_id) && !empty($user_time->hour_rate) && $user->is_active == 1 && $user->is_deleted == 0) { 
       $valid_providers[] = $all_provider; 
      } 
     } 

     $data = [ 
      'valid_providers' => $showUsers, 
      'industries' => Industry::where('is_active', 1)->where('is_deleted', 0)->get(), 
      'degrees' => UserDegree::where('degree_id', $user->degree_id)->get(), 
     ]; 
     return view('frontends.browse-professionals', $data); 
    } 

내 블레이드 템플릿은

@extends ('frontends.layouts.app') 
@section ('main') 
    <div id="content-block" class="margin-top-140"> 
     <div class="container-fluid block custom-container"> 
      <h3 class="block-title">Browse Professionals</h3> 
      <div class="block-subtitle"><span>Connect</span> <span>Learn</span> <span>Inspire</span> <span>Thrive</span> </div> 
      <div class="row"> 
       {{--<form action="" method="post">--}} 
        <div class="col-md-2 left-feild"> 
         <div class="margin-bottom-30"> 
          <h3>Search Filters</h3> 
         </div> 
         @if(Auth::check() && Auth::user()->user_role->role_id == 1000000) 
          <div class="be-vidget"> 
           <h3 class="letf-menu-article"> Looking To </h3> 
           <div class="creative_filds_block"> 
            <div class="radio"> 
             <label><input type="radio" name="lookingTo" onclick="lookingTo(2)"> Seek Advice</label> 
            </div> 
            <div class="radio"> 
             <label><input type="radio" name="lookingTo" onclick="lookingTo(3)"> Share Advice</label> 
            </div> 
           </div> 
          </div> 
          <script> 
           function lookingTo(e) { 
            $.ajax({ 
             type: 'POST', 
             url: '{{ URL::to('looking/to') }}/' + e, 
             success: function (result) { 
              $('#browse_professionals').html(result); 
             } 
            }); 
           } 
          </script> 
         @endif 
         <div class="be-vidget"> 
          <h3 class="letf-menu-article">Professionals</h3> 
          <div class="-creative_filds_block"> 
           <div class="fp-panel-wrap"> 
            <a class="toggle-btn active" onclick="open_industry()" href="#" data-target="#ul_industry" id="a_industry">Industry</a> 
            <ul id="ul_industry" class="fp-panel open" style="overflow:scroll; height:200px;"> 
             @if(!empty($industries)) 
              @foreach($industries as $industry) 
               <li value="{{ $industry->id }}"><a href="javascript:void(0)" onclick="industry_search({{ $industry->id }})">{{ (!empty($industry['name'])) ? $industry['name'] : '' }}</a> </li> 
              @endforeach 
             @endif 
            </ul> 
            <script> 
             function industry_search(e) { 
              $.ajax({ 
               type: 'POST', 
               url: '{{ URL::to('professionals/industry') }}/' + e, 
               success: function (result) { 
                $('#education_experience').html(result); 
                $('#a_industry').attr('class', 'toggle-btn'); 
                $('#ul_industry').css('display', 'none'); 
                $('#education_experience').css('display', 'block'); 
                $('#eduLevel').css('display', 'block'); 
                $('#areaExperience').css('display', 'block'); 

               } 
              }); 
             } 
             function open_industry() { 
              $('#education_experience').css('display', 'block'); // display none hobe na. collapse hoye jabe 
//          $('#a_industry').attr('class', 'toggle-btn active'); 
//          $('#ul_industry').css('display', 'block'); 
              $('#education_experience').css('display', 'block'); 
              $('#eduLevel').css('display', 'none'); 
              $('#areaExperience').css('display', 'none'); 
             } 
            </script> 
            <div id="education_experience" style=""> 
             <a id="a_education" class="toggle-btn" href="#" data-target="#eduLevel">Education Level</a> 
             <ul id="eduLevel" class="no-link fp-panel" style="overflow:scroll; height:200px;"> 


              @if(!empty($degrees)) 
               @foreach($degrees as $degree) 
                <li value="{{ $degree->id }}">{{ (!empty($degree['name'])) ? $degree['name'] : '' }}</a> </li> 
               @endforeach 
              @endif 

             </ul> 
             <a id="a_experience" class="toggle-btn" href="#" data-target="#areaExperience">Areas of Experience</a> 
             <ul id="areaExperience" class="no-link fp-panel" style="overflow:scroll; height:200px;"> 

             </ul> 
            </div> 
           </div> 
          </div> 
         </div> 
         <div class="be-vidget"> 
          <h3 class="letf-menu-article">Meeting Preferences</h3> 
          <label>Price</label> 
          <br> <br> 
          <input type="hidden" id="price_ranger" class="range-slider" value="23"/> 


          <label style="margin-top: 30px;">Type</label> 
          <div class="form-group"> 
           <select class="form-input" id="meeting_type"> 
            <option value="3">All</option> 
            <option value="1">Phone Meeting</option> 
            <option value="2">Web Meeting</option> 
           </select> 
          </div> 
         </div> 

         <button id="search_professionals" type="button" class="btn color-2 size-2 btn-block hover-1">Apply Filter</button> 
         @if(Session::has('remove_filter')) 
          <button type="button" class="btn btn-danger size-2 btn-block hover-1">Remove Filter</button> 
         @endif 

         <script> 
          var industry = ''; 
          $('#ul_industry li').click(function() { 
           industry = $(this).attr('value'); 
          }); 

          $("#search_professionals").click(function() { 
           var degrees = new Array(); 
           $('input[name="degrees_checkbox"]:checked').each(function() { 
            degrees.push(this.value); 
           }); 

           var experiences = new Array(); 
           $('input[name="experiences_checkbox"]:checked').each(function() { 
            experiences.push(this.value); 
           }); 

           var price_ranger = $("#price_ranger").val(); 
           var price_ranger_array = price_ranger.split(","); 
           var start_price = price_ranger_array[0]; 
           var end_price = price_ranger_array[1]; 

           var meeting_type = $("#meeting_type").val(); 

           $.ajax({ 
            'type' : 'post', 
            'url' : '{{ URL::to('search/professionals') }}', 
            'data' : { 
             'industry' : industry, 
             'educationLevels' : degrees, 
             'areasOfExperiences' : experiences, 
             'start_price' : start_price, 
             'end_price' : end_price, 
             'meeting_type' : meeting_type 
            }, 
            'success' : function (result) { 
             console.log(result); 
             $('#browse_professionals').html(result); 
            } 
           }); 
          }); 
         </script> 
        </div> 
       {{--</form>--}} 

       <div class="col-md-10"> 
        <div id="browse_professionals" class="row _post-container_"> 
         @if (!empty($valid_providers)) 
          @foreach ($valid_providers as $provider) 

           <div class="category-1 custom-column-5"> 
            <div class="be-post"> 
             <figure class="ratio-4-3 be-img-block-alt"> 
              <div class="ratio-inner" style="background-image: url('{{ !empty($provider->user_detail->avatar) ? URL::to($provider->user_detail->avatar) : '' }}')"> 
               <img src="{{ !empty($provider->user_detail->avatar) ? URL::to($provider->user_detail->avatar) : '' }}" alt="{{ !empty($provider->username) ? URL::to($provider->username) : '' }}"> 
              </div> 
             </figure> 
             <div class="be-post-title">{{ (!empty($provider->user_share->share)) ? str_limit($provider->user_share->share, 90) : '' }}</div> 
             <div class="author-post"> 
              <span><a href="{{ !empty($provider->username) ? URL::to($provider->username) : '' }}">{{ !empty($provider->user_detail->first_name) ? $provider->user_detail->first_name : '' }} {{ !empty($provider->user_detail->last_name) ? $provider->user_detail->last_name : '' }}</a></span> 
             </div> 
             <span>{{ (!empty($provider->user_detail->credentials)) ? str_limit($provider->user_detail->credentials, 25) : '' }}</span> 
             <div data-value="4" class="static-rating"></div> 
             <div class="info-block clearfix"> 
              <a class="btn color-1 size-2 hover-1 pull-right" href="{{ !empty($provider->username) ? URL::to($provider->username) : '' }}">Contact</a> 
              <h3 class="rate"> ${{ (!empty($provider->user_time->hour_rate)) ? $provider->user_time->hour_rate : '' }} /hr</h3> 
             </div> 
            </div> 
           </div> 
          @endforeach 
         @endif 
        </div> 
       </div> 
      </div> 
     </div> 
    </div> 
@endsection 

내 Searchcontroller는

public function searchProfessionals (Request $request) 
    { 
     $industry = $request->input('industry'); 
     $educationLevels = $request->input('educationLevels'); 
     $areasOfExperiences = $request->input('areasOfExperiences'); 
     $startPrice = $request->input('start_price'); 
     $endPrice = $request->input('end_price'); 
     $meetingType = $request->input('meeting_type'); 

     if ($meetingType == 1) { 
      $type = [1, 1]; 
     } elseif ($meetingType == 2) { 
      $type = [2, 2]; 
     } elseif ($meetingType === 3) { 
      $type = [1, 2]; 
     } else { 
      $type = [1, 2]; 
     } 

     $userMeetings = array(); 
     $userRoles = array(); 
     $users = array(); 
     $showUsers = array(); 
     $userHourRates = array(); 
//  return response($industry); 

     $userIndus = UserIndustry::where('industry_id', $industry)->get(); 

     if (!empty($userIndus)) { 
      foreach ($userIndus as $userInd) { 
       $userHourRates = UserTime::where('user_id', $userInd->user_id)->whereBetween('hour_rate', [$startPrice, $endPrice])->first(); 
      } 

//  $userHourRates = UserTime::whereBetween('hour_rate', [$startPrice, $endPrice])->get(); 
      if (!empty($userHourRates)) { 
       foreach ($userHourRates as $userHourRate) { 
        $userMeetings[] = UserMeeting::whereIn('meeting_id', $type)->where('user_id', $userHourRate->user_id)->first(); 
       } 
       if (!empty($userMeetings)) { 

        foreach ($userMeetings as $userMeeting) { 
         $userRoles[] = UserRole::where('user_id', $userMeeting['user_id'])->where('role_id', '!=', 1)->first(); 
        } 
        if (!empty($userRoles)) { 
         foreach ($userRoles as $userRole) { 
          $users[] = User::find($userRole['user_id']); 
         } 
         if (!empty($users)) { 
          foreach ($users as $u) { 
           $user = User::find($u['id']); 
           $userDetail = UserDetail::where('user_id', $u['id'])->first(); 
           $userShare = UserShare::where('user_id', $u['id'])->first(); 
           $userMeeting = UserMeeting::where('user_id', $u['id'])->first(); 
           $userWeek = UserWeek::where('user_id', $u['id'])->first(); 
           $userTime = UserTime::where('user_id', $u['id'])->first(); 
           if (
            $user['is_active'] == 1 && $user['is_deleted'] == 0 && !empty($userDetail['avatar']) && !empty($userDetail['first_name']) && 
            !empty($userDetail['last_name']) && !empty($userDetail['credentials']) && !empty($userShare['share']) && 
            !empty($userShare['seek']) && !empty($userMeeting['meeting_id']) && !empty($userWeek['week_id']) && 
            !empty($userTime['start_time']) && !empty($userTime['end_time']) && !empty($userTime['hour_rate']) 
           ) { 
            $showUsers[] = $u; 
           } 
          } 
          if (!empty($showUsers)) { 
           $string = ''; 
           foreach ($showUsers as $showUser) { 
            $userShow = User::find($showUser->id); 
            $userDetailShow = UserDetail::where('user_id', $showUser->id)->first(); 
            $userShareShow = UserShare::where('user_id', $showUser->id)->first(); 
            $userRatingShow = Review::where('provider_id', $showUser->id)->orWhere('seeker_id', $showUser->id)->avg('rating'); 
            $userTimeShow = UserTime::where('user_id', $showUser->id)->first(); 
            $string .= ' 
           <div class="category-1 custom-column-5"> 
            <div class="be-post"> 
             <figure class="ratio-4-3 be-img-block-alt"> 
              <div class="ratio-inner" style="background-image: url(' . url($userDetailShow->avatar) . ')"> 
               <img src="' . url($userDetailShow->avatar) . '" alt="omg"> 
              </div> 
             </figure> 
             <div class="be-post-title">' . str_limit($userShareShow->share, 90) . '</div> 
             <div class="author-post"> 
              <span> 
               <a href="' . url($userShow->username) . '">' . 
             $userDetailShow->first_name . ' ' . $userDetailShow->last_name . ' 
               </a> 
              </span> 
             </div> 
             <span>' . $userDetailShow->credentials . '</span> 
            </div> 
            <div data-value="' . $userRatingShow . '" class="static-rating"></div> 
             <div class="info-block clearfix"> 
              <a class="btn color-1 size-2 hover-1 pull-right" href="' . url($userShow->username) . '">Contact</a> 
              <h3 class="rate">$' . $userTimeShow->hour_rate . '/hr</h3> 
             </div> 
            </div> 
           </div> 
          '; 
           } 
           return response($string); 
          } else { 
           return 'data not found.'; 
          } 
         } else { 
          return 'data not found.'; 
         } 
        } else { 
         return 'data not found.'; 
        } 

       } else { 
        return 'data not found.'; 
       } 
      } else { 
       return 'data not found.'; 
      } 
     } else { 
      return 'data not found.'; 
     } 
    } 

내가 체크 박스를 통해 값을 표시 할 수있는 방법 도와주세요입니다. 이 문제를 해결하도록 도와주세요.

+0

어떤 체크 박스가 있습니까? ... 나는 어디서나 HTML을 보지 못합니다. 특정 문제와 관련된 코드 만 게시하십시오. 우리는 모든 관련없는 요소와 스크립트를 볼 필요가 없습니다. 또한 [ask]를 검토하는 데 몇 분이 걸립니다. 귀하의 특정 문제 및 질문은 분명하지 않습니다. * '할 수 없어.'* 아주 많이 말하지 않습니다 – charlietfl

답변

0

JavaScript를 F12로 디버그하여 오류가 있는지 확인하십시오. Javascript에 문제가 없으면 네트워크 탭의 ajax 요청 리턴 데이터를 점검 할 수 있습니다.

+0

자바 스크립트 문제입니다. 데이터는 데이터베이스에 표시된대로 표시 할 수 없으며 해당 데이터는 자바 스크립트가 호출 될 때 볼 수 없습니다. ThaTal –

+0

죄송합니다. 아약스 요청이 너무 많습니다. 모든 아약스 요청을 하나씩 시도해 보시기 바랍니다. 그러면 도움이 될 것입니다. 모든 단계에서 테스트하십시오. – ThaTal

관련 문제