1. Go to this page and download the library: Download inly/core-web 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/ */
inly / core-web example snippets
return [
'features' => ['snapshots' => true],
];
use Inly\CoreWeb\Client\CoreClient;
use Inly\CoreWeb\Snapshots\Snapshot;
use Inly\CoreWeb\Snapshots\SnapshotRegistry;
use Inly\CoreWeb\StaticCaching\SiteCache;
$this->app->extend(SnapshotRegistry::class, fn (SnapshotRegistry $registry) => $registry
->register(
Snapshot::make('locations')
->version(3) // bump when the stored document shape changes
->ttl(fresh: 3600, stale: 2592000, retry: 60)
->pull(fn () => LocationSnapshot::pull(CoreClient::fromConfig())) // every document, keyed by id
->pullOne(fn (string $id) => LocationSnapshot::pullOne(CoreClient::fromConfig(), $id)) // one object, [] when gone
->partitionBy(fn (array $doc) => $doc['site'] ?? null, ['default', 'second'])
->emptyWhen(fn (array $documents) => $documents === [])
->onChange(SiteCache::flushOnChange()) // flush the partition's site
->sitemap(fn (array $doc, string $site) => [['loc' => '/locations/'.$doc['slug'], 'lastmod' => $doc['updated_at']]]),
pings: ['location', 'locations'], // Core's ping types that refresh it
)
->register($catalog, pings: ['product', 'products'], wholePings: ['product-category'])
->register($stock, pings: ['stock'], warm: fn (Command $command) => 0, job: fn (string $id, string $action) => new RefreshStockJob($id, $action))
->idle(['product-categories'])); // accepted, acted on by nothing
$read = app(SnapshotStore::class)->read($snapshot, 'second');
$read->documents; // keyed by id
$read->stale; // the last good copy, served because no fresh one is cached
$read->degraded; // nothing cached and no pull succeeded: documents are empty
use Illuminate\Http\Request;
use Inly\CoreWeb\Chat\ChatContext;
class AssistantContext implements ChatContext
{
public function context(?string $subject, Request $request): array
{
$record = $this->record($subject);
return $record === null ? [] : ['record_id' => $record->core_id, 'page' => $record->url()];
}
// A different key starts a fresh conversation: one per record.
public function key(?string $subject, Request $request): string
{
return (string) ($this->record($subject)?->getKey() ?? 'general');
}
// Only a record that exists names a conversation, so a visitor cannot mint subjects.
private function record(?string $subject): ?Record
{
return $subject === null ? null : (Record::find($subject) ?? abort(404));
}
}
use Inly\CoreWeb\Live\LiveRead;
use Inly\CoreWeb\Live\LiveRequest;
class LoanQuote extends LiveRead
{
public function public(): bool
{
return true;
}
public function rules(): array
{
return ['item' => ['json, array $input): ?array
{
return ['monthly' => $json['data']['monthly'] ?? null];
}
public function ttl(): int
{
return 60;
}
}
use Inly\CoreWeb\Forms\CoreForm;
class DamageInspection extends CoreForm
{
// The key of the Core form it posts to.
public static function coreForm(): string
{
return 'damage-inspection';
}
// The Core fields the view renders.
public static function renders(): array
{
return ['plate', 'name', 'email', 'photos', 'damage'];
}
protected function fieldsView(): string
{
return 'livewire.damage-inspection';
}
}
$checks = app(ContentChecks::class);
$checks->latest('own-url-links'); // the last run's findings
$checks->fix('own-url-links', $findingId, $author); // a draft or a proposal