2017-04-12 48 views
0

我需要在控制器中獲得'mp3'值! (從mp3s type檢查崗位)Laravel.54將數據傳遞給動作控制器

我文章類型: 視頻,相冊,MP3

(web.php)

Route::group(array('prefix' => 'mp3s'), function($pt) { 
    Route::get("/", "[email protected]"); 
    Route::get("mp3/{slug}", "[email protected]"); 
    }); 


Route::group(array('prefix' => 'albums'), function($pt) { 
    Route::get("/", "[email protected]"); 
    Route::get("album/{slug}", "[email protected]"); 
    }); 


Route::group(array('prefix' => 'videos'), function($pt) { 
    Route::get("/", "[email protected]"); 
    Route::get("video/{slug}", "[email protected]"); 
    }); 
+0

爲什麼不直接使用路線::獲得(「{PREFIX}/{slug}「,」PostController @ singlePost「); ? – KoIIIeY

+0

你的意思是你想在控制器的功能中獲得slug值嗎? –

+0

@PHPWeblineindia我可以得到slu 012 –

回答

1

@danial dezfooli

至獲取前綴值你可以在控制器的方法內注入Request Dependency,如下所示。

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

or you can do in another way also 


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

更多的參考,你可以參考:Laravel 5 get route prefix in controller method

-1
Route::get("mp3/{slug}", "[email protected]"); 

在PostController中,你可以得到它像

public function singlePost($slug) { 
     dd($slug)// to check slug value 
    } 
+0

爲什麼有人指出我的答案是向下的? –

相關問題