Switching Brains
Switching Brains

Reputation: 290

Laravel: how to use my composer installed bundle?

I am learning Laravel. With composer i included the mobile-detect-bundle in the installation (files are in the folders). When i use the code as stated in the docs on github

$mobileDetector = $this->get('mobile_detect.mobile_detector');

i get this error:

**ErrorException**

File does not exist at path mobile_detect.mobile_detector (View: ) (View: )

I use this in my blade view and i think i have to set the path of 'mobile_detect.mobile_detector' but i have no clue what it has to be. Maybe one can give me a push in the right direction?

Upvotes: 0

Views: 460

Answers (1)

mpj
mpj

Reputation: 5367

The reason it's not working is because you are trying to use a Symfony 2 bundle inside Laravel right out of the box.

As the github page says:

Symfony2 bundle for detect mobile devices, manage mobile view and redirect to the mobile and tablet version.

Basically, the line that you are trying to run is the way that you use services inside Symfony. It will work if you are in a Symfony application, but not inside Laravel.

// Get the mobile_detect.mobile_detector 
// service from Symfony's service container
$mobileDetector = $this->get('mobile_detect.mobile_detector');

Although there might be some way to make it work, I'd sugggest to search in packagist for a Laravel specific package, or a PHP generic one that provides the same functionality, to make your life easier.

I've made a search and found this one, which is based in Mobile Detect too:

Upvotes: 1

Related Questions