我使用Route::controller
來查看和編輯表單。在這個動作laravel說:laravel在route :: controller中找不到控制器方法
Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException
Controller method not found.
我的路線:
Route::group(array('prefix'=> 'admin' ,'before'=>'auth'), function(){
Route::controller('profile', 'ProfileController', array('getIndex'=>'profile.index', 'postUpdate'=>'profile.update'));
});
我的表格:
{{ Form::model($profile, array('route' => array('profile.update', $profile->id), 'method' => 'PUT')) }}
{{ Form::close() }}
ProfileController可:
class ProfileController extends \BaseController {
public $layout = 'back_end.layouts.main';
function __construct() {
$this->beforeFilter('auth', array('except' => array('getIndex', 'postUpdate')));
$this->beforeFilter('csrf', array('on' => 'post'));
}
public function getIndex()
{
if(Auth::check()){
$profiles = Auth::user();
return View::make('back_end.layouts.profile')->with('profile', $profiles);
}
else return Redirect::intended('login');
}
public function postUpdate($id)
{
if (Session::token() != Input::get('_token'))
{
return Response::view('back_end.missing', array(), 404);
}
$rules = array(
'name' => 'required|alpha',
'family' => 'required',
'email' => 'required|email',
'currPassword'=> 'required',
'password' => 'required|confirmed',
'password_confirmation'=>'required',
);
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails())
{
return Redirect::to('/admin/profile')
->withErrors($validator)
->withInput();
}
$id = Input::get ('id');
$data = User ::find($id);
$HashPassowrd = Hash::make(Input::get('password'));
if(! Hash::check(Input::get('currPassword') , $data->password))
{
return Redirect::to('/admin/profile')
->withErrors('Current Password Error!');
}
else{
$admin = new User;
$admin = User::find($id);
$admin->name = Input::get('name');
$admin->family = Input::get('family');
$admin->email = Input::get('email');
$admin->password = $HashPassowrd;
$admin->save();
return Redirect::to('/admin/profile')
->withErrors('Edit Successfull');
}
}
}
PHP工匠路線
+--------+------------------------------------------------------------------------+---------------------+---------------------------------------+----------------+---------------+
| Domain | URI | Name | Action | Before Filters | After Filters |
+--------+------------------------------------------------------------------------+---------------------+---------------------------------------+----------------+---------------+
| | GET/ | | Closure | | |
| | GET index | index | Closure | | |
| | GET admin/index | dashboard | Closure | | |
| | GET logout | logout | Closure | | |
| | POST auth | auth | Closure | csrf | |
| | GET login | login | Closure | | |
| | GET admin/profile/index/{one?}/{two?}/{three?}/{four?}/{five?} | profile.index | [email protected] | auth | |
| | GET admin/profile | | [email protected] | auth | |
| | POST admin/profile/update/{one?}/{two?}/{three?}/{four?}/{five?} | profile.update | [email protected] | auth | |
| | GET admin/profile/{_missing} | | [email protected] | auth | |
| | GET admin/manaheHeaders/index/{one?}/{two?}/{three?}/{four?}/{five?} | manageHeader.index | [email protected] | auth | |
| | GET admin/manaheHeaders | | [email protected] | auth | |
| | POST admin/manaheHeaders/update/{one?}/{two?}/{three?}/{four?}/{five?} | manageHeader.update | [email protected] | auth | |
| | GET admin/manaheHeaders/{_missing} | | [email protected] | auth | |
| | GET test | test | Closure | | |
+--------+------------------------------------------------------------------------+---------------------+---------------------------------------+----------------+---------------+
也許檢查'artisan routes'的輸出以確保你的URI和路由名是正確的。你也沒有提到(或者我沒有看到)錯誤出現的位置 - 在調用Form :: open()時,還是在瀏覽器中訪問URI(或兩者) ?如果'Form :: open()'調用沒有問題並顯示錶單,則可能需要檢查它生成的URL,以確保它與您的路由符合預期。 – alexrussell
你打的網址是什麼? –
@AntonioCarlosRibeiro在路線或控制器? –