skip to Main Content

I have this route:

Route::get('product/get/{project_token}/{user_id}/{id}', 'get_project')->where('id', '.*'); 

Here for the id param, the value can be any character like

DRGM48/58BA
DRGM48/78BA+BZA43B.
1254EBD

Now, If the id param value is this DRGM48/78BA+BZA43B then I can see that the route is not passing the value. It seems like + character is not accepting.

Can you tell me how can I fix it?

2

Answers


  1. Plus sign is used to represent a space character in the query. So for this, you have to use urlencode and urldecode

    Ex

    $product_id = urlencode('DRGM48/78BA+BZA43B');
    

    In controller

    public function get_project($project_token, $user_id, $id)
    {
        $product_id = urldecode($id);
        // use $product_id in your code
    }
    
    Login or Signup to reply.
  2. I have the same issues in my previous project. So, I have applied multiple solutions but not worked. Then I find the solution which is below.

    Description: The "+" character is a reserved character in URLs and is used to represent a space. Laravel’s route parameters use the "+" character as a wildcard, which means that any text after the + character will be ignored.

    Route::get('product/get/{project_token}/{user_id}/{id}', 'get_project')->where('id', '[A-Za-z0-9+/]+');

    Hope this help to you.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search