0

I am using Eloquent for database calls with slim framework here is my composer.json

{
"require": {
    "slim/slim": "3.0",
    "illuminate/database": "^6.8",
    "monolog/monolog": "^2.0"
}

I want to use Hash::make() which is available in Illuminate\Support\Facades\Hash; but it gives this error

error test code :

<?php 
use Illuminate\Support\Facades\Hash;

require 'vendor/autoload.php';
require 'app.php';

$container = $app->getContainer();
//boot eloquent connection
$capsule = new Capsule;
$capsule->addConnection($container['settings']['db']);
$capsule->setAsGlobal();
$capsule->bootEloquent();

//pass the connection to global container (created in previous article)

$container['db'] = function ($container){
    return $capsule;
};

echo Hash::make('wonder');

I tried the composer update but it did not solve it.

how to solve this ? is there any solution for it ?

sdx11
  • 181
  • 1
  • 1
  • 9

1 Answers1

1

Here is a working example.

First, you need to install:

composer require illuminate/config
composer require illuminate/database
composer require illuminate/hashing

Here is the code example:

<?php

use Illuminate\Config\Repository;
use Illuminate\Container\Container as IlluminateContainer;
use Illuminate\Hashing\HashManager;
use Illuminate\Support\Facades\Facade;
use Illuminate\Support\Facades\Hash;
use Illuminate\Database\Capsule\Manager as Capsule;

require_once __DIR__ . '/../vendor/autoload.php';

$container = new IlluminateContainer();
Facade::setFacadeApplication($container);

$container->singleton('config', function () {
    return new Repository();
});

$container->singleton('hash', function ($app) {
    return new HashManager($app);
});

$container->singleton('hash.driver', function ($app) {
    return $app['hash']->driver();
});

//boot eloquent connection
$capsule = new Capsule();
//$capsule->addConnection($container['settings']['db']);
$capsule->setAsGlobal();
$capsule->bootEloquent();

echo Hash::make('wonder');

PS: Laravel has its own container implementation.

odan
  • 4,757
  • 5
  • 20
  • 49