PHP code example of ttpryg / slim-api-starter

1. Go to this page and download the library: Download ttpryg/slim-api-starter 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/ */

    

ttpryg / slim-api-starter example snippets


   $validated = $validator->validate((array) $request->getParsedBody(), [
       'name' => '

   use Symfony\Component\Validator\Constraints as Assert;

   $validated = $validator->validate($data, [
       'email' => [new Assert\NotBlank(), new Assert\Email()],
   ]);
   

   use Symfony\Component\Validator\Constraints as Assert;

   class UserDto
   {
       public function __construct(
           #[Assert\NotBlank]
           #[Assert\Email]
           public string $email
       ) {}
   }

   $validator->validate($userDto);
   

  public function __construct(private \Psr\Log\LoggerInterface $logger) {}
  
  public function __invoke(...) {
      $this->logger->info("This is a custom log entry");
  }
  
bash
  php slim make:action User/LoginAction
  
bash
  php slim make:model User
  
bash
  php slim migrate
  
bash
  php slim migrate:rollback
  php slim migrate:rollback 3   # rollback 3 batches
  
bash
  php slim make:migration CreateUsersTable
  
bash
  php slim seed:run
  
bash
  php slim seed:create UsersTableSeeder