How to get user agent in Laravel

In Laravel 5, you can get useragent( ex: chrome browser, firefox browser, explorer browser) easily without using $_SERVER variable.

Photo by ROBIN WORRALL on Unsplash

Let’s get start to have a simple example.

public function getUserAgent(Request $request)
$data['useragent'] = $request->server('HTTP_USER_AGENT');



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Patrick Wan

Patrick Wan

My name’s Patrick. I’m a Software Developer, experience in Laravel, Vue Js, React Js, Livewire, Jquery, Codegniter, NPM, GIT. I have 5 years plus experience.