我遇到一个奇怪的问题。我正在为学生管理系统开发一个Web应用程序。我已经开发了API并通过Route :: dispatch()使用它。所有路线和视图都工作正常,但突然/学生路线抛出错误
“ ErrorException(E_ERROR) (查看:/home/rahul/Projects/institute_api/resources/views/students/index.blade.php)”
route.web.php
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('welcome');
});
Route::get('/courses',function(){
$response = getApiResponse('/api/v1/courses');
return view('course.index', ['response' => $response ]);
});
Route::get('/courses/{id}', function(){
return view('course.view');
});
Route::get('/courses/{id}/update', function(){
return view('course.update');
});
Route::get('/courses/add', function(){
return view('course.add');
});
Route::get('/batches',function(){
$response = getApiResponse('/api/v1/batches');
return view('batch.index', ['response' => $response ]);
});
Route::get('/batches/{id}', function(){
return view('batch.view');
});
Route::get('/batches/add',function(){
return view('batch.add');
});
Route::get('/batches/{id}/update', function(){
return view('batch.update');
});
Route::get('/faculties',function(){
$response = getApiResponse('/api/v1/faculties');
return view('faculties.index', ['response' => $response ]);
});
Route::get('faculties/{id}', function(){
return view('faculties.view');
});
Route::get('/faculties/add',function(){
return view('faculties.add');
});
Route::get('faculties/{id}/update', function(){
return view('faculties.update');
});
Route::get('/students', function(){
$response = getApiResponse('/api/v1/students');
return view('students.index', ['response' => $response]);
});
Route::get('students/{id}', function () {
return view('students.view');
});
Route::get('/students/add', function(){
return view('students.add');
});
Route::get('/students/{id}/update', function(){
return view('students.update');
});
Route::get('students/{id}/fee', function(){
return view('fee.index');
});
Route::get('students/{id}/course', function(){
return view('fee.course.add');
});
Route::get('students/{id}/course/update', function(){
return view('fee.course.update');
});
Route::get('students/{id}/pay', function()
{
return view('fee.pay');
});
<?php
function getApiResponse($url)
{
$request = Request::create($url, 'GET');
$response = Route::dispatch($request) ;
return $response;
}
views / students / index.blade.php
@extends('app')
@section('title','Students')
@section('page-heading','Students')
@section('content')
<div class="container">
<div class="row">
@php
$arr = json_decode($response, true);
$data = $arr;
@endphp
@foreach ($data['data'] as $student)
<div class="col-md-4 col-lg-3 col-sm-6 col-xs-12 mb-4 d-flex">
<div class="card" >
<img class="card-img-top" src="{{ $student["photo_url"] }}" alt="{{ $student["first_name"]." ".$student["middle_name"]." ".$student["last_name"] }}" >
<div class="card-body d-flex-column">
<h5 class="card-title">{{ $student["first_name"]." ".$student["middle_name"]." ".$student["last_name"] }}</h5>
<span class="card-text d-block">{{ $student["email"] }}</span>
<span class="card-text d-block">+91 {{ $student["phone"] }}</span>
<span class="card-text d-block">{{ $student["course"] }}</span>
<span class="card-text d-block">
@php
$request = Request::create('/api/v1/faculty/'.$student["faculty_id"], 'GET');
$newresponse = Route::dispatch($request)->getContent();
$newarr = json_decode($newresponse,true);
@endphp
{{ $newarr["first_name"].' '.$newarr["middle_name"].' '.$newarr["last_name"] }}
</span>
<span class="card-text d-block"><a href="/students/{{ $student["id"] }}" class="card-link">View</a></span>
<span class="card-text d-block"><a href="/students/{{ $student["id"] }}/update" class="card-link">Update</a></span>
<span class="card-text d-block"><a href="/students/{{ $student["id"] }}/pay" class="card-link">Fee Payment</a></span>
</div>
</div>
</div>
@endforeach
</div>
</div>
<nav aria-label="Page navigation example">
<ul class="pagination justify-content-center">
@if ($data["prev_page_url"])
<li class="page-item">
<a class="page-link" href="{{ $data["prev_page_url"] }}" tabindex="-1">Previous</a>
</li>
<li class="page-item"><a class="page-link" href="#">1</a></li>
@else
<li class="page-item disabled">
<a class="page-link" href="{{ $data["prev_page_url"] }}" tabindex="-1">Previous</a>
</li>
@endif
<li class="page-item active"><a class="page-link" href="#">{{ $data["current_page"] }}<span class="sr-only">(current)</span></a></li>
@if ($data["next_page_url"])
<li class="page-item"><a class="page-link" href="{{ $data["next_page_url"] }}">{{ $data["current_page"]+1 }}</a></li>
<li class="page-item">
<a class="page-link" href="{{ $data["next_page_url"] }}">Next</a>
</li>
@else
<li class="page-item disabled">
<a class="page-link" href="{{ $data["next_page_url"] }}" tabindex="-1">Next</a>
</li>
@endif
</ul>
</nav>
@endsection
谢谢