Redirect to a resource route with parameters Laravel - redirect

I try to redirect to a resource route with paramateres in my laravel controller
Redirect::route('users.show', array('user'=> $user->account_id));
but the parameter is never getting passed through.
What I'm doing wrong?

You can Try like this
redirect()->route('users.show', ['user'=> $user->account_id]);

It should work. May be you are passing a null value.
Check the value of $user->account_id using dd($user->account_id);

Try to use this:
Redirect::route('users.show', ["user" => $user->account_id]);

You have to add "return" keyword before "redirect". Try like this
return redirect()->route('users.show', $user->account_id);

Related

Lumen Regular Expression Constraints throw NotFoundHttpException

I have a list of routes, some are using parameters and everything is working correctly.
My problem happen when I try to constrain the parameter (to check the it is valid before executing my controller).
Following the documentation I did it this way :
$router->group(['middleware' => 'auth:api'], function () use ($router) {
$router->get('/user/{userId:[a-z0-9]+}', 'UserController#userByUserIdGet');
});
But all I receive is a NotFoundHttpException meaning that it doesn't match my route.
I can't see where my mistake is. Any idea?
Thank you.
The error you recieve, if your route doensn't exists is a MethodNotAllowedHttpException - your code and the regex for your route do work correctly, so I am assuming, that your error could have an other reason.
Maybe you should check this:
NotFoundHttpException with Lumen
OK stupid error from my side.
I'm passing UUID as userID parameter... AND they have a dash in them.
So my regex should be this one
$router->group(['middleware' => 'auth:api'], function () use ($router) {
$router->get('/user/{userId:[a-z0-9\-]+}', 'UserController#userByUserIdGet');
});

How to add query parameter to routes in Lumen?

I am trying to know how to add query parameters to routes in Lumen
this is an example of a route I created
$app->get('/product/{apikey}','ProductController#getProduct');
This works when I use
http://api.lumenbased.com/product/10920918
but I would like to use it like this
http://api.lumenbased.com/product/?apikey=10920918
I tried this
$app->get('/product/?apikey={apikey}','ProductController#getProduct');
But this gives me MethodNotAllowedHttpException
I would like to know how to write routes with query parameters in Lumen ?
Just do:
$app->get('/product','ProductController#getProduct');
and use:
$request->get('apikey')
in the ProductController#getProduct function.
(That said, validating an API key is better done via middleware...)

how to pass parameter in facebook redirect_uri

I'm using https://graph.facebook.com/oauth/authorizeclient_id=APP_ID&redirect_uri=MY_URL&scope=user_likes,friends_likes
to get permissions from user to access his information. after that i'm being redirected to MY_URL, the problem is that i need to pass a parameter to MY_URL.
i would like to do something like:
MY_SITE?parameter=test.
how do i do it without mixing with outer parameters?
thanks!
Use urlencode(MY_URL) instead of MY_URL
Replace MY_URL with encodeURIComponent(MY_URL) using javascript. For example:
window.location = 'https://graph.facebook.com/oauth/authorizeclient_id=APP_ID&redirect_uri='+encodeURIComponent(MY_URL)+'&scope=user_likes,friends_likes';

Play Framework - Redirect with params

I am trying to figure out how to do a redirect within a controller action in Play (2.0) using Scala.
The redirect using
Redirect(routes.Application.index)
works just fine.
What I cannot figure out from the docs, API, or Google is how to add parameters to the call.
I am coming from Grails where this could be done easily as follows:
redirect action: "index", params: ["key": "value"]
.
The only way I have found is to call Redirect using a string url and a query string, which seems awkward.
Basically I would like to make use of Redirect(Call) somehow, but I do not how to create the Call object using reverse routing.
Am I missing something/not getting the concept in Play/Scala?
Thanks in Advance!
Ellou'
A route is just a function, so you can pass arguments as usual:
// Redirect to /hello/Bob
def helloBob = Action {
Redirect(routes.Application.hello("Bob"))
}
This snippet comes from http://www.playframework.org/documentation/2.0/ScalaRouting (at the bottom)
You can also avoid creating another function just for this in your controller. In your route config, you can simply add something like this:
GET /google #controllers.Default.redirect(to = "http://google.com")

Redirect with Mason 1.0

I am using Mason 1.0 and want to redirect the page to another URL.
Is there any way to redirect?
Alternatively...
I have written following code in dbhandler which is giving error, stating that $r is undefined. Can you please help.
$r->method('GET');
$r->headers_in->unset('Content-length');
$r->content_type('text/html');
$r->header_out('Location' => $newPageURL);
$m->abort(301);
I cannot use $m->redirect as it is not avalible to me.
I am referring to this link http://www.masonhq.com/htmlmason/wiki/FAQ:HTTPAndHTML on the section "How do I do an external redirect?"
$r->status(302);
$r->headers_out()->add("Location", "http://google.com");
return 302;
Looks like $m->clear_buffer is missing before your first call.
It's required so it wipes out any response generated before you reach your redirection.