I'm creating a demo project. At the moment I'm building the basics for a users component. I created a resourceful route in my routes file, generated a UsersController via artisan, and started filling in the code.
In my UsersController
I have a simple index
method:
public function index()
{
$users = User::all();
return View::make('users.index')->with('users', $users);
}
A create
method for the new user form:
public function create()
{
return View::make('users.create');
}
And a store
method for the new user form submission:
public function store()
{
$user = new User;
$user->username = Input::get('username');
$user->email = Input::get('email');
$user->nameFirst = Input::get('nameFirst');
$user->nameLast = Input::get('nameLast');
$user->password = Input::get('password');
$user->save();
Redirect::route('users.index');
}
Right now, all of these work individually. The index method grabs all of the users and displays them correctly in my views/users/index.blade.php
view, the new user form generates correctly, and when I submit the form it fires the store
method and writes the user data to the database.
The problem I'm having is that when I try to redirect back to the index view using Redirect::route('users.index');
I get a blank browser window. My url shows as expected, http://localhost:8001/users
, but I get a completely blank window:
I read through the docs and it looks like I'm using the redirect route correctly. Can anyone help figure out what's going wrong?
I should also add that it doesn't seem like the redirect works regardless of which route I point it to. No matter which one of the route name I use I still get blank browser window.
EDIT: Here are my views:
Here's the views/users/index.blade.php
file:
@extends('layouts.default')
@section('title')
User List
@stop
@section('content')
<table>
<thead>
<tr>
<th>Username</th>
<th>First</th>
<th>Last</th>
<th>Email</th>
</tr>
</thead>
<tbody>
@foreach($users as $user)
<tr>
<td>{{ link_to("/users/{$user->username}", $user->username) }}</td>
<td>{{ $user->nameLast }}</td>
<td>{{ $user->nameFirst }}</td>
<td>{{ $user->email }}</td>
</tr>
@endforeach
</tbody>
</table>
<div>
{{ HTML::linkAction('users.create', "Create User") }}
</div>
@stop
Here's the views/users/create.blade.php
file:
@extends('layouts.default')
@section('content')
<h1>Create a New User</h1>
{{ @Form::open(['route' => 'users.store']) }}
<div>
{{ Form::label('nameFirst', "First Name") }}
{{ Form::text('nameFirst') }}
</div>
<div>
{{ Form::label('nameLast', "Last Name") }}
{{ Form::text('nameLast') }}
</div>
<div>
{{ Form::label('username', "Username") }}
{{ Form::text('username') }}
</div>
<div>
{{ Form::label('email', "Email") }}
{{ Form::text('email') }}
</div>
<div>
{{ Form::label('password', "Password") }}
{{ Form::password('password') }}
</div>
{{ Form::submit('Create User') }}
{{ @Form::close() }}
@stop
The routes.php
file:
<?php
Route::get('/', function()
{
return "home";
});
Route::resource('users', 'UsersController');
And the routes per php artisan routes
:
+--------+-----------------------------+---------------+-------------------------+----------------+---------------+
| Domain | URI | Name | Action | Before Filters | After Filters |
+--------+-----------------------------+---------------+-------------------------+----------------+---------------+
| | GET|HEAD / | | Closure | | |
| | GET|HEAD users | users.index | UsersController@index | | |
| | GET|HEAD users/create | users.create | UsersController@create | | |
| | POST users | users.store | UsersController@store | | |
| | GET|HEAD users/{users} | users.show | UsersController@show | | |
| | GET|HEAD users/{users}/edit | users.edit | UsersController@edit | | |
| | PUT users/{users} | users.update | UsersController@update | | |
| | PATCH users/{users} | | UsersController@update | | |
| | DELETE users/{users} | users.destroy | UsersController@destroy | | |
+--------+-----------------------------+---------------+-------------------------+----------------+---------------+