2016-10-01 103 views
2

我正在做我的項目,但被困在這裏。我想打印學位和經驗的價值。我怎樣才能做到這一點?我的控制器文件如下所示:如何在laravel中顯示if語句中的值

public function industryPost (Request $request) { 
     $industry = $request->input('industry'); 

     if (empty($industry)) { 
      return 'Industry can not be null'; 
     } else { 

      $experiences = AreaOfExperience::where('industry_id', $industry)->where('is_active', 1)->where('is_deleted', 0)->get(); 
      $degrees = Degree::where('industry_id', $industry)->where('is_active', 1)->where('is_deleted', 0)->get(); 


      if (!empty($degrees)) { 
       $string2 = ''; 
       foreach ($degrees as $degree) { 
        $string2 .= ' 
         <div class="col-md-4"> 
          <div class="be-checkbox"> 
           <label class="check-box"> 
            <input id="degree" type="checkbox" name="degrees[]" value="'.$degree->id.'" class="checkbox-input"> 
            <span class="check-box-sign"></span> 
           </label> 
           <span class="large-popup-text"> '.$degree->name.' </span> 
          </div> 
         </div> 
        '; 
       } 
       return response($string2); 
      } 
      if (count($degrees) == 0) { 
       return 101; 
      } 

      if (!empty($experiences)) { 
       $string = ''; 
       foreach ($experiences as $experience) { 
        $string .= ' 
         <div class="col-md-4"> 
          <div class="be-checkbox"> 
           <label class="check-box"> 
            <input id="experience" type="checkbox" name="area_of_experiences[]" value="'.$experience->id.'" class="checkbox-input"> 
            <span class="check-box-sign"></span> 
           </label> 
           <span class="large-popup-text"> '.$experience->name.' </span> 
          </div> 
         </div> 
        '; 
       } 
       return response($string); 
      } 
      if (count($experiences) == 0) { 
       return 100; 
      } 


     } 
    } 

我想打印度數和經驗值。但在我的查詢中,它打印了度數的值。我怎麼能做到這一點?請幫忙!

+0

@Komal我怎麼能做到這一點?你能幫忙嗎?請給我例 –

+0

通過兩個陣列來查看並生成你的UI – Komal

+0

你試過下面的代碼 – Komal

回答

0

答案應該是這樣的

public function industryPost (Request $request) { 
     $industry = $request->input('industry'); 

     if (empty($industry)) { 
      return 'Industry can not be null'; 
     } else { 

      $experiences = AreaOfExperience::where('industry_id', $industry)->where('is_active', 1)->where('is_deleted', 0)->get(); 
      $degrees = Degree::where('industry_id', $industry)->where('is_active', 1)->where('is_deleted', 0)->get(); 

      $string2 = ''; 
      if (!empty($degrees)) { 

       foreach ($degrees as $degree) { 
        $string2 .= ' 
         <div class="col-md-4"> 
          <div class="be-checkbox"> 
           <label class="check-box"> 
            <input id="degree" type="checkbox" name="degrees[]" value="'.$degree->id.'" class="checkbox-input"> 
            <span class="check-box-sign"></span> 
           </label> 
           <span class="large-popup-text"> '.$degree->name.' </span> 
          </div> 
         </div> 
        '; 
       } 

      } 
      if (count($degrees) == 0) { 
       return 101; 
      } 
      $string = ''; 

      if (!empty($experiences)) { 

       foreach ($experiences as $experience) { 
        $string .= ' 
         <div class="col-md-4"> 
          <div class="be-checkbox"> 
           <label class="check-box"> 
            <input id="experience" type="checkbox" name="area_of_experiences[]" value="'.$experience->id.'" class="checkbox-input"> 
            <span class="check-box-sign"></span> 
           </label> 
           <span class="large-popup-text"> '.$experience->name.' </span> 
          </div> 
         </div> 
        '; 
       } 
      } 
      $data = array(
       'string2'=>$string2, 
       'string' =>$string 
      ); 

      return response($data); 

      if (count($experiences) == 0) { 
       return 100; 
      } 


     } 
    } 
+0

您的問題解決了嗎?或不是 – Komal

+0

是的問題解決了 –

0

嘗試這樣

$experiences = AreaOfExperience::where('industry_id', $industry)->where('is_active', 1)->where('is_deleted', 0)->get(); 
$degrees = Degree::where('industry_id', $industry)->where('is_active', 1)->where('is_deleted', 0)->get(); 

return view('view_name')->with('experiences', $experiences)->with('degrees', $degrees); 

您的看法

@foreach($degrees as $degree) 
    <div class="col-md-4"> 
     <div class="be-checkbox"> 
      <label class="check-box"> 
       <input id="degree" type="checkbox" name="degrees[]" value="{{$degree->id}}" class="checkbox-input"> 
       <span class="check-box-sign"></span> 
      </label> 
      <span class="large-popup-text">{{$degree->name}}</span> 
     </div> 
    </div> 
@endforeach