我现在正在开展一个名为Hospital& amp;的项目。医生信息。我在这里有不同的孟加拉国分部和在每个部门中,根据其所有权,存在某些类型的医院。但是当我得到不同医院的价值时,它显示出一些错误。它没有找到具体的身份证明。我之前已经问了问题。但它没有解决我的问题。所以我再问这个问题。我的路线文件
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'));
我的医院信息刀片文件
<?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->cats 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
<div class="col-xs-12 col-sm-2 blog-content">
<h2><a href="#">Share</a></h2>
<ul class="social-share">
<li><a href="#"><i class="fa fa-google-plus"></i></a></li>
<li><a href="#"><i class="fa fa-facebook"></i></a></li>
<li><a href="#"><i class="fa fa-twitter"></i></a></li>
<li><a href="#"><i class="fa fa-skype"></i></a></li>
</ul>
<br><br>
<a class="btn btn-success readmore" href="#">Booking</a>
</div>
</div>
</div><!--/.blog-item-->\
</div><!--/.col-md-8-->
</div><!--/.row-->
</div>
</section><!--/#blog-->
@stop
我的控制器
public function district($id)
{
$divisions = Division::all();
$division=Division::find($id);
$district=District::find($id);
// $districts=District::where('division_id', '=', $divisions->id)->get();
if (!$division)
{
throw new NotFoundHttpException;
}
return view('users.district')
->with('divisions', $divisions)
->with('division', $division)
->with('district', $district);
}
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();
$cats=Category::find($id);
$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('cats',$cats)
->with('hospitals',$hospitals);
}
模范医院
<?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');
}
}
分部模型是
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Input;
class Division extends Model
{
protected $fillable = ['name'];
public function districts()
{
// $divisions = Division::all();
// $division_id = Input::get('id');
return $this->hasMany('App\District','division_id');
}
}
我几天前问了这个问题,但没有找到答案。 Plz帮助我。
答案 0 :(得分:0)
您的主要问题是您是否正在尝试从ID获取医院,但您尚未在医院模型中定义任何ID,因此首先应将id列添加到您的医院模型中。
其次从这个
改变你的功能public function hospital_info($id)
{
$divisions = Division::all();
$division=Division::find($id);
$district=District::find($id);
$categories=Category::all();
$cats=Category::find($id);
$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('cats',$cats)
->with('hospitals',$hospitals);
}
到此
public function hospital_info($id)
{
$hospital=Hospital::find($id);
$divisions = Division::all();
$categories=Category::all();
// $districts=District::where('division_id', '=', $divisions->id)->get();
// if (!$district)
// {
// throw new NotFoundHttpException;
// }
return view('users.hospital_info') , compact('divisions','categories', 'hospital');
}
那么你可以得到这样的信息
<div class="col-xs-12 col-sm-6 blog-content">
<h2>{{ $hospital->name }}</h2>
</div>
@foreach($divisions as $itemDivision)
@foreach($categories as $itemCategory)
<div class="col-xs-12 col-sm-6 blog-content">
<h2>{{ $itemDivision->name }}</h2>
</div>
@endforeach
@endforeach
例如,获取有关学区的所有信息:
您应该将(id)列添加到所有模型中,以便以后使用它们 你的函数内部执行此操作:
public function district($id)
{
$district=District::findorfail($id);
$hospitals = DB::table('hospitals')
->leftjoin('districts' ,'hospitals.district_id' , '=', 'districts.id')
->where('district.id','=',$id)
->select('hospitals.*')
->get();
return view('users.district'),compact('district','hospitals') ;
}
当然,医院是一系列对象,您应该使用循环来获取每家医院的信息