Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

zidance's avatar

Middleware not working after change config to detect view using Agent

Middleware share variable not working after i change to mobile view.

Every time call a specific route checking the middleware and share a variable from there using

 View::share('count', $count);

I change my view.php in config directory as shown below

<?php

$viewBasePath = realpath(base_path('resources/views'));

$viewsPaths = [$viewBasePath];

$agent = new Jenssegers\Agent\Agent();

if ($agent->isMobile()) {
    array_unshift($viewsPaths, $viewBasePath.'/mobile');
}

return [
    'paths' => $viewsPaths
    ...

It works fine for web, but when i deploy to my mobile it show undefined variable count? Anything i missed out?

0 likes
3 replies
Nakov's avatar

Are you accessing the same routes from the mobile as from the desktop? Any chance you missed to add this middleware to the routes used by the mobile?

zidance's avatar

I am using same route, but it cannot access if i am deploying using mobile. It works fine with web responsive view. It happens to all middleware setting. All the variable from View::share not working.

zidance's avatar

Solved. Authentication issue. *facepalm

Please or to participate in this conversation.