Сейчас я работаю над проектом « Госпиталь и доктор информации» . Здесь у меня есть разные подразделения в Бангладеш, и в каждом подразделении есть районы, в которых есть определенные типы больниц в зависимости от их собственности. Но когда я получаю значение от разных больниц, это показывает мне некоторую ошибку. Мой файл маршрута
Route::get('/', array('as' =>'home' ,'uses' => 'UserController@index')); Route::get('/about_us', array('as' =>'about_us' ,'uses' => 'UserController@about_us')); Route::get('/district/{id}', array('as' =>'district' ,'uses' => 'UserController@district')); Route::get('/district/hospital/{id}', array('as' =>'hospital' ,'uses' => 'UserController@hospital')); Route::get('/district/hospital/hospital_info/{id}', array('as' =>'hospital_info' ,'uses' => 'UserController@hospital_info'));
Мой контроллер
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); }
Мой файл просмотра
<?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
& МОЯ модель – 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'); } }
District.php
<?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'); } }
ошибка
Пожалуйста помогите. заранее спасибо