2017-04-12 51 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

为什么有人指出我的答案是向下的? –

相关问题