路由在 laravel 5.1 中无法正常工作
Routing did not work properly in laravel 5.1
我目前正在做一个名为 Doctor Management 的项目 System.In 这个项目我被卡住了,因为我的路线不起作用 correctly.Whenevr 我必须继续使用特定的 ID,它给了我乱码 ID。
我的路线文件是
Route::get('/district/hospital/hospital_info/{id}', array('as' =>'hospital_info' ,'uses' => 'UserController@hospital_info'));
我的控制器是
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Input;
use App\Division;
use App\District;
use App\Category;
use App\Dcategory;
use App\Hospital;
use App\Doctor;
class UserController extends Controller
{
public function hospital_info($id)
{
$divisions = Division::all();
$division=Division::find($id);
$district=District::find($id);
$category=Category::find($id);
$hospital=Hospital::find($id);
return view('users.hospital_info')
->with('divisions', $divisions)
->with('division', $division)
->with('district', $district)
->with('category',$category)
->with('hospital',$hospital);
}
我的视图文件是
<?php $active="hospital"; ?>
@extends('layouts.dashboard')
@section('content')
<section id="feature" class="transparent-bg">
<div class="container">
<div class="center wow fadeInDown">
<h2>Renowned Hospital in {{ $district->name }}</h2>
</div>
<div class="row">
<div class="features">
@foreach($categories as $category)
<div class="col-md-4 col-sm-6 wow fadeInDown" data-wow-duration="1000ms" data-wow-delay="600ms">
<div class="feature-wrap">
<h2>{{ $category->name }}</h2>
<h3><a href="{!! URL::route('hospital_info') !!}"> View Details</a></h3>
</div>
</div><!--/.col-md-4-->
@endforeach
</div>
</div>
</div>
</section>
@停止
错误是:
这里可以看到我没有找到id。但如果我静态地给出 id,它会显示信息。我找不到问题出在哪里。请帮我解决这个问题。
您在 URL 中使用了 {id}
,这应该替换为整数 ID。例如你的 URL 应该是 http://localhost/doctor_info/public/district/hospital/hospital_info/1
你应该在你的控制器中写这个
public function hospital_info($id)
{
$divisions = Division::all();
$division=Division::find($id);
$district=District::find($id);
$categories=Category::all();
$category=Category::find($id);
$hospital=Hospital::find($id);
// $hospitals =$hospital->paginate(5);
$hospitals = Hospital::where('district_id',$id)->paginate(2);
$doctor=User::find($id);
$doctors = User::where('district_id',$id)->paginate(1);
// $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('category',$category)
->with('hospital',$hospital)
->with('hospitals',$hospitals)
->with('doctor',$doctor)
->with('doctors',$doctors);
}
并且在你的视图文件中你应该写
<?php $active="hospital"; ?>
@extends('layouts.dashboard')
@section('content')
<section id="feature" class="transparent-bg">
<div class="container">
<div class="center wow fadeInDown">
<h2>Renowned Hospital in {{ $district->name }}</h2>
</div>
<div class="row">
<div class="features">
@foreach($categories as $category)
<div class="col-md-4 col-sm-6 wow fadeInDown" data-wow-duration="1000ms" data-wow-delay="600ms">
<div class="feature-wrap">
<h2>{{ $category->name }}</h2>
<h3><a href="{!! URL::route('hospital_info',$district['id']) !!}"> View Details</a></h3>
</div>
</div><!--/.col-md-4-->
@endforeach
</div>
</div>
</div>
</section>
@stop
我目前正在做一个名为 Doctor Management 的项目 System.In 这个项目我被卡住了,因为我的路线不起作用 correctly.Whenevr 我必须继续使用特定的 ID,它给了我乱码 ID。 我的路线文件是
Route::get('/district/hospital/hospital_info/{id}', array('as' =>'hospital_info' ,'uses' => 'UserController@hospital_info'));
我的控制器是
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Input;
use App\Division;
use App\District;
use App\Category;
use App\Dcategory;
use App\Hospital;
use App\Doctor;
class UserController extends Controller
{
public function hospital_info($id)
{
$divisions = Division::all();
$division=Division::find($id);
$district=District::find($id);
$category=Category::find($id);
$hospital=Hospital::find($id);
return view('users.hospital_info')
->with('divisions', $divisions)
->with('division', $division)
->with('district', $district)
->with('category',$category)
->with('hospital',$hospital);
}
我的视图文件是
<?php $active="hospital"; ?>
@extends('layouts.dashboard') @section('content')
<section id="feature" class="transparent-bg">
<div class="container">
<div class="center wow fadeInDown">
<h2>Renowned Hospital in {{ $district->name }}</h2>
</div>
<div class="row">
<div class="features">
@foreach($categories as $category)
<div class="col-md-4 col-sm-6 wow fadeInDown" data-wow-duration="1000ms" data-wow-delay="600ms">
<div class="feature-wrap">
<h2>{{ $category->name }}</h2>
<h3><a href="{!! URL::route('hospital_info') !!}"> View Details</a></h3>
</div>
</div><!--/.col-md-4-->
@endforeach
</div>
</div>
</div>
</section>
@停止
错误是:
这里可以看到我没有找到id。但如果我静态地给出 id,它会显示信息。我找不到问题出在哪里。请帮我解决这个问题。
您在 URL 中使用了 {id}
,这应该替换为整数 ID。例如你的 URL 应该是 http://localhost/doctor_info/public/district/hospital/hospital_info/1
你应该在你的控制器中写这个
public function hospital_info($id)
{
$divisions = Division::all();
$division=Division::find($id);
$district=District::find($id);
$categories=Category::all();
$category=Category::find($id);
$hospital=Hospital::find($id);
// $hospitals =$hospital->paginate(5);
$hospitals = Hospital::where('district_id',$id)->paginate(2);
$doctor=User::find($id);
$doctors = User::where('district_id',$id)->paginate(1);
// $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('category',$category)
->with('hospital',$hospital)
->with('hospitals',$hospitals)
->with('doctor',$doctor)
->with('doctors',$doctors);
}
并且在你的视图文件中你应该写
<?php $active="hospital"; ?>
@extends('layouts.dashboard')
@section('content')
<section id="feature" class="transparent-bg">
<div class="container">
<div class="center wow fadeInDown">
<h2>Renowned Hospital in {{ $district->name }}</h2>
</div>
<div class="row">
<div class="features">
@foreach($categories as $category)
<div class="col-md-4 col-sm-6 wow fadeInDown" data-wow-duration="1000ms" data-wow-delay="600ms">
<div class="feature-wrap">
<h2>{{ $category->name }}</h2>
<h3><a href="{!! URL::route('hospital_info',$district['id']) !!}"> View Details</a></h3>
</div>
</div><!--/.col-md-4-->
@endforeach
</div>
</div>
</div>
</section>
@stop