1. Go to this page and download the library: Download larafony/skeleton 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/ */
larafony / skeleton example snippets
class Note extends Model
{
#[BelongsTo(related: User::class, foreign_key: 'user_id')]
public ?User $user {
get => $this->relations->getRelation('user');
}
#[BelongsToMany(
related: Tag::class,
pivot_table: 'note_tag',
foreign_pivot_key: 'note_id',
related_pivot_key: 'tag_id'
)]
public array $tags {
get => $this->relations->getRelation('tags');
}
}
class CreateNoteDto
{
#[IsValidated]
public protected(set) string|array|null $tags {
get {
if (!isset($this->tags)) return null;
if (is_array($this->tags)) return $this->tags;
return array_map('trim', explode(',', $this->tags));
}
set => $this->tags = $value;
}
}
#[Route('/notes', 'POST')]
public function store(CreateNoteDto $dto): ResponseInterface
{
// $dto is automatically created and validated from request
$note = new Note()->fill([
'title' => $dto->title,
'content' => $dto->content,
]);
$note->save();
if ($dto->tags) {
$note->attachTags($tagIds);
}
return $this->redirect('/notes');
}