Laravel: how to use my composer installed bundle? - php

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?

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:
https://github.com/jenssegers/Laravel-Agent

Related

How can I use a third party api in the vendors directory of symfony from my controller

I am working with an existing controller in symfony and need to use an api that I have in my vendors directory. Needless to say I am entering a pre-existent, large scale project and with minimum experience in symfony I am not too sure of how to use the vendor directory. When I have tried using "use vendor\fullcontact\sdk*********;" symfony tells me that there is no class called this in my bundle. I have looked for information on using the vendor directory but have came up dry. Any information regarding how I can start using my vendor directory would be appreciated.
Seems you are using the PHP Library for FullContact API.
This library don't use namespace so you can simply try to use it adding an initial slash to the class when you are using it. As Example:
$this->name = new \Services_FullContact_Name($apikey);
Hope this help

Where to Place My Package in Lumen Framework

If I want to use some custom class in Lumen, where should I place them? The Laravel official document does not mention this in any of application structure, service container or package development. Actually I found the document quite confusing to some extents.
For example, I want to set up a service called Invitation, I know I need to register this class in InvitationServiceProvider but where should I place the Invitation.php which the actual class exists in? This package is used for some specific application thus I do not want to put it in composer packagist.
BTW, the version of Lumen Framework is 5.2.
So finally I created a folder named Service under app and just pull all the libraries inside...

Using node modules in Laravel

I am trying to include this module: https://www.npmjs.com/package/react-datepicker-component with react into my Laravel Framework.
I went on to using npm to install it but I am getting no where after that.
I could use some direction. Has anyone tried using NPM for Laravel other than for Laravel Elixir?
I was stuck with this same issue for about an hour trying to pull in the inputmask node package.
The only way I was able to get it included was by attaching it to the window object in app.js (similar to what bootstrap.js does)
window.InputMask = require('inputmask');
If you don't want to load it every time (as it would with app.js) you can create a separate js file that contains only the line of code above and load that on select pages. I feel like there has to be a better way, but this is the only way I've found to make it work.

Laravel 5 and Quickbooks

I'm trying to integrate the Quickbooks Online API into Laravel 5. I've got the code working outside of Laravel using the Consolibyte package. But its written in what I'll call a classic PHP style - meaning there are a number of REQUIRE_ONCE files etc. I'm sure I can crank through and integrate it all, but in the interest of saving time, I'm wondering if anyone else knows of a package for Laravel 5 which already does this?
Ultimately I need to be able to create Customers, Vendors and Invoices. Don't really need the rest of the functionality that the Consolibyte package uses (which is a great package by the way).
If you're using this code:
https://github.com/consolibyte/quickbooks-php
You only need to require one file. There's no real work required to get this working in Laravel. Just do this in your Laravel app:
require_once './QuickBooks.php';
And you're done.
For anyone else looking to solve this problem, this obscure blog post will save your life. It's a lot to post here, but he essentially uses the consolibyte/quickbooks-php, but wraps it up in creamy Laravel goodness so you can see the "under the hood" objects you need to set up so that you don't break the framework.
I followed the instructions, with some alterations for my app, and it authorized first try (Laravel 5.2).
It's not perfect, but it's as clean as you can get for Laravel right now.
Major props to both the article writer Pawan and the package author Keith Palmer Jr!
You can use this one instead its fully enabled to be installed by composer in Laravel or Yii2. I installed it in Yii2.
https://github.com/beanworks/quickbooks-online-v3-sdk install quickbooks from this url and then use the below url to implement oauth
https://github.com/IntuitDeveloper/oauth-php
You can easily make routes for oauth steps involved and there are samples in the later repo which can be used to learn how to post and query objects from quickbook.

Generating nested resource with same directory structure in laravel 4

Sorry if I am asking a silly question here, but I have googled it a lot and couldn't find any satisfactory answer.
I have some experience with codeigniter and I am new to laravel.
I have just installed laravel and jeffrey way generator tool. I am first working on my back-end admin panel, so what I need is to create nested resources so it will map to domain.com/admin/SomeController
But while using php artisan generate:resource country --fields="name:string, status:boolean"
It is working fine. but generating controllers, models, views etc in respective root directory and controller name should also be changed to support nested controllers
I want to create all these in some meaningful directory structure
App/controllers/admin/AdminCountryController.php
App/models/admin/Country.php
App/views/admin/country/index.blade.php etc.
I also checked generator tool documentation but couldn't find these details.
So I want to know how can it be achieved using generator or I have to do it manually.
If I chosen wrong path please tell me as I am at very initial phase of my project and my application structure will depend on it.
You need to create first that directory. For example, you want a controller app/controller/admin/AdminController.php, first create the admin folder on app/controller, then you can do php artisan generate:controller admin/adminController.php.
I am not sure if this coulde be done using Resouce.
Also routing in laravel is different with routing in CI. CI depends on domain.com/controllerClass/method/args and laravel is different.

Categories