skip to Main Content

Is there a possibility to get the part of url, that is defined in route?
For example with this route:

Route::get('/editor/{id}', 'EditorController@editor')->name('editorNew');

after using mentioned functionality, let’s say route_link(); i would like to get:

$route_link = route_link('editorNew', array('id' => 1));
//$route_link containts "/editor/1"

I tried to use route(), but i got http://localhost/app/public/editor-new/1 instead of /editor-new/1 and that’s not what i wanted.
For clarity need this functionality to generate links depending on machine, that the app is fired on (integration with Shopify).

2

Answers


  1. You could use the following:

    $route_link = route('editorNew', [1]);
    

    1 is the first value that will be on the route, at this moment {id}.

    If you want to use the paramater (id) in your method, it will be the following:

    public function editor($id) {
        //your code
    }
    

    And in the view you could use:

    Route::input('id');
    

    Hope this works!

    Login or Signup to reply.
  2. You can use route method to get the relative path by passing false in the third parameter as:

    route('editorNew', [1], false); // returns '/editor-new/1'
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search