无法从另一个表连接值(使用laravel 5.5)

时间:2018-04-26 12:07:58

标签: php laravel foreign-keys

我正面临着存储ID并从两个不同的表中显示其值的问题我有1个表business_master而其他表是page_master我已将business_name列与page_url列结合使用,如果我首先添加我的业务和页面,则可在page_master表中使用时间成功结合这两个值,因为一个企业可以有很多页面,如果我只添加第二次页面,我无法通过page_url列看到business_url:

我的页面模型:

        class PageList extends Model
  {
 protected $table = 'page_master';


  protected $fillable = ['business_id', 'page_url', 'page_name'];


 public function business()
  {
   return $this->hasOne('App\Business','business_id');
  }

 }

在我看来:

<td>{{optional($value->business)->business_url}}.spikesales.io/{{$value->page_url}}</td>

如果我添加business_url和page_url

,这是我的第一次
   hussain.spikesales.io/house

然后,如果我只添加页面,那么输出就是那样的

   .spikesales.io/hello

我的控制器看起来像:

 public function pageListHere()
{
    $list = PageList::wherehas('business')->get();
    return view('page-list',compact('list'));
}

你的helo将受到高度赞赏!

  class PageList extends Model
  {
protected $table = 'page_master';


protected $fillable = ['business_id', 'page_url', 'page_name'];



public function business()
{
    return $this->hasOne('App\Business','business_id');
}

  }

和我的全部观点:

                                           @foreach($list as $value)
                                <tr>
                                    <input type="hidden" id="rwid" value="{{$value->id}}"/>
                                    <td>
                                        <input id="{{$value->id}}" class="checkbox-custom" name="{{$value->id}}" type="checkbox"
                                               value="{{$value->id}}">
                                        <label for="{{$value->id}}" class="checkbox-custom-label"></label>
                                    </td>
                                    <td><p data-placement="top" data-toggle="tooltip" title=""
                                           data-original-title="Tolltip">{{$value->page_name}}</p></td>
                                    <td>{{optional($value->business)->business_url}}.spikesales.io/{{$value->page_url}}</td>

                                    <td> {{$value->created_at}}</td>
                                    <td>

                                        <p>{{$value->coupon()->where('is_ordered','N')->count()}}/{{optional($value->particulars)->coupon_count}}</p>
                                    <div class="progress-bar">
                                        <span class="yello-proges" style="width:{{$value->coupon()->where('is_ordered','N')->count()}}%"></span>
                                    </div>
                                </td>
                                <td>
                                    <button type="button" class="ply-btn playpause">
                                        @if($value->is_live === 1)
                                            <span class="pause" style="display: none;"><i class="fa fa-pause"></i></span>
                                            <span class="play"><i class="fa fa-play"></i></span>
                                            <span class="spinner" style="display: none;"><i class="fa fa-spinner fa-spin"></i></span>
                                        @endif
                                        @if($value->is_live === 0)
                                            <span class="pause"><i class="fa fa-pause"></i></span>
                                            <span class="play" style="display: none;"><i class="fa fa-play"></i></span>
                                            <span class="spinner" style="display: none;"><i class="fa fa-spinner fa-spin"></i></span>
                                        @endif

                                            @if($value->is_live === Null)
                                                <span class="pause"><i class="fa fa-pause"></i></span>
                                                <span class="play" style="display: none;"><i class="fa fa-play"></i></span>
                                                <span class="spinner" style="display: none;"><i class="fa fa-spinner fa-spin"></i></span>
                                            @endif

                                    </button>
                                    {{--<a data-page-id="{{$value->id}}" class="ply-btn" id="playpause">--}}
                                        {{--<span class="pause"><i class="fa fa-pause"></i></span>--}}
                                        {{--<span class="play" style="display: none;"><i class="fa fa-play"></i></span>--}}
                                        {{--<span class="spinner" style="display: none;"><i class="fa fa-spinner fa-spin"></i></span>--}}
                                    {{--</a>--}}
                                    <div class="btn-group" data-placement="top" data-toggle="tooltip" title="" data-original-title="Action">
                                        <button type="button" class="dropdown-toggle actinbtn" data-toggle="dropdown" aria-expanded="false"><i class="fa fa-cog"></i></button>
                                        <ul class="dropdown-menu">
                                            <li><a href="{{url('edit-List/'.$value->id)}}"><i class="fa fa-pencil-square-o"></i> Edit Page</a></li>
                                            <li><a href="{{url('template/'.($value->particulars1)->id)}}" class="viewpage" target="_blank"><i class="fa fa-eye"></i> View Page</a></li>
                                            <li><a class="dangrclr"><i class="fa fa-trash-o"></i>Delete</a></li>
                                            {{--<li><a href="{{url('delete-list/'.$value->id)}}" class="dangrclr"><i class="fa fa-trash-o"></i>Delete</a></li>--}}
                                        </ul>
                                    </div>
                                </td>
                            </tr>
                            @endforeach     

0 个答案:

没有答案