What I'm trying to do is have the current class style to be shown on the menu that the page is on. For example if I'm on the contact page then the contact menu will have the current class.
The problem I'm having is that I'm not able to do it by using my seo table. My seo table connects to the menu table so that I can have something like localhost/website/contact.html instead of localhost/website/4
I'm able to do it if my route was like this
Route::get('/{id}', 'OpenController@content');
But because I would like my urls to have a name instead of an id it is no longer working and I'm struggling to get it to work.
This is my route. If the url is connected to the menu it then displays the url.
Route::get('/{id}', function($id = 1){
$column = 'url';
$url = App\Modules\Seo\Models\Seo::where($column, '=', $id)->get();
$seo = App\Modules\Seo\Models\Seo::where('url', $id)->firstOrFail();
foreach($seo->menu as $test){
$test_url = $test->id;
}
$action = 'content';
return App::make('App\Modules\Open\Http\Controllers\OpenController')->$action($test_url);
});
My menu_active function. This is supposed to grab the $test_url and add the current class to it.
function menu_active($test_url){
if(is_array($test_url)){
return in_array(Request::path(), $test_url) ? 'current' : '';
}
return Request::path() == $test_url ? 'current' : '';
}
I hope I explained everything properly
Try this :
<?php
$completePath = url()->getRequest()->getPathInfo();
$path = ltrim(substr($completePath, strrpos($completePath, '/')), '/');
dd($completePath, $path);
?>
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community