How to setup autoload for Laravel 4 package - laravel

I have a new Laravel 4 app and am trying to add the laravel-oauth2 vendor package.
I ran
composer require taylorotwell/laravel-oauth2
composer dump-autoload
successfully. But I get Class 'OAuth2' not found
Advice much appreciated.

The standard method of adding packages to the Laravel 4 framework would be:
add a line to the "require" section of the main composer.json file, e.g.
"taylorotwell/laravel-oauth2": "0.2.*"
run "composer update"
This will download the package and refresh the autoload classes. I just did a test and it seems to work ok, remember to use the namespace:
$provider = \OAuth2\OAuth2::provider('facebook', array(
'id' => 'client id',
'secret' => 'client secret',
));
or
use OAuth2\OAuth2;
$provider = OAuth2::provider('facebook', array(
'id' => 'client id',
'secret' => 'client secret',
));

Related

How to configure Laravel to use PhpRedis?

PHP 7.3
Laravel 5.8
Until now I was using Predis for my cache in the Laravel project. Now I want to switch to PhpRedis. I've read it's really simple (just config changes), but I have a lot of problems. I don't know what to begin with, so I'll write all what I know.
My hosting provider claims that PhpRedis is enabled.
The code below executed in a controller (Predis is set) works fine - I receive the set value.
$redis = new \Redis();
$redis->connect( 'socket path', 0 );
$redis->set('test', 'testValue');
print_r( $redis->get('test') );
However, the same code in the raw PHP file executed via SSH returns "Uncaught Error: Class 'Redis' not found in..."
Let's go to changes in config/database.php. Here is my configuration:
'redis' => [
'client' => env('REDIS_CLIENT', 'predis'/*'phpredis'*/),
'cluster' => true,
'options' => [
'cluster' => env('REDIS_CLUSTER', 'predis'/*'redis'*/),
'prefix' => Str::slug(env('APP_NAME'), '_').'_',
'parameters' => ['password' => env('REDIS_PASSWORD', null)],
],
'default' => [
'scheme' => 'unix',
'path' => env('REDIS_HOST'),
'host' => env('REDIS_HOST'),
'password' => env('REDIS_PASSWORD'),
'port' => env('REDIS_PORT'),
'database' => env('REDIS_CACHE_DB', 0)
],
(...) // other
],
When I change values to these in comments, my website shows just a blank page - any errors in the mailbox.
Furthermore, when I run for example "php73 artisan config:clear" in the SSH, console returns "Please remove or rename the Redis facade alias in your "app" configuration file in order to avoid collision with the PHP Redis extension." in the Illuminate/Redis/Connectors/PhpRedisConnector.php.
When I change the alias in config/app.php from "Redis" to "RedisManager" and try again it returns
Uncaught Error: Class 'Redis' not found in /path/vendor/laravel/framework/src/Illuminate/Redis/Connectors/PhpRedisConnector.php:70.
What's going on? How to set Laravel's configuration to use PhpRedis? Maybe it's my hosting provider issue? Thanks in advance for every advice.
If I missed some important code, give me a sign - I will add it.
The PHPRedis libraries are not installed by default in a shared hosting environment, and are generally not part of a PHP installation by default. You would have to ask your host to install these libraries within their shared hosting platform.

Reflection Exception in laravel vanilo.io

Everything was working fine until I added Vanilo to my laravel project, I have no idea on how to debug this kindly help.
Laravel Version: 5.5.40
Snippet from app.php
/*
* Third Party Aliases
*/
'Active' => HieuLe\Active\Facades\Active::class,
'Breadcrumbs' => DaveJamesMiller\Breadcrumbs\Facade::class,
'Captcha' => Arcanedev\NoCaptcha\Facades\NoCaptcha::class,
'Form' => Collective\Html\FormFacade::class,
'Fractal' => Spatie\Fractal\FractalFacade::class,
'Gravatar' => Creativeorange\Gravatar\Facades\Gravatar::class,
'Html' => Collective\Html\HtmlFacade::class,
'Socialite' => Laravel\Socialite\Facades\Socialite::class,
'Image' => Intervention\Image\Facades\Image::class,
'Helper' => App\Helpers\Helper::class,
'Agent' => Jenssegers\Agent\Facades\Agent::class,
'Concord' => Konekt\Concord\Facades\Concord::class,
'Helper' => Konekt\Concord\Facades\Helper::class,
even if remove the last helper i still get the error.
hit these commands
php artisan config:clear
composer dump-autoload

Send Mail Using Lumen

Mail.php
return [
'driver' =>'smtp',
'host' => 'smtp.gmail.com',
//'port' => 587,
'port' =>465,
//'encryption' =>'tls',
'encryption' =>'ssl',
'username' => 'xxxxxxxx#gmail.com',
'password' => 'xxxxxxx',
// 'sendmail' => '/usr/sbin/sendmail -bs',
'sendmail' => '/usr/sbin/sendmail -t',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
Controller
$data = []; // Empty array
Mail::send('email.credentials', $data, function($message)
{
$message->to('xxxxxx#gmail.com', 'Jon Doe')->subject('Welcome!');
});
Error
Swift_TransportException Connection could not be established with host
smtp.gmail.com [A connection attempt failed because the connected
party did not properly respond after a period of time, or established
connection failed because connected host has failed to respond.
I Tried...
Change ssl / tls
Change the ports
Add "guzzlehttp/guzzle": "~5.3|~6.0" in composer.json
Add a new line in StreamBuffer.php
$options = array_merge($options, array('ssl' => array('verify_peer' =>
false,'verify_peer_name' => false,'allow_self_signed' => true )));
Please help .
Thank you.
1. Require illuminate/mail
Make sure you’re using the same version as your underlying framework (i.e. if you’re on Lumen v. 5.3, use composer require illuminate/mail "5.3.*").
composer require illuminate/mail "5.5.*"
2. Set up Lumen bootstrap/app.php
First, open your bootstrap.php and uncomment the following lines:
$app->withFacades();
$app->register(App\Providers\AppServiceProvider::class);
Also, add the following line below the last line you uncommented:
$app->configure('services');
This will allow you to define a ‘services’ config file and setup your mail service. Now I know that normally configuration is done in the .env file with Lumen, and we’ll use that shortly, but first we’ll need to write a small config file to map to the .env file.
3. Create your configuration files
Create a new folder at the root level of your install called config(if it doesn’t already exist). In the config folder, create two new files, one named services.php and another named **mail.php**.
In the services.php file paste the following:
<?php
return [
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
],
];
Lastly, add the following to your .env file:
MAIL_DRIVER=mailgun
MAILGUN_DOMAIN=<your-mailgun-domain>
MAILGUN_SECRET=<your-mailgun-api-key>
Make sure you replace those sneaky placeholders with your actual key and domain. If you’re not using Mailgun, you can always use the other mail providers Mail comes with; have a look at the docs if you plan on using a different provider, they are all easy to set up once you’re at this point.
4. Send Email!
To send an email, use one of the following in your classes (depending on your preference):
use Illuminate\Support\Facades\Mail;
$data = []; // Empty array
Mail::send('email.credentials', $data, function($message)
{
$message->to('xxxxxx#gmail.com', 'Jon Doe')->subject('Welcome!');
});
Finally, don’t forget to read the Laravel Mail docs for more info on how to use this great library.
Have you turned on 2 layers security in your Google account (email address you config in .env file) which uses to send email.

Using require-dev with composer and laravel

I was using require-dev for my development tools dependencies. Like the laravel debugbar, the barryvdh ide-helper, etc...
When i get to my production server and run "composer update --no-dev --no-scripts" everything seems to be OK.
Then, you realize that you must remove your "dev providers" from the app.php array.
So whats the point of using require-dev? there isnt a "providers-dev" array?
UPDATE:
I was that i get it fixed but it's not working.
I create the file app/config/local/app.php with this:
<?php
return array(
'providers' => append_config(array(
'Barryvdh\Debugbar\ServiceProvider',
'Way\Generators\GeneratorsServiceProvider',
'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider',
'Barryvdh\Debugbar\ServiceProvider',
))
);
and on the top of app/start/global.php
$env = $app->detectEnvironment(function(){
$hosts = array(
'localhost' => 'local',
'127.0.0.1' => 'local',
);
if(isset($hosts[$_SERVER['SERVER_NAME']])){
return $hosts[$_SERVER['SERVER_NAME']];
}
});
I tried echoing the $env variable and it returns 'local' so it's working. When i open my site i can't see the debugbar but everything else is working.
Any tip?
Just add your dev providers to app/config/local/app.php and use append_config:
'providers' => append_config(array(
'Barryvdh\Debugbar\ServiceProvider',
))

Using Eloquent ORM from Laravel 4 outside of Laravel

I created a folder 'eloquent' to start testing/learning the component, and my composer.json file is:
{
"require": {
"php": ">=5.3.0",
"illuminate/database": "4.0.*"
}
}
Below is my test.php file, with credentials removed. It works great, until I add ->remember(10) into the command. I'd like to look into adding the Illuminate Cache next then, if that's what's needed to start using ->remember(). Is anyone aware of any blog posts or tutorials on doing something like this?
<?php
/**
* Testing Laravel's Eloquent ORM
* #see https://github.com/illuminate/database
* #see http://laravel.com/docs/database
*/
require 'vendor/autoload.php';
use Illuminate\Database\Capsule\Manager as Capsule;
$capsule = new Capsule;
$capsule->addConnection(array(
'driver' => '',
'host' => '',
'database' => '',
'username' => '',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
));
//$capsule->bootEloquent();
$capsule->setAsGlobal();
$name = Capsule::table('user')->where('id', 123 )->remember(10)->get();
var_dump( $name );
// PHP Fatal error: Uncaught exception 'ReflectionException' with message 'Class cache does not exist'
I'm not sure what the next step is to get ->remember() working. I tried adding illuminate/cache to the composer.json file and updated. I wasn't sure how to use it with Eloquent, outside of Laravel.
saff33r is right, but just to help someone like me that need "file" cache this is how to:
in your composer.json
"illuminate/cache": "4.0.*",
"illuminate/filesystem": "4.0.*",
in your boot file:
use \Illuminate\Database\Capsule\Manager as Capsule;
use \Illuminate\Cache\CacheManager as CacheManager;
use \Illuminate\Filesystem\Filesystem as Filesystem;
...
$container = $capsule->getContainer();
$container['config']['cache.driver'] = 'file';
$container['config']['cache.path'] = __DIR__ . '/uploads/cache/eloquent';
$container['config']['cache.connection'] = null;
$container['files'] = new Filesystem();
$cacheManager = new CacheManager($container);
$capsule->setCacheManager($cacheManager);
$capsule->bootEloquent();
It should already be pulling in "illuminate/cache", look in vendor and you should see it there.
You need to setup the cache manager, then pass that through by calling
$capsule->setCacheManager(CacheManager $cache);
I've not looked under the hood for details on how to do this but hopefully this will be enough details to get you going forward.
Edit:
Here's what you need to add to get it working:
use Illuminate\Cache\CacheManager as CacheManager;
$container = $capsule->getContainer();
$container->offsetGet('config')->offsetSet('cache.driver', 'array');
$cacheManager = new CacheManager($container);
$capsule->setCacheManager($cacheManager);
Obviously feel free to change the Cache Driver used but keep in mind that changing the Cache Driver will require adding the extra required settings.
Check out https://github.com/Luracast/Laravel-Database it provides full eloquent support outside laravel including artisan migrations and more
4.2 branch contains laravel 4.2.* components
5.2 branch contains laravel 5.2.* components
Disclosure: I'm the author of the above repository

Resources