I have a route that controls the current page user is in:
Route::group(array('prefix'=>'v1'), function(){
Route::resource('page', 'PageController', ['only'=>['index','show']]);
});
By the above code, it means that to go to homepage I need to type something like http://localhost/public/v1/page. So I need to make it to http://localhost/public/v1 so I changed the above code to something like this:
Route::group(array('prefix'=>'v1'), function(){
Route::resource('/', 'PageController', ['only'=>['index','show']]);
});
That works only for http://localhost/public/v1, if i navigate to something like http://localhost/public/v1/our-products it will produce error says route not found. Is there any workaround for this (without using .htaccess rewrite)?
Additionally I would like to strip the v1 in the link if possible, but the api code still there in the route, is it possible (again, without htaccess)? Thanks for the help.
EDIT
Here's my PageController:
<?php
class PageController extends MediaController { //MediaController extends BaseController
protected $layout = 'layouts.master';
private $data = array();
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index() //this one for index/home page
{
$data = array();
$data['data'] = null;
$css_files = $this->addCSS(array('styles'));
$plugin_files = $this->addJqueryPlugin(array('unslider'));
$data['css_files'] = $this->addCSS(array('styles'));
if(!empty($plugin_files) && isset($plugin_files)) {
$data['css_plugin'] = $plugin_files['css_files'];
$data['js_plugin'] = $plugin_files['js_files'];
}
$data['js_files'] = $this->addJS(array('app'));
$data['title'] = 'Homepage - PT Anugerah Bhandala Sejati';
$this->layout->content = View::make('page.home', $data);
}
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id) //this one for OTHER THAN home page (like news page or product page, so for example, the link "http://localhost/public/v1/our-products" logic will go here)
{
if($id === "our-products") {
$data = array();
$data['data'] = null;
$css_files = $this->addCSS(array('styles'));
$plugin_files = $this->addJqueryPlugin(array('unslider'));
$data['css_files'] = $this->addCSS(array('styles'));
if(!empty($plugin_files) && isset($plugin_files)) {
$data['css_plugin'] = $plugin_files['css_files'];
$data['js_plugin'] = $plugin_files['js_files'];
}
$data['js_files'] = $this->addJS(array('app'));
$data['title'] = 'Our Products - PT Anugerah Bhandala Sejati';
$this->layout->content = View::make('page.product', $data);
}
else
return "Page not found";
}
}
/as home page,/our-productsas product categories page,our-products/item1as product specific page,/newsas all news page,/news/news1/title-of-the-newsas news specific page and perhaps other routes for ajax request later (no membership here)routes.phpfile here? i'm not sure but it must be the order of your routes..array('prefix' => 'v1')part then?Route::resource('v1', 'PageController', ['only'=>['index','show']]);so you have ahttp://localhost/public/v1and ahttp://localhost/public/v1/{resourceid}routes auto generated