Support the ongoing development of Laravel.io →
posted 10 years ago
Requests Input
Last updated 2 years ago.
0

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); })); 
Last updated 2 years ago.
0

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

Last updated 2 years ago.
0

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')

Last updated 2 years ago.
0

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

Last updated 2 years ago.
0

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'
));
Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Joe96 joe96 Joined 28 Apr 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.