PHP code example of alvin0 / database-json-laravel
1. Go to this page and download the library: Download alvin0/database-json-laravel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
alvin0 / database-json-laravel example snippets
namespace App\DatabaseJson\Models;
use DatabaseJson\Model;
class User extends Model
{
}
namespace App\DatabaseJson\Migrations;
use DatabaseJson\DatabaseJson;
use DatabaseJson\Migration;
class CreateTableUserMigrateMigrate extends Migration
{
/**
* How to create table
*
* DatabaseJson::table('NameTable',array(
* {field_name} => {field_type} More information about field types and usage in PHPDoc
* ));
*/
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
DatabaseJson::create('users', array(
'name' => 'string',
'old' => 'integer',
'created_at' => 'string',
'updated_at' => 'string',
));
}
}
namespace App\DatabaseJson\Migrations;
use DatabaseJson\DatabaseJson;
use DatabaseJson\Migration;
class CreateTableUserMigrateMigrate extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
DatabaseJson::table('users')->addFields([
//'name' => 'string'
//{field_name} => {field_type} More information about field types and usage in PHPDoc
]);
//DatabaseJson::table('users')->deleteFields([
//'name',
//{field_name}
//]);
}
}
namespace App\DatabaseJson\Models;
use DatabaseJson\Model;
class User extends Model
{
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = false;
}
use App\DatabaseJson\Models\User;
$user = new User;
$user->name = 'alvin';
$user->old = 27;
$user->save();
namespace App\DatabaseJson\Models;
use DatabaseJson\Model;
class User extends Model
{
public function blogs()
{
return $this->hasMany(Blog::class, 'user_id');
}
}
//return model App\DatabaseJson\Models\User
$userBlog = Blog::find(1)->user
namespace App;
namespace App\DatabaseJson\Models;
class User extends Model
{
/**
* Get the user's first name.
*
* @param string $value
* @return string
*/
public function getFirstNameAttribute($value)
{
return ucfirst($value);
}
}
namespace App;
namespace App\DatabaseJson\Models;
class User extends Model
{
/**
* The accessors to append to the model's array form.
*
* @var array
*/
protected $appends = ['first_name'];
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.