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

diazfarindra's avatar

Get Screen Size from JS and Pass it to Laravel

i need to get screen size value from Javascript for conditinally render in my controller, how do I perform this?

I have used cookie, session, and middleware but am still confused about how to perform it

0 likes
3 replies
Sinnbeck's avatar

You would need to send an ajax request and then perform the actions in Javascript. Or have a form that the user is forced to submit to send in their data (you can get the data using Javascript)

There is no way of knowing the screen size before rendering

Normally you would use css media queries to change the look

1 like
jlrdw's avatar

Or mobile detect. I've used a combination of media queries and mobile detect.

1 like

Please or to participate in this conversation.