mercredi 30 décembre 2015

Laravel 4 - Route [users.postUpdate] not defined

I'm currently doing a demo application on Laravel4. The demo application have some users in the database. I want to edit them one by one. I have a method "postUpdate", however, during editing (http://localhost/testlaravell/users/5/edit) an user from the list, I see the error occurs -

ErrorException (E_ERROR)
Route [users.postUpdate] not defined. (View: D:\wamp\www\testlaravell\local\app\views\users\edit.blade.php).

I have the codes in the routes.php:

Route::get('/', function()
{
return View::make('hello');
});
Route::get('users/{all}/edit', 'UserController@getEdit');
Route::controller('users', 'UserController');

In the UserController.php, I wrote the following script for edit and update:

public function getEdit($id)
{
    //

    $user = User::find($id);
    if (is_null($user))
        {

            return Redirect::to('users/all');
        }
    return View::make('users.edit', compact('user'));
}


/**
 * Update the specified resource in storage.
 *
 * @param  int  $id
 * @return Response
 */
public function postUpdate($id)
{
    //


    $input = Input::all();
    $validation = Validator::make($input, User::$rules);
    if ($validation->passes())
    {
        //$user = User::find($id);

            $user = User::find($id);
            $user->username = Input::get('username');
            $user->name = Input::get('name');
            $user->email = Input::get('email');
            $user->phone = Input::get('phone');
            $user->password = Hash::make(Input::get('password'));
            $user->save();

        return Redirect::route('users.getIndex', $id);
    }
    return Redirect::route('users.getEdit', $id)
        ->withInput()
        ->withErrors($validation)
        ->with('message', 'There were validation errors.');
}

The code under edit.blade.php as below:

@extends('users.user') 

@section('main')

<h1>Edit User</h1>
{{ Form::model($user, array('method' => 'PATCH', 'route' => array('users.postUpdate', $user->id))) }}
<ul>
    <li>
        {{ Form::label('username', 'Username:') }}
        {{ Form::text('username') }}
    </li>
    <li>
        {{ Form::label('password', 'Password:') }}
        {{ Form::text('password') }}
    </li>
    <li>
        {{ Form::label('email', 'Email:') }}
        {{ Form::text('email') }}
    </li>
    <li>
        {{ Form::label('phone', 'Phone:') }}
        {{ Form::text('phone') }}
    </li>
    <li>
        {{ Form::label('name', 'Name:') }}
        {{ Form::text('name') }}
    </li>
    <li>
        {{ Form::submit('Update', array('class' => 'btn btn-info')) }}
        {{ link_to_route('users.getAll', 'Cancel', $user->id, array('class' => 'btn')) }}
    </li>
</ul>
{{ Form::close() }}

@if ($errors->any())
<ul>
    {{ implode('', $errors->all('<li class="error">:message</li>')) }}
</ul>
@endif

@stop

What I missed I don't know. Can someone help me?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1RQYwEB
via IFTTT

Aucun commentaire:

Enregistrer un commentaire