2016-07-23 1 views
0

나는 지금 병원 & 의사 정보라는 프로젝트에서 작업하고 있습니다. 여기에는 방글라데시에서 다른 부서가 있습니다. & 각 부서마다 소유권에 따라 특정 유형의 병원이있는 구역이 있습니다. 그러나 그것으로부터 다른 병원의 가치를 얻을 때 나는 약간의 오류를 보여줍니다. 내보기 파일이Laravel 경로 작동하지 않는 오류가 아닌 개체의 속성을 얻으려고합니다

<?php $active="hospital"; ?> 
@extends('layouts.dashboard') 
@section('content') 

    <section id="blog" class="container"> 
     <div class="center"> 
      <h2>Hospital Information</h2> 
      <h3 class="lead">The government approved a renowned hospital and improved quality of service address , doctor , patient viewing time, bed , pathological tests in various subjects including costs and find the information here .<br> The bed and cabin bookings online , pathological tests , the doctor can be a serial for the meeting from the app .</h3> 
     </div> 

     <div class="blog"> 
      <div class="row"> 
       <div class="col-md-12"> 
        <div class="blog-item"> 
         <div class="row"> 

          <div class="col-xs-12 col-sm-4 blog-content"> 

           <a href="#"><img class="img-responsive img-blog" src="images/2.jpg" width="100%" alt="" /></a> 
          </div> 
          @foreach($division->districts as $district) 
           @foreach($district->categories as $category) 
            @foreach($category->$hospitals as $hospital) 
            <div class="col-xs-12 col-sm-6 blog-content"> 
             <h2>{{ $hospital->name }}</h2> 
            </div> 
            @endforeach 
           @endforeach 
          @endforeach 


        <ul class="pagination pagination-lg"> 
         <li><a href="#"><i class="fa fa-long-arrow-left"></i>Previous Page</a></li> 
         <li class="active"><a href="#">1</a></li> 
         <li><a href="#">2</a></li> 
         <li><a href="#">3</a></li> 
         <li><a href="#">Next Page<i class="fa fa-long-arrow-right"></i></a></li> 
        </ul><!--/.pagination--> 
       </div><!--/.col-md-8--> 

      </div><!--/.row--> 
     </div> 
    </section><!--/#blog--> 
@stop 

& MY 모델

public function hospital($id) 
{ 

    $divisions = Division::all(); 
    $division=Division::find($id); 

    $district=District::find($id); 

    $categories=Category::all(); 

    // $districts=District::where('division_id', '=', $divisions->id)->get(); 

    // if (!$district) 
    // { 
    //  throw new NotFoundHttpException; 
    // } 
    return view('users.hospital') 
       ->with('divisions', $divisions) 
       ->with('division', $division) 
       ->with('district', $district) 
       ->with('categories',$categories); 
} 


public function hospital_info($id) 
{ 
    $divisions = Division::all(); 
    $division=Division::find($id); 

    $district=District::find($id); 

    $categories=Category::all(); 
    $hospitals=Hospital::find($id); 

    // $districts=District::where('division_id', '=', $divisions->id)->get(); 

    // if (!$district) 
    // { 
    //  throw new NotFoundHttpException; 
    // } 
    return view('users.hospital_info') 
       ->with('divisions', $divisions) 
       ->with('division', $division) 
       ->with('district', $district) 
       ->with('categories',$categories) 
       ->with('hospitals',$hospitals); 
} 

입니다 내 경로 파일

Route::get('/', array('as' =>'home' ,'uses' => '[email protected]')); 

Route::get('/about_us', array('as' =>'about_us' ,'uses' => '[email protected]_us')); 

Route::get('/district/{id}', array('as' =>'district' ,'uses' => '[email protected]')); 

Route::get('/district/hospital/{id}', array('as' =>'hospital' ,'uses' => '[email protected]')); 

Route::get('/district/hospital/hospital_info/{id}', array('as' =>'hospital_info' ,'uses' => '[email protected]_info')); 

내 컨트롤러가되어 Hospital.php

<?php 

namespace App; 

use Illuminate\Database\Eloquent\Model; 

class Hospital extends Model 
{ 

    protected $fillable = [ 
     'name', 
     'division_id', 
     'district_id', 
     'category_id', 
    ]; 

    public function district() 
    { 

     return $this->belongsto('App\District'); 
    } 
} 

지입니다

<?php 

namespace App; 

use Illuminate\Database\Eloquent\Model; 

class District extends Model 
{ 
    protected $fillable=[ 
     'name', 
     'division_id', 
    ]; 



    public function division() 
    { 
     return $this->belongsTo('App\Division'); 
    } 

    public function category() 
    { 
     return $this->hasmany('App\Categories'); 
    } 
    public function dcategory() 
    { 
     return $this->hasmany('App\Dcategories'); 
    } 

    public function hospital() 
    { 
     return $this->hasmany('App\Hospital'); 
    } 
} 

trict.php 오류가 enter image description here

이 제발 도와주세요입니다. 미리 감사드립니다.

답변

0

보기 파일에 이렇게 들리지 않아야합니까?

@foreach($division->$districts as $district)

@foreach($district->$categories as $category)

+0

그러면 내 뷰 파일을 어떻게 작성해야합니까? 그리고 특정 행의 ID를 찾지 못했습니다. 도움을 청하십시오. –

0

이 행 :

@foreach($dcategory->$hospitals as $hospital) 

은 잘못된 것입니다. 변수 $ dcategory 존재하지 않는 병원은 다음과 같이 호출해야합니다 : 항목이 연결되어있는 경우 어쩌면 dcategory에 관련된 병원이 없기 때문에

@foreach($category->hospitals as $hospital) 

은 또한 당신이 당신의 DB를 확인해야합니다.

+0

문서의 관계도 확인하십시오 : https://laravel.com/docs/5.1/eloquent-relationships#defining-relationships. 컨트롤러에서 모든 병을 전달할 필요는 없습니다. 연관된 모델 엔티티를 호출하려면 with()를 사용하고 쿼리에서 가져온 변수를 전달해야합니다. –

+0

시도했지만 결과를 얻지 못했습니다. 이드는 찾지 못했습니다. 제발 도와주세요 –

+0

이드는 병원 ID 또는 부서 ID입니까? 코드 재정렬하십시오. 이드를 사용하여 병원과 병원을 가야합니다. –

관련 문제