Issue with laravel 5.8 and mongodb 4.2 connection - laravel

My system has 2 xampp's one with PHP 5.6 and the other with PHP 7.3. I have correctly included both the PHP versions in environment variables. I am trying to connect my laravel v5.8 application with mongodb v4.2.
I have used jenssegers/mongodb package in my application. Also I have added MongodbServiceProvider in app.php. I am using Robo 3T for mongodb GUI. Now whenever I try to post data to mongodb collection then I get a authentication failed error.N= Below are the codes that I have used in my application.
Database.php(Config folder)
'mongodb' => [
'driver' => 'mongodb',
'host' => env('MONGO_DB_HOST', 'localhost'),
'port' => env('MONGO_DB_PORT', 27017),
'database' => env('MONGO_DB_DATABASE'),
'username' => env('MONGO_DB_USERNAME'),
'password' => env('MONGO_DB_PASSWORD'),
'options' => []
],
Todo.php(Model)
namespace App;
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
class Todo extends Eloquent
{
protected $connection = 'mongodb';
protected $collection = 'todo';
protected $fillable = [
'title', 'desc'
];
}
.env file
MONGO_DB_HOST=127.0.0.1
MONGO_DB_PORT=27017
MONGO_DB_DATABASE=mongocrud
MONGO_DB_USERNAME=
MONGO_DB_PASSWORD=
Overview of Error message:
(1/1) AuthenticationException
Authentication failed.
in Find.php line 299
at Server->executeQuery('mongocrud.todo', object(Query), array('readPreference' => object(ReadPreference)))
in Find.php line 299
at Find->execute(object(Server))
in Collection.php line 624
at Collection->find(array(), array('typeMap' => array('root' => 'array', 'document' => 'array'), 'readPreference' => object(ReadPreference), 'readConcern' => object(ReadConcern)))

First delete vendor folder & replace below 2 line in composer.json:
"jenssegers/mongodb": "^3.5",
"laravel/framework": "5.8.*",
to
"jenssegers/mongodb": "^3.5",
"laravel/framework": "5.7.*",
& update composer
after update the composer clear the config cache.

Make sure you have the MongoDB PHP driver installed. You can find installation instructions at http://php.net/manual/en/mongodb.installation.php

Related

Routes missing for Laravel Backpack admin

We have several Laravel applications that use Backpack for the admin panel. A developer wrote a package that used Single sign-on. We have removed this package as it was not working correctly. Once Composer was used to updating Laravel and remove the package, there are NO routes to deal with admin login. Our applications use Laravel 5.8/6 and Backpack 3.6/4.0.
I created another test application with Laravel 5.8 using Backpack 3.6, and the routes are available for login. As you can see, all the login routes are available.
If you look at the following image, you can see the login routes are all missing.
Is there a way to add the routes in again? Laravel Backpack is still installed, but I need to re-register the routes.
All the settings in the application are set to default. I have even made the default authentication guard in config/auth.php to Backpack.
config/auth.php
'defaults' => [
'guard' => 'backpack',
'passwords' => 'users',
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
],
config/backpack/base.php
'route_prefix' => 'admin',
'setup_auth_routes' => false,
'setup_dashboard_routes' => true,
'setup_my_account_routes' => true,
'user_model_fqn' => App\Models\BackpackUser::class,
'middleware_class' => [
App\Http\Middleware\CheckIfAdmin::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
// \Backpack\Base\app\Http\Middleware\UseBackpackAuthGuardInsteadOfDefaultAuthGuard::class,
],
// Alias for that middleware
'middleware_key' => 'admin',
'authentication_column' => 'email',
'authentication_column_name' => 'Email',
'guard' => 'backpack',
'passwords' => 'backpack',
config/backpack/permissionmanager.php
'models' => [
'user' => App\Models\BackpackUser::class,
'permission' => Backpack\PermissionManager\app\Models\Permission::class,
'role' => Backpack\PermissionManager\app\Models\Role::class,
],
'allow_permission_create' => false,
'allow_permission_update' => false,
'allow_permission_delete' => false,
'allow_role_create' => true,
'allow_role_update' => true,
'allow_role_delete' => true,
'multiple_guards' => true,
app/Models/BackpackUser.php
class BackpackUser extends User
{
use CrudTrait;
use HasRoles;
use InheritsRelationsFromParentModel;
protected $table = 'users';
public function sendPasswordResetNotification($token)
{
$this->notify(new ResetPasswordNotification($token));
}
public function getEmailForPasswordReset()
{
return $this->email;
}
}
So pretty much standard settings. I cannot figure out why the routes are not registered and available. If you get to http://localhost/admin, I get redirected to http://localhost/admin/login, which gives a 404 error. Can anyone help?
You have to enable 'setup_auth_routes' => true in config/base.php. This will allow Backpack to use the standard routes. Then the second step is to use Auth::routes(); inside your routes/web.php
If you are missing some/all of the controllers or UIs then you can scaffold them:
Install laravel/ui part using composer require laravel/ui
Use php artisan ui vue --auth or php artisan ui bootstrap --auth or php artisan ui react --auth depending on what you use for the front-end.

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

RuntimeException Could not scan for classes inside "database/factories" Laravel

i need to install Laravel charts in my project. after installing
composer require consoletvs/charts:6.*
I have this error :
[RuntimeException]
Could not scan for classes inside "database/factories" which does not appear
to be a file nor a folder
So after when i copy my provides and allias in App folder, i got :
Class 'ConsoleTVs\Charts\ChartsServiceProvider' not found
Anyone can help please ?
I've just had this error crop up. It was because I'd removed all of the files from the database/factories folder. The options to fix were either to add a stub factory file back into the folder. The UserFactory.php that comes with Laravel will do.
<?php
use Faker\Generator as Faker;
$factory->define(App\User::class, function (Faker $faker) {
return [
'name' => $faker->name,
'email' => $faker->unique()->safeEmail,
'email_verified_at' => now(),
'password' => '$2y$10$TKh8H1.PfQx37YgCzwiKb.KjNyWgaHb9cbcoQgdIVFlYg7B77UdFm', // secret
'remember_token' => str_random(10),
];
});
The alternative is to remove from composer.json
"classmap": [
"database/factories"
],
When a composer installation doesn't work right I check that composer itself is updated.
Run composer's self-update command
php composer.phar self-update

Eloquent 5.5 paginate() not working outside laravel

I am using Illuminate/database package outside Laravel with my CodeIgniter setup. The initialization is done using Capsule class like this
use Illuminate\Database\Capsule\Manager as CapsuleManager;
use Illuminate\Events\Dispatcher;
use Illuminate\Container\Container;
class Capsule extends CapsuleManager
{
public function __construct()
{
parent::__construct();
require_once __DIR__.'/../config/database.php';
$db = (object) $db['default'];
$this->addConnection(array(
'driver' => 'mysql',
'host' => $db->hostname,
'database' => $db->database,
'username' => $db->username,
'password' => $db->password,
'charset' => $db->char_set,
'collation' => $db->dbcollat,
'prefix' => $db->dbprefix,
));
$this->setEventDispatcher(new Dispatcher(new Container));
// Make this Capsule instance available globally via static methods... (optional)
$this->setAsGlobal();
// Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
$this->bootEloquent();
}
}
I had it running on illuminate/database 5.2. Recently I updated it to illuminate/database 5.5. My Eloquent paginate() has stopped working. The links() method on eloquent collection gives following error.
Call to a member function make() on null
With a stack trace to
return new HtmlString(static::viewFactory()->make($view ?: static::$defaultView, array_merge($data, [
in vendor\illuminate\pagination\LengthAwarePaginator.php on Line 90
Any help in this regard will be appreciated.

Resources