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?