1. Go to this page and download the library: Download basanta/array-model 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/ */
basanta / array-model example snippets
namespace App\ArrayModels;
use Basanta\ArrayModel\ArrayModel;
class User extends ArrayModel {}
namespace App\ArrayModels;
use Basanta\ArrayModel\ArrayModel;
class User extends ArrayModel
{
public function posts()
{
return $this->hasMany(Post::class, 'user_id', 'id');
}
}
class Post extends ArrayModel
{
public function user()
{
return $this->belongsTo(User::class, 'user_id', 'id');
}
}
$user = User::where('id', 1)->first();
$posts = $user->posts; // relationship method is executed and cached