Git Product home page Git Product logo

laravel-mobile-detect's Introduction

Laravel Mobile Detect

A package that enables you to use device detection right in your Blade templates. (Utilises the well-known, constantly updated PHP mobile detection library.)

When would you use this package?

Responsive CSS may help to make content in the browser look nice on different devices but it won't help you serve responsive content from your backend (at least not the easy way). This can have a really bad knock-on effect on the user experience (have you ever waited for a large image to load while having a bad connection on your mobile?). This package will make it a breeze to serve device-specific content right from your back-end.

How does this package work?

The package implements various Blade directives that you can use to serve different content from your Blade template for different device types.

Installation

Install the package through composer:

$ composer require riverskies/laravel-mobile-detect

Laravel 5.4 or earlier

Add the service provider to your config/app.php file:

Riverskies\Laravel\MobileDetect\MobileDetectServiceProvider::class

Optionally, you can add an alias as well if you'd like to use the underlying instance anywhere else (or have access to all the functions):

'MobileDetect' => Riverskies\Laravel\MobileDetect\Facades\MobileDetect::class

Usage

Use the new Blade directives in your template files:

@desktop
    <img src="/path/to/high-definition/image"/>
@elsedesktop
    <img src="/path/to/handheld-optimised/image"/>
@enddesktop

Available directives

@desktop, @elsedesktop, @enddesktop - for destkop devices

@handheld, @elsehandheld, @endhandheld - for non-desktop (mobile and tablet) devices

@tablet, @elsetablet, @endtablet - for tablet devices

@nottablet, @elsenottablet, @endnottablet - for non-tablet (desktop or mobile) devices

@mobile, @elsemobile, @endmobile - for mobile devices

@notmobile, @elsenotmobile, @endnotmobile - for non-mobile (desktop or tablet) devices

@ios, @elseios, @endios - for iOS platforms

@android, @elseandroid, @endandroid - for Android platforms

The usage of @else... directives are optional.

laravel-mobile-detect's People

Contributors

barnabaskecskes avatar emiliobravo avatar zyuzka avatar

Watchers

James Cloos avatar jaenudin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.