When trying to access this URL 'users/login' I got that error, Here is my code :
View users/login.blade.php :
<head>Sign in : </head>
<body>
{{ HTML::ul($errors->all()) }}
<?php echo Form::open(array('url' => 'users'));
echo '<div class="form-group">';
echo Form::label('username', 'User Name');
echo Form::text('ausername', null, array('class' => 'form-control'));
echo '</div>';
echo '<div class="form-group">';
echo Form::label('Password', 'Password');
echo Form::password('apassword', null, array('class' => 'form-control'));
echo '</div>';
echo Form::submit('Sign in', array('class' => 'btn btn-primary'));
echo Form::close();
?>
</body>
Controller Usercontroller.php
<?php
class UserController extends BaseController {
public function index()
{
$users = User::all();
return View::make('users.index')
->with('users', $users);
}
public function create()
{
return View::make('users.create');
}
public function store()
{
$rules = array(
'username' => 'required|alpha_dash',
'password' => 'required|confirmed',
'name' => 'required|regex:/^[a-zA-Z][a-zA-Z ]*$/',
'email' => 'required|email|unique:users',
'country' => 'required'
);
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return Redirect::to('users/create')
->withErrors($validator)
->withInput(Input::except('password'));
} else {
$user = new User;
$user->username = Input::get('username');
$user->password = Hash::make(Input::get('password'));
$user->name = Input::get('name');
$user->email = Input::get('email');
$user->country = Input::get('country');
$user->save();
// redirect
Session::flash('message', 'Successfully created user!');
return Redirect::to('users');
}
}
public function login()
{
$reflector = new ReflectionClass("UserController");
$fn = $reflector->getFileName();
dd($fn);
return View::make('users.login');
}
public function authen()
{
if (Auth::attempt(array('username' => Input::get('ausername'), 'password' => Input::get('apassword'))))
{
return Redirect::intended('users');
}
}
}
and my routes.php
<?php
Route::resource('users','UserController');
Route::get('users/login', 'UserController@login');
Route::get('/', function()
{
return View::make('hello');
});
is it a route problem, thank you for the help
I have experienced the same problem as you. The problem ends up with rearranging the resource code, i.e.
Route::get('masterprices/data', 'MasterPriceController@data');
Route::get( 'masterprices/upload', 'MasterPriceController@upload');
Route::post('masterprices/upload', 'MasterPriceController@do_upload');
Route::get('masterprices/{masterprices}/multipledelete', 'MasterPriceController@multipledelete');
Route::resource('masterprices', 'MasterPriceController');
It checks the other possible handler, if none it will reach the last line which is resource to handle index page.
This one:
Route::resource('users','UserController');
defines following routes:
| 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
So URI users/login calls users.show route and that's the problem.
Solution is like Kryten said to remove that route completely, but I suppose you still want to use some of the routes for the resource, like in your controller (create, store, index), so better use this:
Route::resource('users', 'UserController', ['only'=> ['index','create','store']]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With