Hot to use emcconville/google-map-polyline-encoding-tool in laravel - laravel

Hi i have installed emcconville/google-map-polyline-encoding-tool in Laravel, with composer, but cant see any references to the extension when i try yo use it in a class.
Do i need to register the extension anywhere in Laravel?

You don't need to register the package as an extension, the class Polyline coming from the package is automatically loaded with PHP/Composer autoload mechanism, so you can use it directly in your code (as per docs):
$points = array(
array(41.89084,-87.62386),
array(41.89086,-87.62279),
array(41.89028,-87.62277),
array(41.89028,-87.62385),
array(41.89084,-87.62386)
);
$encoded = \Polyline::encode($points);

Related

How to change Laravel Jetstream components path

I wanna change default Jetstream components after publishing views (php artisan vendor:publish --tag=jetstream-views) from resources/views/vendor/jetstream/components for example to resources/views/path/to/jet/comps
You can do this by copying the components from laravel/jetstream and putting them wherever you like within your app.
Then you need to alias the jetstream class with your own version.
What I did was copy all components from
/vendor/laravel/jetstream/src/Http/livewire/
Copied them to
/app/Http/Livewire/
Then open your app/Providers/JetstreamSrviceProvider.php or if you would prefer you can create your own service provider or use AppServiceProvider.php.
Add the following before the class definition but after the namespace definition:
use Illuminate\Foundation\AliasLoader;
Then in the register method add this:
$loader = AliasLoader::getInstance();
$loader->alias('Laravel\Jetstream\Http\Livewire\ApiTokenManager', 'App\Http\Livewire\ApiTokenManager');
$loader->alias('Laravel\Jetstream\Http\Livewire\CreateTeamForm', 'App\Http\Livewire\CreateTeamForm');
$loader->alias('Laravel\Jetstream\Http\Livewire\DeleteTeamForm', 'App\Http\Livewire\DeleteTeamForm');
$loader->alias('Laravel\Jetstream\Http\Livewire\DeleteUserForm', 'App\Http\Livewire\DeleteUserForm');
$loader->alias('Laravel\Jetstream\Http\Livewire\LogoutOtherBrowserSessionsForm', 'App\Http\Livewire\LogoutOtherBrowserSessionsForm');
$loader->alias('Laravel\Jetstream\Http\Livewire\NavigationDropdown', 'App\Http\Livewire\NavigationDropdown');
$loader->alias('Laravel\Jetstream\Http\Livewire\TeamMemberManager', 'App\Http\Livewire\TeamMemberManager');
$loader->alias('Laravel\Jetstream\Http\Livewire\TwoFactorAuthenticationForm', 'App\Http\Livewire\TwoFactorAuthenticationForm');
$loader->alias('Laravel\Jetstream\Http\Livewire\UpdatePasswordForm', 'App\Http\Livewire\UpdatePasswordForm');
$loader->alias('Laravel\Jetstream\Http\Livewire\UpdateProfileInformationForm', 'App\Http\Livewire\UpdateProfileInformationForm');
$loader->alias('Laravel\Jetstream\Http\Livewire\UpdateTeamNameForm', 'App\Http\Livewire\UpdateTeamNameForm');
Then run
composer dump-autoload
You can then open your version of the components and modify the view paths if you prefer or whatever else it is you were looking to do.
I have built a CMS as a package and done exactly this from a package which works well and means we can ship the package with our own views and updated components.

Integrate CHARGEBEE library to LARAVEL

Im starting using LARAVEL last version 7.12 and I'm having an issue trying to integrate CHARGEBEE library to make request to Chargebee api.
I was reading that I can install packages with composer, I did it:
composer require chargebee/chargebee-php:'>=2, <3'
Doing that now I have downloaded chargebee lib here: /vendor/chargebee/chargebee-php/
Now also I saw This stack overflow question here:
That for the user to correctly use this Library-Package I need to create a ServiceProvider so I did:
php artisan make:provider ChargeBeeServiceProvider
then I really don't know how to write the REGISTER() function here, I added also this line: App\Providers\ChargebeeServiceProvider::class, to /config/app.php to 'providers'
ChargebeeServiceProvider
Right now I have a controller: /app/http/controllers/PortalController and I'm trying to use this:
ChargeBee_Environment::configure("sitename","apikeyvalue");
$all = ChargeBee_Customer::all(array( "firstName[is]" => "John",
"lastName[is]" => "Doe", "email[is]" => "john#test.com" ));
foreach($all as $entry){
$customer = $entry->customer();
$card = $entry->card();
}
PortalController
BUT on the frontend it's giving me an error:
Error Class 'App\Http\Controllers\ChargeBee_Customer' not found
Not really sure how i can use this custom Chargebee library here on Laravel.
can somebody please help to integrate in the correct way ?
Thanks!
The real problem here is that ChargeBee_Environment class doesn't exists.
It should be Chargebee\ChargeBee\Environment. And the Models are in their own folder, for example the Portal is ChargeBee\ChargeBee\Models\PortalSession
WPTC-Troop's answer provides some great information on the issue of using a service provider vs library directly, but in the end you need to call the correct classes.
My working code for creating a portal session is below. It would be similar for a Customer object:
\ChargeBee\ChargeBee\Environment::configure("test-site","test_api_key");
$result = \ChargeBee\ChargeBee\Models\PortalSession::create(["customer" => ["id" => "AzZlwTSSVw9871E9g"]]);
$portalSession = $result->portalSession();
$output = $portalSession->getValues();
return $output;
Two things, you can use any third party library as Service Provider(DI) in Laravel or use it directly where ever you needed(mostly in controller)
Not just third party library you can ease the instance creation of class etc in Service Provider. Basically it's for dependency injection, Check IoC in general you'll understand it better.
You tried/mixed both in your case and didn't completely use any single approach.
You've created a Service Provider called ChargeBeeServiceProvider but it doesn't return/bind any resource or no API initialization done in register method. This is where you register and make use of DI. You can bind in properties as well. Here is the official doc to it.
You tried to use directly by initializing ChargeBee_Environment and use ChargeBee_Customer but you didn't mention where to look for this class that is the reason you get the error(Error Class 'App\Http\Controllers\ChargeBee_Customer' not found). I mean compiler will look for ChargeBee_Environment from the same local space but ChargeBee_Environment is available from global scope.
Simple solution to your same code. Add \ to the class to look from global scope or make use of use statement in the top of your file similar to import in java but still we need to require/include the file in php but don't worry, chargebee make use of autoloader(Check here -> composer.json) so it will be loaded automatically in both approach.
\ChargeBee_Environment::configure("sitename","apikeyvalue");
$all = \ChargeBee_Customer::all(array( "firstName[is]" => "John",
"lastName[is]" => "Doe", "email[is]" => "john#test.com" ));
Try the above and let me know. Answered from mobile device. Code is not tested fully(Just copied your and added \ to it).
Excuse brevity :)
I have a solution to use ChargeBee and Laravel. Don't need any: register provider, add to aliases or add path to autoload in composer.json by file path. Just add in use classes that you need in code your Service or your Controller. Like use ChargeBee_Environment and other.
use ChargeBee_Environment;
use ChargeBee_Customer;
ChargeBee_Environment::configure("sitename","apikeyvalue");
$all = ChargeBee_Customer::all(array( "firstName[is]" => "John", "lastName[is]" => "Doe", "email[is]" => "john#test.com" ));
foreach($all as $entry){
$customer = $entry->customer();
$card = $entry->card();
}

OctoberCMS and BotMan

I want to integrate a chatbot (BotMan version 2.0) into an existing OctoberCMS project , here is what I did till now :
1- I added BotMan to the projct using the following command :
composer require botman/botman
2- I created a routes.php file in the same directory as the plugin.php file
<?php
use BotMan\BotMan\BotMan;
use BotMan\BotMan\BotManFactory;
use BotMan\BotMan\Drivers\DriverManager;
//Route::match(['get', 'post'], '/botman', 'BotManController#handle');
//Route::get('/botman/tinker', 'October\Demo\BotManController#tinker');
// Create an instance
$botman = BotManFactory::create($config);
// Give the bot something to listen for.
$botman->hears('hello', function (BotMan $bot) {
$bot->reply('Hello yourself.');
});
// Start listening
$botman->listen();
My questions are :
1- Where I have to add the BotManController.php file
2- I tried to add BotManController.php in the same directory as the routes.php file but I get the following error :
Class 'App\Http\Controllers\Controller' not found
( and thats because its an OctoberCMS project not Laravel project ... I dont have the App directory )
Can anyone please provide me a solution to that or another way to integrate Botman into OctoberCMS !
First off, read https://luketowers.ca/blog/how-to-use-laravel-packages-in-october-cms-plugins/ as well as https://octobercms.com/docs/plugin/composer.
Secondly, you can put the BotManController file anywhere in your plugin you want as long as you understand PHP namespaces and how to properly reference it where you want to. I would probably recommend putting it in a /classes/ directory under your plugin folder, and then changing the App\Http\Controllers\Controller reference to instead reference the base Illuminate\Routing\Controller class. You could also put it in a /controllers/ directory, but in OctoberCMS that is typically reserved for your backend controllers so I wouldn't recommend mixing the two.

How to get PhpStorm to autocomplete facades in blade-files

When using #if (Auth::check()), PhpStorm doesn't recognize the Auth.
How do I tell PhpStorm that Auth is \Illuminate\Support\Facades\Auth?
Tested:
#php
use Illuminate\Support\Facades\Auth;
/** #var \Illuminate\Support\Facades\Auth Auth */
class Auth extends \Illuminate\Support\Facades\Auth {}
#endphp
#use(\Illuminate\Support\Facades\Auth)
neither worked, still get "Undefined Class Auth"
Edit 1:
the class Auth extends \Illuminate\Support\Facades\Auth {} line works if it's in another file, for example, the "_ide_helper.php", having it inside the blade file doesn't work.
IDE won't recognize methods accessed via the facade. laravel-ide-helper is a popular package that solves this problem. It generates a custom helper file that the IDE understands. This is not a complete solution but it covers most of laravel classes and helps with autocompletion. Here are your options.
Download and drop the latest _ide_helper.php file for laravel into your project from https://gist.github.com/barryvdh/5227822
Install the laravel-ide-helper package and let it generate a helper file on the fly. https://github.com/barryvdh/laravel-ide-helper
I'd personally suggest installing the package.
To get the right class use #if (\Auth::check())!

location of helper function in Laravel 5

I am using Laravel 5 and new in this Platform. I studied about URL:asset In the earlier version of PHP, we could find the helper function in Auto Load or config files.
Do the helper function list exists somewhere in the Framework directory where if we want to change something in the helper function according to our need.
The helper functions are present in
/vendor/laravel/framework/source/illuminate/Foundation/helpers.php
You can find your helper function inside app.php as facades are registered on app.php and service container would let you resolve the class anywhere you want by use shorthandname or registered name;

Resources