This pretty usefull for a smaller PHP project that doesn't require the full-stack laravel framework.
Clone this repo
$ git clone https://github.com/xrexonx/myEloquent.git
or you can manually download the zip file [here] on github. [here]: https://github.com/xrexonx/myEloquent
Configure your database connections on yourProject/config/database.php file.
<?php
use Illuminate\Database\Capsule\Manager as Capsule;
$capsule = new Capsule;
$capsule->addConnection([
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'databasename',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
]);
On your projectPath/migrations/ Create a file create_table_users.php
<?php
require 'bootstrap.php';
use Illuminate\Database\Capsule\Manager as Capsule;
// Create Users Table
// =================================
Capsule::schema()->create('users', function($table)
{
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password', 60);
$table->enum('status', ['1', '0']);
$table->string('activationCode');
$table->timestamps();
});
And then run this on your terminal
$ cd $yourProjectPath/migrations/
$ php create_table_users.php
or simply run this on your browser
localhost/yourProjectName/migrations/create_table_users.php
It will create your users table on your database.
<?php
require 'bootstrap.php';
// Create new records
// =================================
User::create([
'name' => 'John Doe',
'email' => 'johndoe@gmail.com',
'password' => md5('secret'),
'status' => '1',
'activationCode' => md5('johndoe@gmail.com')
]);
// Get
// =================================
dd(User::first()->toArray());
// Updates
// =================================
$user = User::first();
$user->email = 'jd@gmail.com';
$user->save();
// Delete
// =================================
$user = User::find(1);
$user->delete();
More documentations on
MIT © Rexon A. De los Reyes
Thanks and enjoy!