doufuhao8085 2017-03-15 01:23
浏览 37

在Laravel外面滔滔不绝

For the first time i'm trying to create a project from beginning for test Eloquent outside Laravel.

Folder Structure

-> orm
    ->app
        -> models
            ->customer.php
            ->database.php
        -> controllers
    ->vendor
->index.php

composer.json

{
"require": {
    "illuminate/database": "^5.4"
},
"autoload": {
    "psr-4": {
        "Controllers\\": "app/controllers/",
        "Models\\": "app/models/" 
        }
    }
}

app/models/database.php

<?php
namespace Models;

use Illuminate\Database\Capsule\Manager as Capsule;

class Database{
    function __construct() {
        $capsule = new Capsule;

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

        $capsule->bootEloquent();
        $capsule->setAsGlobal();
    }
}

app/models/customer.php

namespace Models;

use \Illuminate\Database\Eloquent\Model;

class Customer extends Model {

}

index.php

<?php
require "vendor/autoload.php";

use Models\Database;

new Database();

$customer = Customer::find(1);
$customer->address1 = "His address, 45";
$customer->name = "my customer";

$customer->save();

echo $customer->name;

executing this (record id = 1 exists) it gives me this error: Fatal error: Class 'Customer' not found in C:\xampp\htdocs\orm\index.php on line 8

What is the problem?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求解 yolo算法问题
    • ¥15 虚拟机打包apk出现错误
    • ¥30 最小化遗憾贪心算法上界
    • ¥15 用visual studi code完成html页面
    • ¥15 聚类分析或者python进行数据分析
    • ¥15 逻辑谓词和消解原理的运用
    • ¥15 三菱伺服电机按启动按钮有使能但不动作
    • ¥15 js,页面2返回页面1时定位进入的设备
    • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
    • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。