Laravel 5.3 Slack integration - php

I need to get access to Slack's Event API from my Laravel 5.3 application. I have installed vluzrmos's package from GitHub, but I can't get it to work properly. I ran through all the steps in the installation, but when I try to do SlackUser::lists() in my Controller I get an error like this:
Non-static method Vluzrmos\SlackApi\Contracts\SlackUser::lists() cannot be called statically, assuming $this from incompatible context.
Could you help? Thanks

Assuming you have configured the providers & aliases correctly (in config/app.php), you need to add:
use SlackUser;
to the top of your class, and then call:
SlackUser::lists();
Please post your usage of SlackUser::lists(); if this doesn't solve your issue.

Related

PHP: Override a service-provider that calls a method that's not in my Laravel?

I have an old website which was developed in Laravel 5.2 and which for various reasons can't be upgraded from that.
I have a vendor package which, in the boot() method of one ServiceProvider, has this line:
$this->loadMigrationsFrom($somewhere);
... but this method did not exist in Laravel 5.2.
What would be the cleanest way to override this errant method-call?
It occurs to me that I might just be able to write a new service-provider class to replace this one, since all it really seems to do is to register one console command. But is there a way to "override" it?
In this case I was able to bypass the problem by creating a new ServiceProvider and using it instead of the vendor's version in config/app.php.

setlocale and getlocale in lumen 5.6

I was trying to localize my application and in the middleware, I am getting the locale from the request object. Now I need to access this outside the controller while running a job.
As from the documentation, I can see that the app() can hold this data. But app()->setLocale() and app()->getLocale() is not working for me in lumen 5.6.
Ant help will be much appreciable.
Finally, I found the answer. There is a translator object in the framework and you have to use the following code to set a locale
app('translator')->setLocale($locale);
and to get a locale in anywhere in the application using
app('translator')->getLocale();

Facade Error - Non-static method should not be called statically

I want to create an shopify app with laravel.I am using the package https://packagist.org/packages/bnmetrics/laravel-shopify-api
I have followed all the steps shown there.But after running this app I am getting this error
Non-static method BNMetrics\Shopify\Shopify::make() should not be called statically
I have already registered service provider and add shopify facade as instructed.But the issue exist.Is there anything I am missing?
I am newbie to laravel and sorry for my bad English.
I know this is an old post, but I had the same problem and I realized that I was importing
use BNMetrics\Shopify\Shopify;
and I just needed to import
use Shopify;
just in case it helps someone else

Using Laravel Facades with UserFrosting

Have recently starting using UserFrosting to as part of a project and I'm having some problems using Facades within UserFrosting and would appreciate some help if possible.
I am attempting to use the File facade from within a UserFrosting controller to create a folder on the local filesystem using the following code
use Illuminate\Support\Facades\File;
......
$directoryCreated = File::makeDirectory($directoryPath);
However at runtime i get the following error
PHP Fatal error: Call to a member function makeDirectory() on null in /var/www/test-app/userfrosting/vendor/illuminate/support/Facades/Facade.php on line 210
It seems that the UserFrosting app does not recognise the File facade (or any other facacde - i also tried Storage) and it has not been registered with the app.
Is it possible to use the facade classes with UserFrosting?
If so do I have to register them somewhere within the UserFrosting app config?
Any direction pointers would be greatly appreciated.
Thanks in advance!
From the Facade documentation:
Laravel "facades" serve as "static proxies" to underlying classes in the service container...
So, it looks like Laravel's facades depend on Laravel's service container. You can read more about how Laravel sets up the default facades here: https://www.sitepoint.com/how-laravel-facades-work-and-how-to-use-them-elsewhere/#how-laravel-aliases-the-facades
Unfortunately, UserFrosting does not use Laravel's service container. Rather, it uses Slim, which has its own service container. In Slim v2 (which UF 0.3.1 uses), the Slim application itself is the service container.
You can define services for UF in initialize.php. So, you might try something like:
$app->filesystem = new \Illuminate\Filesystem\Filesystem();
Then later, you can use the filesystem service like:
$app->filesystem->makeDirectory($directoryPath);
You could try to use Slim's container to allow the Facade to resolve its accessor (it will use array access on the container to resolve it). You would have to make sure that the binding the facade uses exists. You can take a look at the Service Provider that corresponds to the service you want to use to know how its setting up the binding.
The File facade is accessing the binding 'files' (Illuminate\Filesystem\Filesystem).
\Illuminate\Support\Facades\Facade::setFacadeApplication($container);
\Illuminate\Support\Facades\File::makeDirectory(...);
Its worth a shot, but its mostly the binding that is being resolved that is important.

Problems wit sign me up plugin

Hi i am trying to use Sign me up Plugin for my application. But unable to get it running. There are so many issues and errors.
Plugin i have downloaded is:-
sign_me_up-2.0
But there are so many errors i am getting
Ex:- Declaration of SignMeUpComponent::initialize() should be compatible with Component::initialize(Controller $controller)
I have tried for tutorials and serached for solutions online. But no luck...
Can anyone help me out on how to use this plugin ???
What i reffered :-
http://www.jotlab.com/2011/sign-me-up-a-cakephp-registration-plugin
Thanks in advance
Make sure your version of CakePHP is compatible with the plugin. I understand between version 1.3 and 2, they took advantage of the newer features of PHP which included strongly-typed method parameters. The error you're receiving is that the SignMeUpComponent inherits from the Component class which is in framework core. If the component wants to override the initialize method, it must follow the same method/function signature.
If the plugin is on Git and you feel comfortable in doing so, clone it and update all the components methods, and then put in a pull request so you're changes can be merged in.
Alternatively use an earlier version of CakePHP.

Categories