1. Go to this page and download the library: Download serter35/lto 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/ */
serter35 / lto example snippets
namespace App\DTOs;
use SerterSerbest\LTO\Attributes\Request\FromBody;
use SerterSerbest\LTO\BaseDTO;
#[FromBody]
class CommentDTO extends BaseDTO
{
public function __construct(
public ?string $title,
public ?string $description
) {}
}
namespace App\Http\Controllers;
use App\DTOs\CommentDTO;
use App\Models\Comment;
class CommentController extends Controller
{
public function store(CommentDTO $dto)
{
return Comment::create($dto->toArray());
}
}
#[FromBody]
class PostStoreDTO extends BaseDTO
{
public function __construct(
public ?string $title,
public ?string $description
) {}
}
#[FromQuery]
class QueryFilterDTO extends BaseDTO
{
public function __construct(
public ?string $sortColumn,
public ?string $sortBy,
public ?array $contains
) {}
}
#[FromBody]
class CommentBodyDTO extends BaseDTO
{
public function __construct(
public ?string $title,
public ?string $body,
#[FromQuery] public ?bool $no_interaction,
#[FromRoute('post')] public int $postId
) {}
}
#[FromRequest]
class CommentBodyDTO extends BaseDTO
{
public function __construct(
public ?string $firstname,
public ?string $lastname
) {}
}
#[FromBody('header')]
public ?string $title;
class PostStoreDTO extends BaseDTO
{
public function __construct(
public ?string $title,
public ?string $description
) {}
}
public function store(UserCreateDTO $dto)
{
return User::create($dto->toArray());
}
#[FromBody]
class UserUpdateDTO extends BaseDTO
{
use Validatable;
public function __construct(
public ?string $first_name,
public ?string $last_name,
public ?string $email
) {}
protected function getValidationRules(): array
{
return [
'first_name' => '
protected function getValidationMessages(): array
{
return [
'first_name.