caiquebispo / laraslim
A lightweight PHP microframework combining Slim and Laravel features for fast and structured API development.
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 1
Forks: 1
Open Issues: 0
Type:project
Requires
- php: ^8.4
- caiquebispo/blade-slim: ^1.0
- illuminate/database: ^12.7
- illuminate/http: ^12.7
- illuminate/validation: ^12.7
- php-di/php-di: ^7.0
- slim/psr7: ^1.7
- slim/slim: 4.*
- symfony/console: ^7.2
- vlucas/phpdotenv: ^5.6
Requires (Dev)
- laravel/pint: ^1.22
- pestphp/pest: ^3.8
- pestphp/pest-plugin-drift: ^3.0
- phpstan/phpstan: ^2.1
README
Description
LaraSlim is a microframework for PHP that combines the lightness of the Slim Framework with a structure inspired by Laravel. It's ideal for creating clean, modular APIs with a lightweight and fast setup.
Note: This project does not include an authentication engine by default. You can integrate your own or use third-party libraries.
It also doesn't include a template engine, but you can integrate it with Blade (Laravel) or any other engine of your choice.
⚠️ This is a beta project: some features may be under development and bugs may occur.
Requirements
- PHP ^8.4
- Docker
- Composer
Installation via Composer
composer create-project caiquebispo/laraslim example_app
Manual Installation
-
Clone the repository:
git clone https://github.com/caiquebispo/LaraSlim.git cd LaraSlim
-
Build Docker containers:
sh build
-
Start the Docker containers:
sh up
-
Attach the Docker containers:
sh attach
-
Down the Docker containers:
sh down
-
Install dependencies:
composer install
-
Copy the
.env
file:cp .env.exemple .env
-
Run tests and checks:
composer test
- Show all available commands:
php artisan-slim
Application Access
- API:
http://localhost:8003
- PHPMyAdmin:
http://localhost:8080
- User:
root
- Password:
root
- User:
Project Structure
app/Http/Controllers
: Application controllers.app/Http/Request
: Form validation files.app/Models
: Data models.app/DTOs
: Data Transfer Objects.app/Services
: Business logic layer.app/Kernel
: Configuration and setup files.database/migrations
: Database migration files.public
: Web-accessible files (e.g.,index.php
).composer.json
: Composer configuration.
Database Configuration
Configure your .env
file as needed. Example using SQLite:
DB_CONNECTION="sqlite" DB_HOST="" DB_DATABASE="../database/skeleton_db.sqlite" DB_USERNAME="" DB_PASSWORD=""
Useful Commands
Create a new migration:
php artisan-slim make:migration users
Create a new model:
php artisan-slim make:model User
Create a new controller:
php artisan-slim make:controller UserController
Create a new form request:
php artisan-slim make:request UserRequest
Migrations are automatically executed when the container is started.
Examples
Route Group
use Slim\Routing\RouteCollectorProxy; $app->group('/api', function (RouteCollectorProxy $group) { $group->get('/users', 'UserController:index'); $group->post('/users', 'UserController:store'); });
Simple Route
use LaraSlim\Controllers\HomeController; $app->get('/', [HomeController::class, 'index']);
Basic Controller
<?php namespace LaraSlim\Controllers; class HomeController { public function index() { // Controller logic here } }
Form Request
<?php namespace LaraSlim\Http\Request; class UserRequest extends BaseRequest { protected function rules(): array { return [ //'name' => 'required|string|max:255', ]; } protected function messages(): array { return [ //'email.required' => 'The email field is required.', ]; } }
Using Form Request in Controller
<?php namespace LaraSlim\Http\Controllers; use LaraSlim\DTOs\UserDTO; use LaraSlim\Http\Request\UserRequest; use LaraSlim\Kernel\Providers\Response; use LaraSlim\Services\UserServices; class UserController { public function __construct(private UserServices $userServices) {} public function store(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface { $validator = (new UserRequest($request->getParsedBody()))->validate(); if ($validator->fails()) { return (new Response($response))->json([ 'status' => 'error', 'message' => 'Validation failed', 'errors' => $validator->errors() ], 422); } $user = $this->userServices->store(new UserDTO(...$request->getParsedBody())); return (new Response($response))->json([ 'status' => 'success', 'message' => 'User created successfully', 'user' => $user ], 201); } }
Author
- Caique Bispo
📧 caiquebispodanet86@gmail.com
License
This project is licensed under the terms of the MIT License.