在 Laravel 5 中单击提交时出现错误?
Getting error when click Submit in Laravel 5?
控制器文件代码:EmergencyContactsController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\EmergencyContacts;
class EmergencyContactsController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function create(){
return view('patient/emergencycontacts');
}
public function store(array $data){
echo '<pre>'; print_r($data); die();
}
}
路由文件代码:
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route::get('/home', 'HomeController@index');
Route::get('/patient/emergency-contacts' , 'patient/EmergencyContacts@index' ) ;
Route::get('/emergencycontacts_create' , 'patient/EmergencyContacts@create' ) ;
//Route::post('/emergncycontacts_store' , 'patient/EmergencyContacts@store' ) ;
Route::post('/emergencycontacts_store', ['uses' => 'patient/EmergencyContacts@store', 'as' => 'emergencycontacts_store']);
Route::resource('/patient/emergency-contacts', 'EmergencyContactsController');
Blade 文件代码:patient/emergencycontacts.blade.php
{!! Form::open(array('route' => 'emergencycontacts_store', 'class' => 'form')) !!}
<div class="form-group">
{!! Form::label('Salutation') !!}
{{ Form::select('salutation', ['Mr.', 'Mrs.', 'Miss.','Ms.']) }}
</div>
<div class="form-group">
{!! Form::label('First Name') !!}
{!! Form::text('firstname', null, array('required', 'class'=>'form-control', 'placeholder'=>'First Name')) !!}
</div>
<div class="form-group">
{!! Form::label('Last Name') !!}
{!! Form::text('lastname', null, array('required', 'class'=>'form-control', 'placeholder'=>'Last Name')) !!}
</div>
<div class="form-group">
{!! Form::label('Relationship') !!}
{{ Form::select('relationship', ['Father', 'Mother', 'Husband','Wife','Son','Daughter','Uncle','Aunty','Other']) }}
</div>
<div class="form-group">
{!! Form::label('Phone') !!}
{!! Form::text('phone', null, array('required'ReflectionException in Container.php line 719: Class App\Http\Controllers\patient/EmergencyContacts does not exist, 'class'=>'form-control', 'placeholder'=>'Phone')) !!}
</div>
<div class="form-group">
{!! Form::label('Fax') !!}
{!! Form::text('fax', null, array('class'=>'form-control', 'placeholder'=>'Fax')) !!}
</div>
<div class="form-group">
{!! Form::submit('Save',array('class'=>'btn btn-primary')) !!}
</div>
{{ Form::close() }}
当我尝试提交时,出现以下错误。我是 laravel 的新人。
获取错误:
ReflectionException in Container.php line 719: Class App\Http\Controllers\patient/EmergencyContacts does not exist
更新 routes/web.php 文件中给定的控制器路径:
'EmergencyContactsController@...'
商店功能:
public function store(Request $request)
{
echo '<pre>';
print_r($request->all());
echo '</pre>';
}
控制器文件代码:EmergencyContactsController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\EmergencyContacts;
class EmergencyContactsController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function create(){
return view('patient/emergencycontacts');
}
public function store(array $data){
echo '<pre>'; print_r($data); die();
}
}
路由文件代码:
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route::get('/home', 'HomeController@index');
Route::get('/patient/emergency-contacts' , 'patient/EmergencyContacts@index' ) ;
Route::get('/emergencycontacts_create' , 'patient/EmergencyContacts@create' ) ;
//Route::post('/emergncycontacts_store' , 'patient/EmergencyContacts@store' ) ;
Route::post('/emergencycontacts_store', ['uses' => 'patient/EmergencyContacts@store', 'as' => 'emergencycontacts_store']);
Route::resource('/patient/emergency-contacts', 'EmergencyContactsController');
Blade 文件代码:patient/emergencycontacts.blade.php
{!! Form::open(array('route' => 'emergencycontacts_store', 'class' => 'form')) !!}
<div class="form-group">
{!! Form::label('Salutation') !!}
{{ Form::select('salutation', ['Mr.', 'Mrs.', 'Miss.','Ms.']) }}
</div>
<div class="form-group">
{!! Form::label('First Name') !!}
{!! Form::text('firstname', null, array('required', 'class'=>'form-control', 'placeholder'=>'First Name')) !!}
</div>
<div class="form-group">
{!! Form::label('Last Name') !!}
{!! Form::text('lastname', null, array('required', 'class'=>'form-control', 'placeholder'=>'Last Name')) !!}
</div>
<div class="form-group">
{!! Form::label('Relationship') !!}
{{ Form::select('relationship', ['Father', 'Mother', 'Husband','Wife','Son','Daughter','Uncle','Aunty','Other']) }}
</div>
<div class="form-group">
{!! Form::label('Phone') !!}
{!! Form::text('phone', null, array('required'ReflectionException in Container.php line 719: Class App\Http\Controllers\patient/EmergencyContacts does not exist, 'class'=>'form-control', 'placeholder'=>'Phone')) !!}
</div>
<div class="form-group">
{!! Form::label('Fax') !!}
{!! Form::text('fax', null, array('class'=>'form-control', 'placeholder'=>'Fax')) !!}
</div>
<div class="form-group">
{!! Form::submit('Save',array('class'=>'btn btn-primary')) !!}
</div>
{{ Form::close() }}
当我尝试提交时,出现以下错误。我是 laravel 的新人。 获取错误:
ReflectionException in Container.php line 719: Class App\Http\Controllers\patient/EmergencyContacts does not exist
更新 routes/web.php 文件中给定的控制器路径:
'EmergencyContactsController@...'
商店功能:
public function store(Request $request)
{
echo '<pre>';
print_r($request->all());
echo '</pre>';
}