沙滩星空的博客沙滩星空的博客

非Laravel框架使用Laravel组件

使用 Eloquent 模块

Eloquent 模块引入

composer require illuminate/database

如果使用分页的话,还要引入 illuminate/database

composer require illuminate/database

程序头部公共部分,引入composer加载器。例:

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

配置并初始化 Eloquent :

新建文件 eloquent.php
引入composer加载器之后,再引入 eloquent.php 初始化文件

use Illuminate\Database\Capsule\Manager as Capsule;

$capsule = new Capsule;

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

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

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

使用 Eloquent 模型:

use  Illuminate\Database\Eloquent\Model  as Eloquent;

class User extends  Eloquent
{
    protected $table = 'users';
}


整合laravel的ORM,Eloquent模块 https://blog.csdn.net/leigin/article/details/95312246
官方组件:https://github.com/illuminate/database

未经允许不得转载:沙滩星空的博客 » 非Laravel框架使用Laravel组件

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址