Can you submit your code, so we can see where it goes wrong.
For
return Redirect::route('confirm')
to work, you need to have named the route that matches 'confirm'
.
If you just want to point to http://yourwebsite.com/confirm
, you should use
return Redirect::to('confirm')
Both of these ways require that you have a route set up to handle the confirm
route. Like this:
return Route::get('confirm', function() { ... });
You should also pass along your initial record's id, as otherwise it won't be known by the route you are submitting the form to from the confirm
page:
return Redirect::to('confirm')->with('record_id', $id);
You can then get the record_id
in the confirm
function with
$record_id = Session::get('record_id);
Hope this helps.
This
return Route::get('confirm', function() { ... });
should be
Route::get('confirm', function() { ... });
Hi This is my error
invalidArgumentException Route [confirm] not defined.
Route::any('confirm', function(){
return 'hi';
});
And this is from my model
public static function deleteCity($id)
{
$city = City::find($id);
if($id == $city['id'])
{
return Redirect::route('confirm');
}else
{
var_dump('This is incorrect');
}
Hello, I think the correct format of the routes should be something like this:
Route::get('the/url', array('as' =>'route.name','uses'=>'ControllerName@MethodName'));
You can also use resourceful routing like this:
Route::resource('ModelName', 'ControllerName');
@ottz0 In your case you need to either name your route:
Route::any('confirm', array('as' => 'confirm', function()
{
return 'hi';
}));
or, use Redirect::to()
:
return Redirect::to('confirm');
I think, Redirects
don't get executed when in a model method that gets called from a controller. But to keep with the MVC principle, the model should not really contain application logic anyway. And redirects and routes are clearly application logic. So it's best if you keep your Redirect
in the controller (or routes.php
closure) and just make it dependant on a boolean
return value from a model method:
In the controller:
if( $city->hasBigPark() )
{
return Redirect::to('confirm');
}
// Do something ELSE
In the model you then have a method like this:
public function hasBigPark()
{
if($this->parkArea < 1000)
return true;
else
return false;
}
Thanks...... now how to I send data with it and does this need to go back to the controller in order to pass it again to the route?
Sorry I'm only new to this and I don't know what is supposed to be sending, receiving, routing and %^#E$#YT%%^&!!!!
Could you please explain from start to finish as I can only find part answers.
Does this: route->controller->model->controller->route->to page??????
Why can't it be route->controller->model->send straight to route with data?
In Model
public static function ab()
{
//Redirects need to be sent back to controller
$result = array('name'=>'alan');
return Redirect::to('cd')->with($result);
}
Ok Sisou,
Thanks for that, I got you. That was my suspicion but no documentation proved otherwise
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community