我可以在Laravel之外使用Input :: all()吗?

时间:2015-08-17 12:44:34

标签: php laravel laravel-5 facade

我继承了一个'普通'php的项目,即它没有使用Framework或其他依赖项。我一直致力于整合EloquentArdent(用于自我验证模型)。

我使用作曲家安装它们,似乎一切都运行良好。我有一个名为Models的文件夹,我使用引导程序类型文件加载类:

$loader = require 'vendor/autoload.php';

use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Events\Dispatcher;
use Illuminate\Container\Container;
use Illuminate\Support\Facades\Facade;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;

$capsule = new Capsule;

$capsule->addConnection([
    'driver'    => 'mysql',
    'host'      => '127.0.0.1',
    'database'  => '*********',
    'username'  => '*********',
    'password'  => '*********',
    'charset'   => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix'    => '',
]);

$capsule->setEventDispatcher(new Dispatcher(new Container));

// Make this Capsule instance available globally via static methods... (optional)
$capsule->setAsGlobal();

// Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
$capsule->bootEloquent();


// Autoload all the models
spl_autoload_register(function ($class) {
    include 'models/' . $class . '.php';
});


LaravelBook\Ardent\Ardent::configureAsExternal(array(
  'driver'    => 'mysql',
  'host'      => '127.0.0.1',
  'port'      => 3306,
  'database'  => '************',
  'username'  => '************',
  'password'  => '************',
  'charset'   => 'utf8',
  'collation' => 'utf8_unicode_ci'
), 'en'); //English is the default messages language, may be left empty

但是,每当我尝试使用Input :: all()时,都会导致以下错误:

 Call to a member function all() on a non-object in /home/loadbay/public_html/beta/php-bin/vendor/illuminate/support/Facades/Facade.php on line 207

我认为它与Facades有关,我不知道如何使这个工作。有人可以帮我理解我如何使用Input :: all()吗?

更新

Facade.php第207行:

return $instance->$method();

1 个答案:

答案 0 :(得分:1)

您可以尝试直接创建Input(),而不是使用Request外观:

$request = \Illuminate\Http\Request::capture();
$input = $request->all();

Container将所有这些挂钩在一起会很好,但我现在没有这方面的信息。