1. Go to this page and download the library: Download surrealdb/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/ */
namespace App\Models;
use App\Schemas\UserSchema;
use Surqlize\Attributes\Id;
use Surqlize\Attributes\Schema;
use Surqlize\Attributes\Table;
use Surqlize\Model\Model;
use SurrealDB\SDK\Types\RecordId;
#[Table('user')]
#[Schema(UserSchema::class)]
final class User extends Model
{
/** @var RecordId<'user'> */
#[Id]
public RecordId $id;
public string $name;
}
namespace App\Schemas;
use Surqlize\Model\SchemaContract;
final class UserSchema implements SchemaContract
{
public function definitions(): array
{
return [
'DEFINE TABLE user SCHEMAFULL;',
'DEFINE FIELD name ON user TYPE string;',
];
}
public function rules(): array
{
return [];
}
}
use SurrealDB\Laravel\Testing\RefreshSurqlizeState;
final class UserTest extends TestCase
{
use RefreshSurqlizeState;
protected function tearDown(): void
{
$this->resetSurqlizeState();
parent::tearDown();
}
}