I have setup a view by extending my template file @extends( 'app' )
in my contact.blade.php
I define the routes like so
Route::get( 'contact', 'ContactController@getClub' );
in this controller I have
public function getClub( Request $request )
{
$id = $request->input( 'clubId' );
$club = DB::select( 'select * from club_info where id='.$id );
return view('contact', [
'club' => $club[ 0 ]
]);
}
The page works however I have a function which checks if the page is the current page and I would apply css/js like that. This function no longer returns the desired result. It was working at one point when I define the view with simple routes that does not go thru the controller
here is my function in the app service provider
public function boot()
{
// returns true if $name is the current page name
View::share( 'isCurrent', function( $name ) {
return Route::currentRouteNamed( $name );
});
}
A sample usage is in the app.blade file like this
if( $isCurrent( 'contact' ) )
<link rel="stylesheet" type="text/css" href="" />
@endif
I am not sure why it wouldn't work since I am still returning a view with the same name as before. The only thing I could think of is maybe, when this check occur the view wasn't named yet? But I have no idea, can someone please shed some light on it.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire