Ad

How To Get Client DOM Width In Laravel PHP

- 1 answer

I don't know if this is even possible, but I'd appreciate any help.

  • How do I get the client's DOM width in Laravel?
  • Basically, is there a way to extract the client's screen width from the $request?
  • Or are there any functions in Laravel or Blade that will give me a screen width value?

I know that I can get the DOM width with jQuery $(document).width(), but I need the width value on server side; before any js is executed.

Ad

Answer

@ArturGrigio You can try set JavaScript cookie and access it in Laravel. When user visits your website, get the screen size with JS (window.width) and store it in a cookie screen=WxH In Laravel $screen = Cookie::get('screen');

$screen = explode("x", $screen);
$width = $screen[0]
$height = $screen[0];

This is 1 solution to do it.

Unfortunately the is no way to get screen size info from PHP. You can try to play around with User Agent and detect if it is a mobile or desktop or tablet. and way to get screen size info from PHP. You can try to play around with User Agent and detect if it is a mobile or desktop or tablet. and make fix sizes for those 3 types.

A good User Agent package for Laravel

Ad
source: stackoverflow.com
Ad