This is for flash data not request parameters.
return Redirect::route('user')->with('nick', $username);
Use this one
return Redirect::route('user', array('nick' => $username));
And I think your problem is you didn't name your route. Try
Route::get('user/{nick}', array('as' => 'user', function($nick) { return View::make('home.user')->with('target', $nick); }));
bmgalego said:
This is for flash data not request parameters.
return Redirect::route('user')->with('nick', $username);
Use this one
return Redirect::route('user', array('nick' => $username));
And I think your problem is you didn't name your route. Try
Route::get('user/{nick}', array('as' => 'user', function($nick) { return View::make('home.user')->with('target', $nick); }));
I've modified, now this are my routes
Route::get('/find', array(
'as' => 'find-post',
'uses' => 'HomeController@find'
));
Route::get('/find', function() {
return View::make('home.find');
});
Route::get('user/{nick}', array('as' => 'user', function($nick) {
return View::make('home.user')->with('target', $nick);
}));
And this the controller
public function find() {
$validator = Validator::make(Input::all(),
array(
'username' => 'required'
));
if($validator->fails()) {
return Redirect::route('find')
->withErrors($validator);
}
else
{
$username = Input::get('username');
$search = User::where('Name', '=', $username)->first();
if($search) {
return Redirect::route('user', array('nick' => $username));
}
else
{
$errors = new MessageBag(['error' => ['Player does not exist']]);
return Redirect::back()->withErrors($errors);
}
}
}
And i still get NotFoundHttpException
Here you have two routes with same uri and method. fix that
Route::get('/find', array(
'as' => 'find-post',
'uses' => 'HomeController@find'
));
Route::get('/find', function() {
return View::make('home.find');
});
And in controller you redirect when validator fails to Redirect::route('find'), and you have no routes named find. Remember you are using named routes, so name your routes. If you want to redirect to a specific url use Redirect::to('find')
bmgalego said:
Here you have two routes with same uri and method. fix that
Route::get('/find', array( 'as' => 'find-post', 'uses' => 'HomeController@find' )); Route::get('/find', function() { return View::make('home.find'); });
And in controller you redirect when validator fails to Redirect::route('find'), and you have no routes named find. Remember you are using named routes, so name your routes. If you want to redirect to a specific url use Redirect::to('find')
Route::get('/find', array(
'as' => 'find-post',
'uses' => 'HomeController@find'
));
Route::get('/find', array('as' => 'find', function() {
return View::make('home.find');
});
Route::get('user/{nick}', array('as' => 'user', function($nick) {
return View::make('home.user')->with('target', $nick);
}));
I named my routes, one find is find-post, and the other is just find. But i still get notfound
I think the problem is your routes, you probably want the router to use the route 'find-post' on a POST method so change it from get to post
Route::post('/find', array(
'as' => 'find-post',
'uses' => 'HomeController@find'
));
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community