use Illuminate\Database\Capsule\Manager as Capsule; $capsule = new Capsule; $capsule->addConnection([ 'driver' => 'mysql', 'host' => 'localhost', 'database' => 'mydatabase', 'username' => 'myusername', 'password' => 'mypassword', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', ]); $capsule->setAsGlobal(); $capsule->bootEloquent();
use Illuminate\Database\Eloquent\Model; class User extends Model { protected $table = 'users'; protected $primaryKey = 'id'; public $timestamps = true; }
$users = User::all(); foreach ($users as $user) { echo $user->name; }
$user = new User; $user->name = 'John Doe'; $user->email = 'johndoe@example.com'; $user->password = bcrypt('secret'); $user->save();The PHP Illuminate Database Eloquent Model is part of the Laravel Framework, a popular PHP web application framework.