我是larevel的新手,从昨天开始到现在为止我一直试图解决这个问题,并且没有取得任何进展,我就被困在这里......
请帮助:(
以下是路线的代码:
Route::get('/admin/edit', array('uses' => 'AdminController@getUpdateUser', 'as' => 'getUpdateUser'));
Route::resource('admin1', 'AdminController');
这是我查看更新的按钮的代码(我认为问题可能就在这里,我不能想到会调用ID D的代码:)
{{ link_to_action('AdminController@getUpdateUser', 'Edit', array($users->id),array('class' => 'btn btn-info')) }}
- 这是我在 AdminController 的代码:
public function getUpdateUser($id)
{
$users = User::find($id);
//load view and pass users
return View::make('admin.edit')
->with('users', $users);
}
public function updateUser($id)
{
$validate = Validator::make(Input::all(), array(
'firstname' => 'required',
'lastname' => 'required',
'middlename' => 'required',
'address' => 'required',
'birthday' => 'required',
'contact' => 'required|numeric',
'email' => 'required'
));
if ($validate->fails()) {
return Redirect::to('admin.edit')
->withErrors($validate)
->withInput(Input::except('password'));
}
else
{
$user = User::find($id);
$user->firstname = Input::get('firstname');
$user->lastname = Input::get('lastname');
$user->middlename = Input::get('middlename');
$user->address = Input::get('address');
$user->birthday = Input::get('birthday');
$user->contact = Input::get('contact');
$user->email = Input::get('email');
if($user->save())
{
return Redirect::route('admin.view')->with('success', 'USER HAS BEEN UPDATED');
}
else
{
return Redirect::route('admin.view')->with('fail', 'An error occured while updating the user. Please double check your inputs and try again.');
}
}
}
这是 admin.edit
的代码@extends('layouts.master')
@section('head')
@parent
<title>Manage Users</title>
@stop
@section('content')
<div class ="container">
<h1>Edit User</h1>
{{ Form::model($users, array('route' => array('admin1.updateUser', $users- >id), 'method' => 'PUT')) }}
--textboxes and inputs here--
{{ Form::submit('Update', array('class' => 'btn btn-info')) }}
请帮帮我T_T谢谢!
答案 0 :(得分:0)
您错过的是将ID实际作为route parameter放在路线网址中。像这样:
Route::get('/admin/edit/{id}', array('uses' => 'AdminController@getUpdateUser', 'as' => 'getUpdateUser'));