lundi 28 décembre 2015

Laravel: Route [users.edit] not defined

I have created a demo application in Laravel 4, for some learning experience. The routes.php is as follows:

Route::get('/', function()
{
    return View::make('hello');
});

Route::group(['prefix' => 'users', 'before' => 'auth'], function () {
Route::get('dashboard', function () {
    $layout = View::make('users.dashboard');
    $layout->title = "Dashboard";
    $layout->content = View::make('users.dashboard');       
    return $layout;
}); 
Route::get('/all/', [ 'as' => 'users.index', 'uses' => 'UserController@all']);
Route::get('/create/', [ 'as' => 'users.create', 'uses' => 'UserController@create']);
Route::get('users/login', [ 'as' => 'users.login', 'uses' => 'UserController@getLogin']);
Route::post('users/login', [ 'as' => 'users.login', 'uses' => 'UserController@postSignin']);
Route::get('users/logout', [ 'as' => 'users.logout', 'uses' => 'UserController@getLogout']);
Route::resource('/','UserController');
});

Route::controller('users', 'UserController');

Here, I prefixed the "users". However, Trying logging in with/out correct login details, it shows only the login page instead of showing up the error message on the login page or dashboard.

Any suggestion? FYI,

The index.blade.php in app\views\users is below:

@extends('users.user') 
@section('title', 'User Listing Page')
@section('description', 'This is the user listing page')
@section('main')

<h1>All Users</h1>

<p>{{ link_to_route('users.create', 'Add new user') }}</p>

<h1>Login</h1>
<p>{{ link_to_route('users.login', 'Login') }}</p> 

<table>

    <tr>

        <td>{{ $users->links() }}</td>

    </tr>       

</table>


@if ($users->count())
<table class="table table-striped table-bordered">
    <thead>
        <tr>
    <th>Username</th>
    <th>Email</th>
    <th>Phone</th>
    <th>Name</th>
        </tr>
    </thead>

    <tbody>
        @foreach ($users as $user)
            <tr>
      <td>{{ $user->username }}</td>
      <td>{{ $user->email }}</td>
      <td>{{ $user->phone }}</td>
      <td>{{ $user->name }}</td>
      <td>{{ link_to_route('users.edit', 'Edit', array($user->id), array('class' => 'btn btn-info')) }}</td>
      <td>{{ Form::open(array('method' => 'DELETE', 'route' => array('users.destroy', $user->id))) }}
      {{ Form::submit('Delete', array('class' => 'btn btn-danger')) }}
                    {{ Form::close() }}
                </td>
            </tr>
        @endforeach



    </tbody>

</table>

<table>

    <tr>

        <td>{{ $users->links() }}</td>

    </tr>       

</table>

@else
    There are no users
@endif

@stop

The script login.blade.php (on the same location as above) as follows:

@extends('users.user') 

@section('main')

<h1>Login</h1>

{{ Form::open(array('route' => 'users.login')) }}

<ul>


    <li>
        {{ Form::label('username', 'Username:') }}
        {{ Form::text('username') }}
    </li>

    <li>
        {{ Form::label('password', 'Password:') }}
        {{ Form::password('password') }}
    </li>


    <li>
        {{ Form::submit('Submit', array('class' => 'btn')) }}
    </li>
</ul>
{{ Form::close() }}

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

@stop



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire