繁体   English   中英

如何在laravel的if语句中显示值

[英]How to show value in if statement in laravel

我正在做我的项目,但陷入其中。 我想同时打印学位和经验的价值。 我怎样才能做到这一点? 我的控制器文件如下所示:

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;
            }


        }
    }

我想同时打印学位和经验的价值。 但是在我的查询中,它显示度的值。 我怎样才能做到这一点? 请帮忙!

这样尝试

$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   

答案应该是这样的

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;
            }


        }
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM