1. Go to this page and download the library: Download code16/ozu-client 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/ */
code16 / ozu-client example snippets
use Code16\OzuClient\Support\Database\MigratesOzuTable;
// ...
return new class extends Migration
{
use MigratesOzuTable;
public function up(): void
{
$this->createOzuTable('projects');
Schema::table('projects', function (Blueprint $table) {
$table->string('country')->nullable();
// ...
});
}
};
use Code16\OzuClient\Eloquent\IsOzuModel;
// ...
class Project extends Model
{
use IsOzuModel;
// ...
public static function configureOzuCollection(OzuCollectionConfig $config): OzuCollectionConfig
{
return $config
->setLabel('Projects')
->setIcon('fa-ruler-combined')
->setHasPublicationState()
->setIsCreatable()
->setIsDeletable(false);
}
public static function configureOzuCollectionList(OzuCollectionListConfig $config): OzuCollectionListConfig
{
return $config
->addColumn(OzuColumn::makeImage('cover', 1))
->addColumn(OzuColumn::makeText('title', 5)->setLabel('Title'))
->addColumn(OzuColumn::makeText('country', 6)->setLabel('Country'))
->setIsSearchable()
->setIsReorderable();
}
public static function configureOzuCollectionForm(OzuCollectionFormConfig $config): OzuCollectionFormConfig
{
return $config
->addCustomField(
OzuField::makeText('country')
->setLabel('Country')
->setValidationRules(['
return new class extends Migration
{
use MigratesOzuTable;
public function up(): void
{
$this->createOzuTable('projects');
Schema::table('projects', function (Blueprint $table) {
$table->foreignId('parent_id')->constrained('categories')->cascadeOnDelete();
// ...
});
}
};
class Project extends Model
{
use IsOzuModel;
public function category(): BelongsTo
{
return $this->belongsTo(Category::class, 'parent_id');
}
// ...
public static function configureOzuCollectionList(OzuCollectionListConfig $config): OzuCollectionListConfig
{
return $config
// Optionally add a filter for the Project list in the CMS
->declareBelongsToFilter(ozuModelClass: Category::class, label: 'Saison',
use Code16\OzuClient\Eloquent\Media;
// ...
class Project extends Model
{
use IsOzuModel;
public function visuals(): MorphMany
{
return $this->morphMany(Media::class, 'model')
->where('model_key', 'visuals')
->orderBy('order');
}
public function ogImage(): MorphOne
{
return $this->morphOne(Media::class, 'model')
->where('model_key', 'ogImage');
}
// ...
}
use Code16\OzuClient\Support\Database\OzuSeeder;
// ...
class DatabaseSeeder extends OzuSeeder
{
public function run(): void
{
// this will delete any remaining seeded Media file
$this->clearMediaDirectory();
Project::factory()
->count(12)
->has(Media::factory()->image('cover')->withFile(), 'cover')
->has(Media::factory()->image('visuals')->withFile()->count(3), 'visuals')
->sequence(fn ($sequence) => [
'order' => $sequence->index + 1,
'country' => fake()->country(),
])
->create();
// ...
}
}