1

I want to use Illuminate database(https://github.com/illuminate/database). Not with Laravel, use only in my php file. I do

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'    => '',
]);

But it seems not working, and don't show any error message. Do I need to require any file? The illuminate directory is in the same directory with my php file.

EDIT:

I can use query now. Like this

$users = Capsule::table('users')->where('votes', '>', 100)->get();

I don't know how to use model.

User.php

class User extends Illuminate\Database\Eloquent\Model {
}

My php file

require 'vendor/autoload.php';
require 'User.php';
$users = User::where('status', '=', 1)->get();

Got error

Fatal error: Call to a member function connection() on a non-object in /Users/someone/repos/test/vendor/illuminate/database/Illuminate/Database/Eloquent/Model.php on line 2472

SOLVED:

Everything works fine. Use @majid8911 example https://github.com/mattstauffer/IlluminateNonLaravel Thank you everyone.

Howard
  • 601
  • 1
  • 11
  • 15

1 Answers1

6

take a look at here I successfully did the same with this tutorial: https://github.com/mattstauffer/IlluminateNonLaravel

Majid Abdolhosseini
  • 2,191
  • 4
  • 31
  • 59
  • I saw the codes a while. I can see some models defined in app/Eloquent, but how to use in my php file. Do I need to require any files? What does the public directory do? Thanks – Howard Dec 25 '14 at 11:07
  • I use you codes. It's works. I can run $users = UserEncapsulated::all(); However, foreach ($users as $user){ echo $user->name; } not working – Howard Dec 25 '14 at 12:10