1. Go to this page and download the library: Download caiquebispo/laraslim 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/ */
use LaraSlim\Kernel\Exceptions\HttpException;
// Throw HTTP exception
throw HttpException::notFound('User not found');
throw HttpException::unauthorized();
// Or use helpers
abort(404, 'Resource not found');
abort_if($condition, 403, 'Forbidden');
use Slim\Routing\RouteCollectorProxy;
$app->group('/api', function (RouteCollectorProxy $group) {
$group->get('/users', 'UserController:index');
$group->post('/users', 'UserController:store');
});
namespace LaraSlim\Http\Controllers;
use LaraSlim\Services\UserServices;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
class UserController
{
public function __construct(private UserServices $userServices) {}
public function store(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
{
$data = $request->getParsedBody();
$user = $this->userServices->store($data);
return response($response)->created($user, 'User created successfully');
}
}
bash
php artisan-slim make:migration users
php artisan-slim make:model User
php artisan-slim make:controller UserController
php artisan-slim make:request UserRequest
php artisan-slim # List all commands
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.