Skip to content

Commit c209ba5

Browse files
committed
init
0 parents  commit c209ba5

File tree

121 files changed

+7804
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+7804
-0
lines changed

.editorconfig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_size = 4
7+
indent_style = space
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.{yml,yaml}]
15+
indent_size = 2
16+
17+
[docker-compose.yml]
18+
indent_size = 4

.env.example

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
APP_NAME="Your App Name"
2+
APP_ENV=local
3+
APP_KEY=
4+
APP_DEBUG=true
5+
APP_URL=http://localhost
6+
7+
APP_LOCALE=en
8+
APP_FALLBACK_LOCALE=en
9+
APP_FAKER_LOCALE=en_US
10+
11+
APP_MAINTENANCE_DRIVER=file
12+
# APP_MAINTENANCE_STORE=database
13+
14+
BCRYPT_ROUNDS=12
15+
16+
LOG_CHANNEL=stack
17+
LOG_STACK=single
18+
LOG_DEPRECATIONS_CHANNEL=null
19+
LOG_LEVEL=debug
20+
21+
DB_CONNECTION=mariadb
22+
DB_HOST=127.0.0.1
23+
DB_PORT=7655
24+
DB_DATABASE=laravelapibackend
25+
DB_USERNAME=root
26+
DB_PASSWORD=myPassword123
27+
28+
OCTANE_HTTPS=false
29+
OCTANE_SERVER=swoole
30+
31+
SESSION_DRIVER=database
32+
SESSION_LIFETIME=120
33+
SESSION_ENCRYPT=false
34+
SESSION_PATH=/
35+
SESSION_DOMAIN=null
36+
37+
BROADCAST_CONNECTION=log
38+
FILESYSTEM_DISK=local
39+
QUEUE_CONNECTION=database
40+
41+
CACHE_STORE=redis
42+
CACHE_DRIVER=redis
43+
CACHE_PREFIX=laravelapibackend_cache_
44+
REDIS_DATABASE=0
45+
REDIS_CACHE_DB=0
46+
REDIS_CLIENT=phpredis
47+
REDIS_HOST=redis
48+
REDIS_PORT=7656
49+
REDIS_USERNAME=default
50+
REDIS_PASSWORD=redisPass123
51+
52+
MAIL_MAILER=smtp
53+
MAIL_SCHEME=null
54+
MAIL_BCC=
55+
MAIL_HOST=
56+
MAIL_PORT=587
57+
MAIL_USERNAME=username@host.com
58+
MAIL_PASSWORD=password
59+
MAIL_ENCRYPTION=tls
60+
MAIL_FROM_ADDRESS=
61+
ADMIN_EMAIL=
62+
MAIL_FROM_NAME="Mail from API"
63+
64+
VITE_APP_NAME="${APP_NAME}"

.gitattributes

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
* text=auto eol=lf
2+
3+
*.blade.php diff=html
4+
*.css diff=css
5+
*.html diff=html
6+
*.md diff=markdown
7+
*.php diff=php
8+
9+
/.github export-ignore
10+
CHANGELOG.md export-ignore
11+
.styleci.yml export-ignore

.gitignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
*.log
2+
.DS_Store
3+
.env
4+
.env.backup
5+
.env.production
6+
.phpactor.json
7+
.phpunit.result.cache
8+
/.fleet
9+
/.idea
10+
/.nova
11+
/.phpunit.cache
12+
/.vscode
13+
/.zed
14+
/ssl
15+
/auth.json
16+
/node_modules
17+
/public/build
18+
/public/hot
19+
/public/storage
20+
/storage/*.key
21+
/storage/pail
22+
/vendor
23+
Homestead.json
24+
Homestead.yaml
25+
Thumbs.db
26+
composer.lock
27+
package-lock.json
28+
mariadb/

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Laravel 12 Swoole - Vue3 template
2+
3+
<p align="center">
4+
<a href="https://laravel.com" target="_blank">
5+
<img src="https://raw.githubusercontent.com/laravel/art/master/logo-lockup/5%20SVG/2%20CMYK/1%20Full%20Color/laravel-logolockup-cmyk-red.svg" width="400" alt="Laravel Logo">
6+
</a>
7+
</p>
8+
9+
<p align="center">
10+
<a href="https://github.com/laravel/framework/actions"><img src="https://github.com/laravel/framework/workflows/tests/badge.svg" alt="Build Status"></a>
11+
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/dt/laravel/framework" alt="Total Downloads"></a>
12+
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/v/laravel/framework" alt="Latest Stable Version"></a>
13+
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/l/laravel/framework" alt="License"></a>
14+
</p>
15+
16+
## Project Overview
17+
18+
Laravel 12 as API backend using PHP 8.4.10 with a Swoole server, with role-based access & auth + a Vue3, Tailwind, DaisyUI frontend.
19+
Complete with a docker-compose.yml containing MariaDB & Redis & Nginx to deploy on a server.
20+
21+
### Optimize images
22+
23+
```php
24+
ImageOptimizer::optimize(storage_path('app/public/' . $pathToImage));
25+
```
26+
27+
### Development Setup
28+
29+
1. Clone the repository
30+
2. Edit `.env.example` and `docker-compose.yml` to match your environment
31+
3. Run `docker compose up -d --build`
32+
4. Generate application key: `php artisan key:generate`
33+
5. Run storage link: `php artisan storage:link`
34+
6. Run migrations: `php artisan migrate`
35+
7. Run seeders: `php artisan db:seed`
36+
8. Start development server: `npm run dev`
37+
9. Access at `127.0.0.1:7654`
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use App\Models\Role;
6+
use App\Models\User;
7+
use Illuminate\Console\Command;
8+
use Illuminate\Support\Facades\DB;
9+
use Illuminate\Support\Facades\Hash;
10+
use Throwable;
11+
12+
class RegisterUser extends Command
13+
{
14+
/**
15+
* The name and signature of the console command.
16+
*
17+
* @var string
18+
*/
19+
protected $signature = 'user:register {name} {email} {password} {role}';
20+
21+
/**
22+
* The console command description.
23+
*
24+
* @var string
25+
*/
26+
protected $description = 'Register a new user in format: Name.Surname, name@example.com, password, role=admin,editor,user';
27+
28+
/**
29+
* Execute the console command.
30+
*/
31+
public function handle(): void
32+
{
33+
$name = $this->argument('name');
34+
$email = $this->argument('email');
35+
$password = $this->argument('password');
36+
$role = $this->argument('role');
37+
38+
if (!in_array($role, ['admin', 'editor', 'user'])) {
39+
$this->error('Invalid role. Allowed roles: admin,editor,user');
40+
return;
41+
}
42+
43+
if (!str_contains($name, '.')) {
44+
$this->error('Invalid name format. Allowed format: Name.Surname');
45+
return;
46+
}
47+
48+
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
49+
$this->error('Invalid email format.');
50+
return;
51+
}
52+
53+
DB::beginTransaction();
54+
try {
55+
$user = User::query()
56+
->create([
57+
'name' => str_replace('.', ' ', $name),
58+
'email' => $email,
59+
'password' => Hash::make($password),
60+
'email_verified_at' => now(),
61+
]);
62+
63+
$userRole = Role::query()
64+
->where('name', $role)
65+
->first();
66+
67+
$user->roles()->attach($userRole);
68+
69+
DB::commit();
70+
71+
$this->info('User registered successfully.');
72+
73+
} catch (Throwable $th) {
74+
DB::rollBack();
75+
$this->error($th->getMessage());
76+
}
77+
}
78+
}

app/Exceptions/Handler.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace App\Exceptions;
4+
5+
use Illuminate\Http\JsonResponse;
6+
use Symfony\Component\HttpFoundation\Response;
7+
use Throwable;
8+
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
9+
10+
class Handler extends ExceptionHandler
11+
{
12+
/**
13+
* A list of the exception types that are not reported.
14+
*
15+
* @var array
16+
*/
17+
protected $dontReport = [
18+
//
19+
];
20+
21+
/**
22+
* A list of the inputs that are never flashed for validation exceptions.
23+
*
24+
* @var array
25+
*/
26+
protected $dontFlash = [
27+
'password',
28+
'password_confirmation',
29+
];
30+
31+
public function render($request, Throwable $e): JsonResponse|Response
32+
{
33+
if ($request->is('api/*')) {
34+
return response()->json([
35+
'message' => 'Server Error',
36+
'error' => $e->getMessage()
37+
], 500);
38+
}
39+
40+
return parent::render($request, $e);
41+
}
42+
43+
}
44+

0 commit comments

Comments
 (0)