PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, January 16, 2022

[FIXED] Laravel 5 get route prefix in controller method

 January 16, 2022     laravel-5, php     No comments   

Issue

I am working in Laravel 5.0 app.

I have created route group like below,

 Route::group(['prefix' => 'expert'], function () {

    Route::get('dashboard', [
          'as'   => 'expert.dashboard',
          'uses' => 'DashboardController@index'
    ]);
 ]);

I want to get the current route prefix in DashboardController's index method. I dont know how to do that. I could not find this in documentation. Please help me.


Solution

You can do this two way

Type-hinting Request in method

 public function index(\Illuminate\Http\Request $request){
  dd($request->route()->getPrefix());
 }

or

 public function index(){
  dd($this->getRouter()->getCurrentRoute()->getPrefix());
 }

I hope this helps.



Answered By - pinkal vansia
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing