2

Is this the correct way to pass the id from a function to another ?

return Redirect::to('uploads/show', $id);

or should I use

return Redirect::to('uploads/show')->with($id);

the function that I am trying to pass the id to

public function getShow($id)
{
  $entryid = $this->upload->findOrFail($id);

  $this->layout->content = View::make('uploads.show', compact('entryid'));
}

The error i get is

Missing argument 1 for UploadsController::getShow()

2 Answers 2

4

When using Redirect you should do:

return Redirect::to('uploads/show/'.$id);

to pass variable to controller though router

Sign up to request clarification or add additional context in comments.

Comments

2

If you want to do it as correctly as possible you need to craft your URL properly. The previous answer which uses string concatenation isn't wrong, but a better way might be:

return Redirect::to(URL::to('uploads/show', [$id]));

You will find though that as you get more routes, and especially the first time you decide to rework your routing convention, that using named routes (or at least controller-based routing with Route::controller) will probably serve you better. In this case it's a similar situation:

// routes.php
Route::get('uploads/show/{id}', ['as' => showUpload', 'uses' => 'Controller@action']);

// redirect:
return Redirect::route('showUpload', [$id]);

Also notice how you can pass the params directly in here (rather than using URL::to()) as using a named route isn't a simple string route like above.

Similarly, if you were using controller-based routing:

// routes.php
Route::Controller('uploads', 'Controller'); // I don't use this, syntax is like this

// redirect:
return Redirect::action('Controller@getShow', [$id]); // again I don't use this, but it's similar

1 Comment

Thanks for your answer, for the time being, the above answer will do the job.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.