├── public ├── favicon.ico ├── robots.txt ├── index.php └── .htaccess ├── database ├── .gitignore ├── seeders │ ├── DatabaseSeeder.php │ ├── RolesAndPermissionsSeeder.php │ └── UserSeeder.php ├── migrations │ ├── 0001_01_01_000001_create_cache_table.php │ ├── 2025_04_09_202153_create_personal_access_tokens_table.php │ ├── 0001_01_01_000000_create_users_table.php │ ├── 0001_01_01_000002_create_jobs_table.php │ └── 2025_04_09_195002_create_permission_tables.php └── factories │ └── UserFactory.php ├── bootstrap ├── cache │ └── .gitignore ├── providers.php └── app.php ├── storage ├── logs │ └── .gitignore ├── app │ ├── private │ │ └── .gitignore │ ├── public │ │ └── .gitignore │ └── .gitignore └── framework │ ├── testing │ └── .gitignore │ ├── views │ └── .gitignore │ ├── cache │ ├── data │ │ └── .gitignore │ └── .gitignore │ ├── sessions │ └── .gitignore │ └── .gitignore ├── tests ├── Unit │ └── ExampleTest.php ├── Feature │ └── ExampleTest.php ├── TestCase.php └── Pest.php ├── app ├── Http │ ├── Controllers │ │ └── Controller.php │ └── Middleware │ │ └── HandleInertiaRequests.php ├── Providers │ └── AppServiceProvider.php ├── Enums │ └── Permissions │ │ ├── Rol.php │ │ └── Permiso.php ├── Helpers │ ├── ConsoleHelper.php │ └── AuthenticationHelper.php ├── Services │ ├── FileService.php │ └── MailService.php └── Models │ └── User.php ├── routes ├── api.php ├── web.php └── console.php ├── .gitattributes ├── .editorconfig ├── resources ├── ts │ ├── src │ │ ├── redux │ │ │ ├── hook.ts │ │ │ ├── store.ts │ │ │ └── slices │ │ │ │ └── themeSlice.ts │ │ ├── hooks │ │ │ └── useThemeApp.ts │ │ ├── config │ │ │ └── PreConfigApp.tsx │ │ ├── layouts │ │ │ └── Layout.tsx │ │ ├── pages │ │ │ ├── error │ │ │ │ └── NotFoundPage.tsx │ │ │ └── others │ │ │ │ ├── ExampleModalPage.tsx │ │ │ │ ├── ExampleFormPage.tsx │ │ │ │ └── TemplateTestPage.tsx │ │ ├── scss │ │ │ └── modules │ │ │ │ └── Modal.module.scss │ │ └── components │ │ │ ├── forms │ │ │ └── FormDefault.tsx │ │ │ ├── inputs │ │ │ └── InputDefault.tsx │ │ │ └── modals │ │ │ └── ModalDefault.tsx │ └── app.tsx ├── views │ └── app.blade.php └── css │ └── app.css ├── .gitignore ├── artisan ├── tsconfig.json ├── vite.config.js ├── package.json ├── config ├── services.php ├── filesystems.php ├── sanctum.php ├── cache.php ├── mail.php ├── queue.php ├── auth.php ├── app.php ├── logging.php ├── database.php ├── permission.php └── session.php ├── phpunit.xml ├── .env.example ├── composer.json └── README.md /public/favicon.ico: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /database/.gitignore: -------------------------------------------------------------------------------- 1 | *.sqlite* 2 | -------------------------------------------------------------------------------- /bootstrap/cache/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/logs/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | User-agent: * 2 | Disallow: 3 | -------------------------------------------------------------------------------- /storage/app/private/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/app/public/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/testing/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/views/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/cache/data/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/sessions/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/cache/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !data/ 3 | !.gitignore 4 | -------------------------------------------------------------------------------- /storage/app/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !private/ 3 | !public/ 4 | !.gitignore 5 | -------------------------------------------------------------------------------- /bootstrap/providers.php: -------------------------------------------------------------------------------- 1 | toBeTrue(); 5 | }); 6 | -------------------------------------------------------------------------------- /app/Http/Controllers/Controller.php: -------------------------------------------------------------------------------- 1 | get('/'); 5 | 6 | $response->assertStatus(200); 7 | }); 8 | -------------------------------------------------------------------------------- /tests/TestCase.php: -------------------------------------------------------------------------------- 1 | user(); 8 | })->middleware('auth:sanctum'); 9 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 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 12 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 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 19 | -------------------------------------------------------------------------------- /resources/ts/src/redux/hook.ts: -------------------------------------------------------------------------------- 1 | import { useDispatch, useSelector } from "react-redux"; 2 | import { AppDispatch, RootState } from "./store"; 3 | 4 | //STUB - useAppDispatch en lugar de 'useDispatch' 5 | export const useReduxDispatch = useDispatch.withTypes(); 6 | //STUB - useAppSelector en lugar de 'useSelector' 7 | export const useReduxSelector = useSelector.withTypes(); 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.phpunit.cache 2 | /node_modules 3 | /public/build 4 | /public/hot 5 | /public/storage 6 | /storage/*.key 7 | /storage/pail 8 | /vendor 9 | .env 10 | .env.backup 11 | .env.production 12 | .phpactor.json 13 | .phpunit.result.cache 14 | Homestead.json 15 | Homestead.yaml 16 | npm-debug.log 17 | yarn-error.log 18 | /auth.json 19 | /.fleet 20 | /.idea 21 | /.nova 22 | /.vscode 23 | /.zed 24 | -------------------------------------------------------------------------------- /resources/ts/src/hooks/useThemeApp.ts: -------------------------------------------------------------------------------- 1 | import { useSelector } from 'react-redux'; 2 | import { RootState } from '../redux/store'; 3 | import { ThemeSliceType } from '../redux/slices/themeSlice'; 4 | 5 | /** 6 | * Hook para obtener el estado del tema 7 | * @return {ThemeSliceType} 8 | */ 9 | export const useThemeApp = (): ThemeSliceType => { 10 | return useSelector((state: RootState) => state.stateTheme); 11 | }; 12 | -------------------------------------------------------------------------------- /resources/ts/src/redux/store.ts: -------------------------------------------------------------------------------- 1 | import { configureStore } from "@reduxjs/toolkit"; 2 | import themeSlice from "./slices/themeSlice"; 3 | 4 | // TODO - STORE REDUX 5 | export const store = configureStore({ 6 | // Proveedores redux 7 | reducer: { 8 | // Estado del tema 9 | stateTheme: themeSlice, 10 | }, 11 | }); 12 | 13 | // Tipos 14 | export type RootState = ReturnType; 15 | export type AppDispatch = typeof store.dispatch; 16 | -------------------------------------------------------------------------------- /resources/views/app.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | @viteReactRefresh 9 | @vite(['resources/css/app.css','resources/ts/app.tsx']) 10 | @inertiaHead 11 | 12 | Admin 13 | 14 | 15 | 16 | @inertia 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /app/Providers/AppServiceProvider.php: -------------------------------------------------------------------------------- 1 | handleCommand(new ArgvInput); 17 | 18 | exit($status); 19 | -------------------------------------------------------------------------------- /app/Enums/Permissions/Rol.php: -------------------------------------------------------------------------------- 1 | call(RolesAndPermissionsSeeder::class); 23 | $this->call(UserSeeder::class); 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "esnext", 4 | "module": "esnext", 5 | "moduleResolution": "node", 6 | "strict": true, 7 | "jsx": "react-jsx", // Importante para TSX 8 | "esModuleInterop": true, 9 | "moduleDetection": "force", 10 | "forceConsistentCasingInFileNames": true, 11 | "resolveJsonModule": true, 12 | "isolatedModules": true, 13 | "noEmit": true, 14 | "types": ["vite/client"] 15 | }, 16 | "include": ["resources/**/*"], 17 | "exclude": ["public/**/*", "node_modules", "vendor"] 18 | } 19 | -------------------------------------------------------------------------------- /vite.config.js: -------------------------------------------------------------------------------- 1 | import { defineConfig } from "vite"; 2 | import laravel from "laravel-vite-plugin"; 3 | import tailwindcss from "@tailwindcss/vite"; 4 | import react from "@vitejs/plugin-react"; 5 | 6 | export default defineConfig({ 7 | plugins: [ 8 | laravel({ 9 | input: [ 10 | 'resources/css/app.css', 11 | 'resources/ts/app.tsx' 12 | ], 13 | refresh: true, 14 | }), 15 | react(), 16 | tailwindcss(), 17 | ], 18 | resolve: { 19 | alias: { 20 | "@": "/resources/ts", 21 | }, 22 | }, 23 | }); 24 | -------------------------------------------------------------------------------- /public/index.php: -------------------------------------------------------------------------------- 1 | handleRequest(Request::capture()); 21 | -------------------------------------------------------------------------------- /bootstrap/app.php: -------------------------------------------------------------------------------- 1 | withRouting( 10 | web: __DIR__.'/../routes/web.php', 11 | api: __DIR__.'/../routes/api.php', 12 | commands: __DIR__.'/../routes/console.php', 13 | health: '/up', 14 | ) 15 | ->withMiddleware(function (Middleware $middleware) { 16 | $middleware->append(HandleInertiaRequests::class); 17 | }) 18 | ->withExceptions(function (Exceptions $exceptions) { 19 | // 20 | })->create(); 21 | -------------------------------------------------------------------------------- /public/.htaccess: -------------------------------------------------------------------------------- 1 | 2 | 3 | Options -MultiViews -Indexes 4 | 5 | 6 | RewriteEngine On 7 | 8 | # Handle Authorization Header 9 | RewriteCond %{HTTP:Authorization} . 10 | RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] 11 | 12 | # Handle X-XSRF-Token Header 13 | RewriteCond %{HTTP:x-xsrf-token} . 14 | RewriteRule .* - [E=HTTP_X_XSRF_TOKEN:%{HTTP:X-XSRF-Token}] 15 | 16 | # Redirect Trailing Slashes If Not A Folder... 17 | RewriteCond %{REQUEST_FILENAME} !-d 18 | RewriteCond %{REQUEST_URI} (.+)/$ 19 | RewriteRule ^ %1 [L,R=301] 20 | 21 | # Send Requests To Front Controller... 22 | RewriteCond %{REQUEST_FILENAME} !-d 23 | RewriteCond %{REQUEST_FILENAME} !-f 24 | RewriteRule ^ index.php [L] 25 | 26 | -------------------------------------------------------------------------------- /app/Enums/Permissions/Permiso.php: -------------------------------------------------------------------------------- 1 | { 8 | // Paginas 9 | const pages = import.meta.glob("./src/**/*.tsx", { eager: true }); 10 | 11 | // Layout 12 | let page: any = pages[`./src/${name}.tsx`]; 13 | 14 | // Layout 15 | page.default.layout = 16 | page.default.layout || ((page: any) => ); 17 | 18 | return page; 19 | }, 20 | setup({ el, App, props }) { 21 | createRoot(el).render( 22 | 23 | 24 | 25 | ); 26 | }, 27 | }).then((r) => {}); 28 | -------------------------------------------------------------------------------- /resources/ts/src/config/PreConfigApp.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { Toaster } from "react-hot-toast"; 3 | 4 | // React redux 5 | import { Provider as ReduxProvider } from "react-redux"; 6 | import { store } from "../redux/store"; 7 | 8 | // Props 9 | interface PreConfigAppProps { 10 | children: React.ReactNode; 11 | } 12 | 13 | /** 14 | * PreConfigApp configuration initial before the application starts 15 | * 16 | * @param {React.ReactNode} children - Children components 17 | * @returns {JSX.Element} 18 | */ 19 | const PreConfigApp: React.FC = ({ children }) => { 20 | return ( 21 | 22 | 23 | {/* Aplicación */} 24 | {children} 25 | 26 | {/* Toast */} 27 | 28 | 29 | ); 30 | }; 31 | 32 | export default PreConfigApp; 33 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "type": "module", 4 | "scripts": { 5 | "build": "vite build", 6 | "dev": "vite" 7 | }, 8 | "devDependencies": { 9 | "@tailwindcss/vite": "^4.0.0", 10 | "@types/react-dom": "^19.1.2", 11 | "@vitejs/plugin-react": "^4.3.4", 12 | "axios": "^1.8.2", 13 | "concurrently": "^9.0.1", 14 | "laravel-vite-plugin": "^1.2.0", 15 | "tailwindcss": "^4.0.0", 16 | "vite": "^6.2.4" 17 | }, 18 | "dependencies": { 19 | "@inertiajs/react": "^2.0.7", 20 | "@reduxjs/toolkit": "^2.6.1", 21 | "@types/react": "^19.1.0", 22 | "formik": "^2.4.6", 23 | "react": "^19.1.0", 24 | "react-dom": "^19.1.0", 25 | "react-hot-toast": "^2.5.2", 26 | "react-redux": "^9.2.0", 27 | "sass": "^1.86.3", 28 | "typescript": "^5.8.3", 29 | "yup": "^1.6.1" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /resources/ts/src/redux/slices/themeSlice.ts: -------------------------------------------------------------------------------- 1 | import { createSlice, PayloadAction } from "@reduxjs/toolkit"; 2 | 3 | // Definimos tipo 4 | export type ThemeAppType = "dark" | "light"; 5 | 6 | // Definimos el estado 7 | export type ThemeSliceType = { 8 | theme: ThemeAppType; 9 | isThemeDark: boolean; 10 | }; 11 | 12 | // Definimos datos iniciales 13 | const initialState: ThemeSliceType = { 14 | theme: "light", 15 | isThemeDark: false, 16 | }; 17 | 18 | // Creamos un slice 19 | export const themeSlice = createSlice({ 20 | name: "theme", // Nombre del slice 21 | initialState, // Datos iniciales 22 | reducers: { 23 | // Actualizar tema 24 | updateTheme: (state, action: PayloadAction) => { 25 | state.theme = action.payload; 26 | state.isThemeDark = action.payload === "dark"; 27 | }, 28 | }, 29 | }); 30 | 31 | // Exportamos 32 | export const { updateTheme } = themeSlice.actions; 33 | 34 | export default themeSlice.reducer; 35 | -------------------------------------------------------------------------------- /resources/ts/src/layouts/Layout.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { useThemeApp } from "../hooks/useThemeApp"; 3 | 4 | // Props 5 | interface LayoutProps { 6 | children: React.ReactNode; 7 | } 8 | 9 | /** 10 | * Layout component 11 | * 12 | * @param {React.ReactNode} children - Children components 13 | * @returns {JSX.Element} 14 | */ 15 | const Layout: React.FC = ({ children }) => { 16 | // Obtener acceso al tema actual del app 17 | const { theme } = useThemeApp(); 18 | 19 | return ( 20 |
21 |
22 |
23 |
24 | {children} 25 |
26 |
27 |
28 |
29 | ); 30 | }; 31 | 32 | export default Layout; 33 | -------------------------------------------------------------------------------- /database/migrations/0001_01_01_000001_create_cache_table.php: -------------------------------------------------------------------------------- 1 | string('key')->primary(); 16 | $table->mediumText('value'); 17 | $table->integer('expiration'); 18 | }); 19 | 20 | Schema::create('cache_locks', function (Blueprint $table) { 21 | $table->string('key')->primary(); 22 | $table->string('owner'); 23 | $table->integer('expiration'); 24 | }); 25 | } 26 | 27 | /** 28 | * Reverse the migrations. 29 | */ 30 | public function down(): void 31 | { 32 | Schema::dropIfExists('cache'); 33 | Schema::dropIfExists('cache_locks'); 34 | } 35 | }; 36 | -------------------------------------------------------------------------------- /database/migrations/2025_04_09_202153_create_personal_access_tokens_table.php: -------------------------------------------------------------------------------- 1 | id(); 16 | $table->morphs('tokenable'); 17 | $table->string('name'); 18 | $table->string('token', 64)->unique(); 19 | $table->text('abilities')->nullable(); 20 | $table->timestamp('last_used_at')->nullable(); 21 | $table->timestamp('expires_at')->nullable(); 22 | $table->timestamps(); 23 | }); 24 | } 25 | 26 | /** 27 | * Reverse the migrations. 28 | */ 29 | public function down(): void 30 | { 31 | Schema::dropIfExists('personal_access_tokens'); 32 | } 33 | }; 34 | -------------------------------------------------------------------------------- /resources/css/app.css: -------------------------------------------------------------------------------- 1 | /* Use of tailwind */ 2 | @import "tailwindcss"; 3 | 4 | @theme { 5 | /* Colores de la interfaz */ 6 | --color-primary-50: rgba(245, 245, 245, 1); 7 | --color-primary-100: rgba(230, 230, 230, 1); 8 | --color-primary-200: rgba(200, 200, 200, 1); 9 | --color-primary-300: rgba(160, 160, 160, 1); 10 | --color-primary-400: rgba(100, 100, 100, 1); 11 | --color-primary-500: rgba(50, 50, 50, 1); 12 | --color-primary-600: rgba(30, 30, 30, 1); 13 | --color-primary-700: rgba(20, 20, 20, 1); 14 | --color-primary-800: rgba(10, 10, 10, 1); 15 | --color-primary-900: rgba(0, 0, 0, 1); 16 | --color-primary-950: rgba(0, 0, 0, 0.87); 17 | } 18 | 19 | /* Modo oscuro manual (dark | light */ 20 | @custom-variant dark (&:where(.dark, .dark *)); 21 | 22 | /* Ajustes globales */ 23 | *, 24 | *::before, 25 | *::after { 26 | -moz-box-sizing: border-box; 27 | box-sizing: border-box; 28 | } 29 | 30 | html, 31 | body { 32 | margin: 0; 33 | padding: 0; 34 | list-style: none; 35 | position: relative; 36 | } 37 | -------------------------------------------------------------------------------- /routes/web.php: -------------------------------------------------------------------------------- 1 | Inertia::render('pages/others/TemplateTestPage')); 11 | 12 | 13 | /** 14 | * Development routes 15 | * 16 | * These routes are only loaded in the 'local' environment. 17 | */ 18 | if (app()->environment('local')) { 19 | Route::prefix('develop')->group(function () { 20 | // Template default 21 | Route::get('home', fn() => Inertia::render('pages/others/TemplateTestPage')); 22 | 23 | // Template modal 24 | Route::get('modal', fn() => Inertia::render('pages/others/ExampleModalPage')); 25 | 26 | // Template form 27 | Route::get('form', fn() => Inertia::render('pages/others/ExampleFormPage')); 28 | }); 29 | } 30 | 31 | 32 | /** 33 | * Catch-all route for 404 errors 34 | */ 35 | Route::fallback(function () { 36 | return Inertia::render('pages/error/NotFoundPage') 37 | ->toResponse(request()) 38 | ->setStatusCode(404); 39 | }); 40 | -------------------------------------------------------------------------------- /resources/ts/src/pages/error/NotFoundPage.tsx: -------------------------------------------------------------------------------- 1 | import { Link } from "@inertiajs/react"; 2 | import React from "react"; 3 | 4 | /** 5 | * 404 page 6 | * 7 | * @returns {JSX.Element} 8 | */ 9 | const NotFoundPage: React.FC = () => { 10 | return ( 11 |
12 | {/* Header */} 13 |

404

14 | {/* Message */} 15 |

Página no encontrada

16 | {/* Button */} 17 | 21 | 22 | Volver al inicio 23 | 24 | 25 |
26 | ); 27 | }; 28 | 29 | export default NotFoundPage; 30 | -------------------------------------------------------------------------------- /app/Helpers/ConsoleHelper.php: -------------------------------------------------------------------------------- 1 | 35 | */ 36 | public function share(Request $request): array 37 | { 38 | return array_merge(parent::share($request), [ 39 | // 40 | ]); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /config/services.php: -------------------------------------------------------------------------------- 1 | [ 18 | 'token' => env('POSTMARK_TOKEN'), 19 | ], 20 | 21 | 'ses' => [ 22 | 'key' => env('AWS_ACCESS_KEY_ID'), 23 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 24 | 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), 25 | ], 26 | 27 | 'resend' => [ 28 | 'key' => env('RESEND_KEY'), 29 | ], 30 | 31 | 'slack' => [ 32 | 'notifications' => [ 33 | 'bot_user_oauth_token' => env('SLACK_BOT_USER_OAUTH_TOKEN'), 34 | 'channel' => env('SLACK_BOT_USER_DEFAULT_CHANNEL'), 35 | ], 36 | ], 37 | 38 | ]; 39 | -------------------------------------------------------------------------------- /database/factories/UserFactory.php: -------------------------------------------------------------------------------- 1 | 11 | */ 12 | class UserFactory extends Factory 13 | { 14 | /** 15 | * The current password being used by the factory. 16 | */ 17 | protected static ?string $password; 18 | 19 | /** 20 | * Define the model's default state. 21 | * 22 | * @return array 23 | */ 24 | public function definition(): array 25 | { 26 | return [ 27 | 'name' => fake()->name(), 28 | 'email' => fake()->unique()->safeEmail(), 29 | 'email_verified_at' => now(), 30 | 'password' => static::$password ??= Hash::make('password'), 31 | 'remember_token' => Str::random(10), 32 | ]; 33 | } 34 | 35 | /** 36 | * Indicate that the model's email address should be unverified. 37 | */ 38 | public function unverified(): static 39 | { 40 | return $this->state(fn (array $attributes) => [ 41 | 'email_verified_at' => null, 42 | ]); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | tests/Unit 10 | 11 | 12 | tests/Feature 13 | 14 | 15 | 16 | 17 | app 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | APP_NAME=Laravel 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 | PHP_CLI_SERVER_WORKERS=4 15 | 16 | BCRYPT_ROUNDS=12 17 | 18 | LOG_CHANNEL=stack 19 | LOG_STACK=single 20 | LOG_DEPRECATIONS_CHANNEL=null 21 | LOG_LEVEL=debug 22 | 23 | DB_CONNECTION=mariadb 24 | DB_HOST=127.0.0.1 25 | DB_PORT=3306 26 | DB_DATABASE=backend 27 | DB_USERNAME=root 28 | DB_PASSWORD= 29 | 30 | SESSION_DRIVER=database 31 | SESSION_LIFETIME=120 32 | SESSION_ENCRYPT=false 33 | SESSION_PATH=/ 34 | SESSION_DOMAIN=null 35 | 36 | BROADCAST_CONNECTION=log 37 | FILESYSTEM_DISK=local 38 | QUEUE_CONNECTION=database 39 | 40 | CACHE_STORE=database 41 | # CACHE_PREFIX= 42 | 43 | MEMCACHED_HOST=127.0.0.1 44 | 45 | REDIS_CLIENT=phpredis 46 | REDIS_HOST=127.0.0.1 47 | REDIS_PASSWORD=null 48 | REDIS_PORT=6379 49 | 50 | MAIL_MAILER=log 51 | MAIL_SCHEME=null 52 | MAIL_HOST=127.0.0.1 53 | MAIL_PORT=2525 54 | MAIL_USERNAME=null 55 | MAIL_PASSWORD=null 56 | MAIL_FROM_ADDRESS="hello@example.com" 57 | MAIL_FROM_NAME="${APP_NAME}" 58 | 59 | AWS_ACCESS_KEY_ID= 60 | AWS_SECRET_ACCESS_KEY= 61 | AWS_DEFAULT_REGION=us-east-1 62 | AWS_BUCKET= 63 | AWS_USE_PATH_STYLE_ENDPOINT=false 64 | 65 | VITE_APP_NAME="${APP_NAME}" 66 | 67 | # EXTRA KEYS 68 | USE_CONSOLE_KEY=1 69 | -------------------------------------------------------------------------------- /app/Services/FileService.php: -------------------------------------------------------------------------------- 1 | app/Services/FileService.php 4 | 5 | namespace App\Services; 6 | 7 | use Illuminate\Support\Facades\App; 8 | use Illuminate\Support\Facades\File; 9 | 10 | 11 | //TODO - FILE SERVICE 12 | class FileService 13 | { 14 | 15 | // * Variables 16 | 17 | public static string $pathStorage = "app/public/"; 18 | 19 | /** 20 | * 21 | * Método para limpiar datos de storage/app 22 | * 23 | * @param string $directory 24 | * 25 | * @return void 26 | */ 27 | public static function clearDirectoryStorageApp(string $directory): void 28 | { 29 | try { 30 | 31 | // ? No es de consola 32 | if (!App::runningInConsole()) { 33 | throw new \Exception('Esta función solo puede ser ejecutada desde la consola.'); 34 | } 35 | 36 | // Ruta completa al directorio dentro de storage/app 37 | $directoryPath = storage_path(self::$pathStorage . $directory); 38 | 39 | // ? No existe 40 | if (!File::isDirectory($directoryPath)) { 41 | throw new \Exception('El directorio solicitado no existe'); 42 | } 43 | 44 | // Obtener la lista de archivos 45 | $files = File::files($directoryPath); 46 | 47 | // Eliminar cada archivo 48 | foreach ($files as $file) { 49 | File::delete($file); 50 | } 51 | } catch (\Throwable $th) { 52 | throw new \Exception($th->getMessage()); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /resources/ts/src/scss/modules/Modal.module.scss: -------------------------------------------------------------------------------- 1 | // components/Modal/Modal.module.scss 2 | @keyframes backdropEnter { 3 | from { 4 | opacity: 0; 5 | } 6 | to { 7 | opacity: 1; 8 | } 9 | } 10 | 11 | @keyframes backdropLeave { 12 | from { 13 | opacity: 1; 14 | } 15 | to { 16 | opacity: 0; 17 | } 18 | } 19 | 20 | @keyframes modalEnter { 21 | from { 22 | opacity: 0; 23 | transform: translateY(10px) scale(0.98); 24 | } 25 | to { 26 | opacity: 1; 27 | transform: translateY(0) scale(1); 28 | } 29 | } 30 | 31 | @keyframes modalLeave { 32 | from { 33 | opacity: 1; 34 | transform: translateY(0) scale(1); 35 | } 36 | to { 37 | opacity: 0; 38 | transform: translateY(10px) scale(0.98); 39 | } 40 | } 41 | 42 | .backdrop { 43 | position: fixed; 44 | top: 0; 45 | left: 0; 46 | right: 0; 47 | bottom: 0; 48 | z-index: 9999; 49 | background-color: rgba(0, 0, 0, 0.5); 50 | display: flex; 51 | align-items: center; 52 | justify-content: center; 53 | backdrop-filter: blur(5px); 54 | -webkit-backdrop-filter: blur(5px); 55 | 56 | &[data-close-on-click="true"] { 57 | cursor: pointer; 58 | 59 | .modalContainer { 60 | cursor: default; 61 | } 62 | } 63 | } 64 | 65 | .modalContainer { 66 | background-color: white; 67 | border-radius: 1rem; 68 | box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25); 69 | margin: auto; 70 | position: relative; 71 | } 72 | 73 | .modalEnter { 74 | animation: modalEnter 0.25s cubic-bezier(0.4, 0, 0.2, 1) forwards; 75 | } 76 | 77 | .modalLeave { 78 | animation: modalLeave 0.2s ease-in forwards; 79 | } 80 | -------------------------------------------------------------------------------- /resources/ts/src/components/forms/FormDefault.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { Formik, Form, FormikHelpers, FormikValues } from "formik"; 3 | import * as Yup from "yup"; 4 | 5 | // Props 6 | interface FormDefaultProps { 7 | initialValues: T; 8 | validationSchema: Yup.ObjectSchema; 9 | handleSubmit: ( 10 | values: T, 11 | formikHelpers: FormikHelpers 12 | ) => void | Promise; 13 | children: React.ReactNode; 14 | } 15 | 16 | /** 17 | * Email Form element. 18 | * 19 | * @return {JSX.Element} 20 | */ 21 | function FormDefault({ 22 | initialValues, 23 | validationSchema, 24 | handleSubmit, 25 | children, 26 | }: FormDefaultProps) { 27 | return ( 28 | 29 | initialValues={initialValues} 30 | validationSchema={validationSchema} 31 | onSubmit={handleSubmit} 32 | > 33 | {({ isSubmitting, isValid, dirty }) => ( 34 |
35 | {children} 36 | 37 | 44 |
45 | )} 46 | 47 | ); 48 | } 49 | 50 | export default FormDefault; 51 | -------------------------------------------------------------------------------- /tests/Pest.php: -------------------------------------------------------------------------------- 1 | extend(Tests\TestCase::class) 15 | // ->use(Illuminate\Foundation\Testing\RefreshDatabase::class) 16 | ->in('Feature'); 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Expectations 21 | |-------------------------------------------------------------------------- 22 | | 23 | | When you're writing tests, you often need to check that values meet certain conditions. The 24 | | "expect()" function gives you access to a set of "expectations" methods that you can use 25 | | to assert different things. Of course, you may extend the Expectation API at any time. 26 | | 27 | */ 28 | 29 | expect()->extend('toBeOne', function () { 30 | return $this->toBe(1); 31 | }); 32 | 33 | /* 34 | |-------------------------------------------------------------------------- 35 | | Functions 36 | |-------------------------------------------------------------------------- 37 | | 38 | | While Pest is very powerful out-of-the-box, you may have some testing code specific to your 39 | | project that you don't want to repeat in every file. Here you can also expose helpers as 40 | | global functions to help you to reduce the number of lines of code in your test files. 41 | | 42 | */ 43 | 44 | function something() 45 | { 46 | // .. 47 | } 48 | -------------------------------------------------------------------------------- /database/migrations/0001_01_01_000000_create_users_table.php: -------------------------------------------------------------------------------- 1 | id(); 17 | $table->string('name'); 18 | $table->string('username')->unique(); 19 | $table->enum('rol', Rol::values()); 20 | $table->boolean('is_active')->default(true); 21 | $table->string('password'); 22 | $table->rememberToken(); 23 | $table->timestamps(); 24 | }); 25 | 26 | Schema::create('password_reset_tokens', function (Blueprint $table) { 27 | $table->string('email')->primary(); 28 | $table->string('token'); 29 | $table->timestamp('created_at')->nullable(); 30 | }); 31 | 32 | Schema::create('sessions', function (Blueprint $table) { 33 | $table->string('id')->primary(); 34 | $table->foreignId('user_id')->nullable()->index(); 35 | $table->string('ip_address', 45)->nullable(); 36 | $table->text('user_agent')->nullable(); 37 | $table->longText('payload'); 38 | $table->integer('last_activity')->index(); 39 | }); 40 | } 41 | 42 | /** 43 | * Reverse the migrations. 44 | */ 45 | public function down(): void 46 | { 47 | Schema::dropIfExists('users'); 48 | Schema::dropIfExists('password_reset_tokens'); 49 | Schema::dropIfExists('sessions'); 50 | } 51 | }; 52 | -------------------------------------------------------------------------------- /resources/ts/src/pages/others/ExampleModalPage.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { useThemeApp } from "../../hooks/useThemeApp"; 3 | import ModalDefault from "../../components/modals/ModalDefault"; 4 | 5 | /** 6 | * Pagina para probar el modal 7 | * 8 | * @returns {JSX.Element} 9 | */ 10 | const ExampleModalPage: React.FC = () => { 11 | // Variables 12 | const [isOpen, setIsOpen] = React.useState(false); 13 | 14 | // Variables redux 15 | const { isThemeDark } = useThemeApp(); 16 | 17 | return ( 18 |
19 | {/* Header */} 20 |

Modal

21 | {/* Message */} 22 |

23 | Example of the use a modal in this template 24 |

25 | 26 | {/* Botón para abrir el modal */} 27 | 35 | 36 | {/* Modal */} 37 | setIsOpen(!isOpen) }} 39 | title="Header Modal" 40 | closeOnBackdropClick 41 | isThemeDark={isThemeDark} 42 | > 43 |
44 |

Hello word

45 |
46 |
47 |
48 | ); 49 | }; 50 | 51 | export default ExampleModalPage; 52 | -------------------------------------------------------------------------------- /database/migrations/0001_01_01_000002_create_jobs_table.php: -------------------------------------------------------------------------------- 1 | id(); 16 | $table->string('queue')->index(); 17 | $table->longText('payload'); 18 | $table->unsignedTinyInteger('attempts'); 19 | $table->unsignedInteger('reserved_at')->nullable(); 20 | $table->unsignedInteger('available_at'); 21 | $table->unsignedInteger('created_at'); 22 | }); 23 | 24 | Schema::create('job_batches', function (Blueprint $table) { 25 | $table->string('id')->primary(); 26 | $table->string('name'); 27 | $table->integer('total_jobs'); 28 | $table->integer('pending_jobs'); 29 | $table->integer('failed_jobs'); 30 | $table->longText('failed_job_ids'); 31 | $table->mediumText('options')->nullable(); 32 | $table->integer('cancelled_at')->nullable(); 33 | $table->integer('created_at'); 34 | $table->integer('finished_at')->nullable(); 35 | }); 36 | 37 | Schema::create('failed_jobs', function (Blueprint $table) { 38 | $table->id(); 39 | $table->string('uuid')->unique(); 40 | $table->text('connection'); 41 | $table->text('queue'); 42 | $table->longText('payload'); 43 | $table->longText('exception'); 44 | $table->timestamp('failed_at')->useCurrent(); 45 | }); 46 | } 47 | 48 | /** 49 | * Reverse the migrations. 50 | */ 51 | public function down(): void 52 | { 53 | Schema::dropIfExists('jobs'); 54 | Schema::dropIfExists('job_batches'); 55 | Schema::dropIfExists('failed_jobs'); 56 | } 57 | }; 58 | -------------------------------------------------------------------------------- /resources/ts/src/pages/others/ExampleFormPage.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import * as Yup from "yup"; 3 | import FormDefault from "../../components/forms/FormDefault"; 4 | import InputDefault from "../../components/inputs/InputDefault"; 5 | import toast from "react-hot-toast"; 6 | 7 | /** 8 | * Validations Formik 9 | * 10 | */ 11 | const validationSchema = Yup.object().shape({ 12 | affair: Yup.string().required("The affair is required"), 13 | message: Yup.string().required("The message is required"), 14 | phone: Yup.string() 15 | .required("The phone is required") 16 | .matches(/^\d+$/, "Just numbers are allowed"), 17 | }); 18 | 19 | const initialValues = { 20 | affair: "", 21 | message: "", 22 | phone: "", 23 | }; 24 | 25 | /** 26 | * ExampleFormPage component 27 | * 28 | * @returns {JSX.Element} 29 | */ 30 | const ExampleFormPage: React.FC = () => { 31 | // Action form 32 | const handleSubmit = React.useCallback( 33 | (values: typeof initialValues, { setSubmitting, resetForm }: any) => { 34 | console.log("Values send:", values); 35 | setTimeout(() => { 36 | toast.success("Form sent successfully"); 37 | setSubmitting(false); 38 | resetForm(); 39 | }, 2000); 40 | }, 41 | [] 42 | ); 43 | 44 | return ( 45 |
46 | {/* Header */} 47 |

Form

48 | {/* Message */} 49 |

50 | Example of the use a form in this template 51 |

52 | 53 | {/* Form */} 54 | 59 | 60 | 61 | 62 | 63 |
64 | ); 65 | }; 66 | 67 | export default ExampleFormPage; 68 | -------------------------------------------------------------------------------- /app/Helpers/AuthenticationHelper.php: -------------------------------------------------------------------------------- 1 | value, Permiso::values())) { 28 | throw new InvalidArgumentException('El permiso proporcionado no es válido.'); 29 | } 30 | 31 | // Verifica si el usuario tiene permiso 32 | $authorized = self::userHasPermission($permiso->value, $x_header_id_user); 33 | 34 | // ? No tiene permiso 35 | if (!$authorized) { 36 | throw new InvalidArgumentException('No tienes permisos para realizar esta acción.'); 37 | } 38 | 39 | return true; 40 | 41 | // ! Error 42 | } catch (\Throwable $th) { 43 | throw new HttpResponseException(response()->json([ 44 | 'error' => $th->getMessage() 45 | ], 422)); 46 | } 47 | } 48 | 49 | /** 50 | * Verifica si el usuario tiene el permiso para esta acción. 51 | * 52 | * @param string $permiso 53 | * @param string $id_user 54 | * @return bool 55 | */ 56 | public static function userHasPermission(string $permiso, string $id_user): bool 57 | { 58 | // Obtenemos usuario 59 | $user = User::find($id_user); 60 | 61 | // Verifica si el usuario existe 62 | if (!$user) { 63 | throw new InvalidArgumentException('El usuario con el ID proporcionado no existe.'); 64 | } 65 | 66 | // ? Es super usuario 67 | if ($user->hasRole(Rol::SUPER_ADMIN)) { 68 | return true; 69 | } 70 | 71 | // Tiene el permiso 72 | return $user->hasPermissionTo($permiso); 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /resources/ts/src/components/inputs/InputDefault.tsx: -------------------------------------------------------------------------------- 1 | import React, { DetailedHTMLProps } from "react"; 2 | import { Field, ErrorMessage, useFormikContext } from "formik"; 3 | 4 | /** 5 | * Props for the component 6 | */ 7 | interface InputDefaultProps 8 | extends DetailedHTMLProps< 9 | React.InputHTMLAttributes, 10 | HTMLInputElement 11 | > { 12 | name: string; 13 | label: string; 14 | regex?: RegExp; 15 | errorMessage?: string; 16 | } 17 | 18 | /** 19 | * Default input. 20 | * 21 | * @return {JSX.Element} 22 | */ 23 | const InputDefault: React.FC = ({ 24 | name, 25 | label, 26 | regex, 27 | errorMessage = "Formato inválido", 28 | ...props 29 | }) => { 30 | // Formik context hooks 31 | const { values, setFieldError, setFieldTouched } = useFormikContext<{ 32 | [key: string]: string; 33 | }>(); 34 | 35 | // Custom validation function 36 | const validate = React.useCallback( 37 | (value: string) => { 38 | // ? Vació 39 | if (!value || value.length === 0) return "Campo requerido"; 40 | 41 | // ? Regex validation 42 | if (regex && !regex.test(value)) return errorMessage; 43 | 44 | // No errors 45 | return undefined; 46 | }, 47 | [errorMessage, regex] 48 | ); 49 | 50 | // Handle field blur event 51 | const handleBlur = React.useCallback(() => { 52 | // Validate field on blur event 53 | setFieldTouched(name, true); 54 | // Get error from validation function and set it to field error if exists 55 | const error = validate(values[name]); 56 | // ? Error detecte 57 | if (error) setFieldError(name, error); 58 | }, [name, setFieldError, setFieldTouched, validate, values]); 59 | 60 | return ( 61 |
62 | {/* Label of element */} 63 | 66 | {/* Input element */} 67 | 73 | {/* Error message */} 74 | 79 |
80 | ); 81 | }; 82 | 83 | export default InputDefault; 84 | -------------------------------------------------------------------------------- /database/seeders/RolesAndPermissionsSeeder.php: -------------------------------------------------------------------------------- 1 | value => [ 24 | Permiso::SUPER_ADMIN->value, 25 | ], 26 | // Administrador 27 | Rol::ADMIN->value => [ 28 | // USUARIOS 29 | Permiso::CREAR_USUARIO->value, 30 | Permiso::EDITAR_USUARIO->value, 31 | Permiso::ELIMINAR_USUARIO->value, 32 | Permiso::LISTAR_USUARIOS->value, 33 | Permiso::ACTIVAR_USUARIO->value, 34 | Permiso::DESACTIVAR_USUARIO->value, 35 | Permiso::VER_USUARIO->value, 36 | ], 37 | // Ninguno 38 | Rol::NONE->value => [], 39 | ]; 40 | 41 | /** 42 | * Ejecuta las semilla de la base de datos. 43 | * 44 | * @return void 45 | */ 46 | public function run() 47 | { 48 | collect(self::$roles_usuarios_app)->each(function ($permisos, $rol) { 49 | 50 | try { 51 | // Verificamos si el rol ya existe 52 | $existingRole = Role::where('name', $rol)->where('guard_name', 'web')->first(); 53 | 54 | // ? No existe 55 | if (!$existingRole) { 56 | // Creamos el rol 57 | $role = Role::create(['name' => $rol]); 58 | 59 | // Asignamos permiso 60 | collect($permisos)->each(function ($permiso) use ($role) { 61 | Permission::firstOrCreate(['name' => $permiso, 'guard_name' => 'web']); 62 | $role->givePermissionTo($permiso); 63 | }); 64 | } else { 65 | // Asignamos permiso 66 | $existingRole->syncPermissions($permisos); 67 | } 68 | 69 | // ! Error 70 | } catch (\Exception $e) { 71 | echo "Error al crear rol: " . $e->getMessage(); 72 | } 73 | }); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /app/Models/User.php: -------------------------------------------------------------------------------- 1 | 54 | */ 55 | protected $fillable = [ 56 | 'name', 57 | 'username', 58 | 'password', 59 | 'rol', 60 | 'is_active' 61 | ]; 62 | 63 | /** 64 | * Atributos ocultos 65 | * @var array 66 | */ 67 | protected $hidden = [ 68 | 'is_active', 69 | 'password', 70 | 'remember_token', 71 | 'updated_at', 72 | 'created_at', 73 | ]; 74 | 75 | /** 76 | * Atributos convertidos 77 | * @var array 78 | */ 79 | protected $casts = [ 80 | 'is_active' => 'boolean', 81 | 'password' => 'hashed', 82 | ]; 83 | 84 | /** 85 | * Obtener los atributos que deben de ser convertidos. 86 | * 87 | * @return array 88 | */ 89 | protected function casts(): array 90 | { 91 | return [ 92 | 'is_active' => 'boolean', 93 | 'password' => 'hashed', 94 | ]; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://getcomposer.org/schema.json", 3 | "name": "laravel/laravel", 4 | "type": "project", 5 | "description": "The skeleton application for the Laravel framework.", 6 | "keywords": [ 7 | "laravel", 8 | "framework" 9 | ], 10 | "license": "MIT", 11 | "require": { 12 | "php": "^8.2", 13 | "inertiajs/inertia-laravel": "^2.0", 14 | "laravel/framework": "^12.0", 15 | "laravel/sanctum": "^4.0", 16 | "laravel/tinker": "^2.10.1", 17 | "spatie/laravel-permission": "^6.16" 18 | }, 19 | "require-dev": { 20 | "fakerphp/faker": "^1.23", 21 | "laravel/pail": "^1.2.2", 22 | "laravel/pint": "^1.13", 23 | "laravel/sail": "^1.41", 24 | "mockery/mockery": "^1.6", 25 | "nunomaduro/collision": "^8.6", 26 | "pestphp/pest": "^3.8", 27 | "pestphp/pest-plugin-laravel": "^3.1" 28 | }, 29 | "autoload": { 30 | "psr-4": { 31 | "App\\": "app/", 32 | "Database\\Factories\\": "database/factories/", 33 | "Database\\Seeders\\": "database/seeders/" 34 | } 35 | }, 36 | "autoload-dev": { 37 | "psr-4": { 38 | "Tests\\": "tests/" 39 | } 40 | }, 41 | "scripts": { 42 | "post-autoload-dump": [ 43 | "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump", 44 | "@php artisan package:discover --ansi" 45 | ], 46 | "post-update-cmd": [ 47 | "@php artisan vendor:publish --tag=laravel-assets --ansi --force" 48 | ], 49 | "post-root-package-install": [ 50 | "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"" 51 | ], 52 | "post-create-project-cmd": [ 53 | "@php artisan key:generate --ansi", 54 | "@php -r \"file_exists('database/database.sqlite') || touch('database/database.sqlite');\"", 55 | "@php artisan migrate --graceful --ansi" 56 | ], 57 | "dev": [ 58 | "Composer\\Config::disableProcessTimeout", 59 | "npx concurrently -c \"#93c5fd,#c4b5fd,#fdba74\" \"php artisan serve\" \"php artisan queue:listen --tries=1\" \"npm run dev\" --names='server,queue,vite'" 60 | ] 61 | }, 62 | "extra": { 63 | "laravel": { 64 | "dont-discover": [] 65 | } 66 | }, 67 | "config": { 68 | "optimize-autoloader": true, 69 | "preferred-install": "dist", 70 | "sort-packages": true, 71 | "allow-plugins": { 72 | "pestphp/pest-plugin": true, 73 | "php-http/discovery": true 74 | } 75 | }, 76 | "minimum-stability": "stable", 77 | "prefer-stable": true 78 | } 79 | -------------------------------------------------------------------------------- /config/filesystems.php: -------------------------------------------------------------------------------- 1 | env('FILESYSTEM_DISK', 'local'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Filesystem Disks 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Below you may configure as many filesystem disks as necessary, and you 24 | | may even configure multiple disks for the same driver. Examples for 25 | | most supported storage drivers are configured here for reference. 26 | | 27 | | Supported drivers: "local", "ftp", "sftp", "s3" 28 | | 29 | */ 30 | 31 | 'disks' => [ 32 | 33 | 'local' => [ 34 | 'driver' => 'local', 35 | 'root' => storage_path('app/private'), 36 | 'serve' => true, 37 | 'throw' => false, 38 | 'report' => false, 39 | ], 40 | 41 | 'public' => [ 42 | 'driver' => 'local', 43 | 'root' => storage_path('app/public'), 44 | 'url' => env('APP_URL').'/storage', 45 | 'visibility' => 'public', 46 | 'throw' => false, 47 | 'report' => false, 48 | ], 49 | 50 | 's3' => [ 51 | 'driver' => 's3', 52 | 'key' => env('AWS_ACCESS_KEY_ID'), 53 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 54 | 'region' => env('AWS_DEFAULT_REGION'), 55 | 'bucket' => env('AWS_BUCKET'), 56 | 'url' => env('AWS_URL'), 57 | 'endpoint' => env('AWS_ENDPOINT'), 58 | 'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false), 59 | 'throw' => false, 60 | 'report' => false, 61 | ], 62 | 63 | ], 64 | 65 | /* 66 | |-------------------------------------------------------------------------- 67 | | Symbolic Links 68 | |-------------------------------------------------------------------------- 69 | | 70 | | Here you may configure the symbolic links that will be created when the 71 | | `storage:link` Artisan command is executed. The array keys should be 72 | | the locations of the links and the values should be their targets. 73 | | 74 | */ 75 | 76 | 'links' => [ 77 | public_path('storage') => storage_path('app/public'), 78 | ], 79 | 80 | ]; 81 | -------------------------------------------------------------------------------- /database/seeders/UserSeeder.php: -------------------------------------------------------------------------------- 1 | 'Usuario develop', 30 | 'username' => 'root', 31 | 'rol' => Rol::SUPER_ADMIN->value, 32 | ], 33 | // ADMINISTRADOR 34 | [ 35 | 'name' => 'Eric Salazar Alvarez', 36 | 'username' => 'eriC17', 37 | 'rol' => Rol::ADMIN->value, 38 | ] 39 | ]; 40 | 41 | 42 | private User $user; 43 | 44 | /** 45 | * SexoSeeder constructor. 46 | * @param User user 47 | */ 48 | public function __construct( 49 | User $user 50 | ) { 51 | $this->user = $user; 52 | } 53 | 54 | /** 55 | * Ejecuta las semilla de la base de datos. 56 | * 57 | * @return void 58 | */ 59 | public function run(): void 60 | { 61 | collect(self::$datos)->each(function ($data) { 62 | 63 | try { 64 | 65 | // Obtenemos rol 66 | $rol = Role::where('name', $data['rol'] ?? Rol::NONE->value)->first(); 67 | 68 | // ? Existe 69 | if ($rol) { 70 | 71 | // Creamos user 72 | $user = $this->user::create([ 73 | 'name' => $data['name'] ?? "N/A", 74 | 'username' => $data['username'], 75 | 'password' => Hash::make($data['password'] ?? self::$password_static), 76 | 'rol' => $data['rol'] ?? Rol::NONE->value, 77 | ]); 78 | 79 | 80 | // Asignamos 81 | $user->assignRole($rol); 82 | 83 | // Asignamos permisos asociados al rol 84 | $permisosRol = $rol->permissions()->pluck('name')->toArray(); 85 | $user->givePermissionTo($permisosRol); 86 | } else { 87 | $nombre = $data['nombre'] ?? "N/A"; 88 | echo "Error: El rol de '{$nombre}' no existe. Usuario no creado.\n"; 89 | } 90 | 91 | // ! Error 92 | } catch (\Exception $e) { 93 | echo "\nError al crear usuario: " . $e->getMessage(); 94 | } 95 | }); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /config/sanctum.php: -------------------------------------------------------------------------------- 1 | explode(',', env('SANCTUM_STATEFUL_DOMAINS', sprintf( 19 | '%s%s', 20 | 'localhost,localhost:3000,127.0.0.1,127.0.0.1:8000,::1', 21 | Sanctum::currentApplicationUrlWithPort() 22 | ))), 23 | 24 | /* 25 | |-------------------------------------------------------------------------- 26 | | Sanctum Guards 27 | |-------------------------------------------------------------------------- 28 | | 29 | | This array contains the authentication guards that will be checked when 30 | | Sanctum is trying to authenticate a request. If none of these guards 31 | | are able to authenticate the request, Sanctum will use the bearer 32 | | token that's present on an incoming request for authentication. 33 | | 34 | */ 35 | 36 | 'guard' => ['web'], 37 | 38 | /* 39 | |-------------------------------------------------------------------------- 40 | | Expiration Minutes 41 | |-------------------------------------------------------------------------- 42 | | 43 | | This value controls the number of minutes until an issued token will be 44 | | considered expired. This will override any values set in the token's 45 | | "expires_at" attribute, but first-party sessions are not affected. 46 | | 47 | */ 48 | 49 | 'expiration' => null, 50 | 51 | /* 52 | |-------------------------------------------------------------------------- 53 | | Token Prefix 54 | |-------------------------------------------------------------------------- 55 | | 56 | | Sanctum can prefix new tokens in order to take advantage of numerous 57 | | security scanning initiatives maintained by open source platforms 58 | | that notify developers if they commit tokens into repositories. 59 | | 60 | | See: https://docs.github.com/en/code-security/secret-scanning/about-secret-scanning 61 | | 62 | */ 63 | 64 | 'token_prefix' => env('SANCTUM_TOKEN_PREFIX', ''), 65 | 66 | /* 67 | |-------------------------------------------------------------------------- 68 | | Sanctum Middleware 69 | |-------------------------------------------------------------------------- 70 | | 71 | | When authenticating your first-party SPA with Sanctum you may need to 72 | | customize some of the middleware Sanctum uses while processing the 73 | | request. You may change the middleware listed below as required. 74 | | 75 | */ 76 | 77 | 'middleware' => [ 78 | 'authenticate_session' => Laravel\Sanctum\Http\Middleware\AuthenticateSession::class, 79 | 'encrypt_cookies' => Illuminate\Cookie\Middleware\EncryptCookies::class, 80 | 'validate_csrf_token' => Illuminate\Foundation\Http\Middleware\ValidateCsrfToken::class, 81 | ], 82 | 83 | ]; 84 | -------------------------------------------------------------------------------- /resources/ts/src/pages/others/TemplateTestPage.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import toast from "react-hot-toast"; 3 | import { useReduxDispatch } from "../../redux/hook"; 4 | import { useThemeApp } from "../../hooks/useThemeApp"; 5 | import { updateTheme } from "../../redux/slices/themeSlice"; 6 | import { Link } from "@inertiajs/react"; 7 | 8 | // Update state n random 9 | const getRadomNumber = (isSendNotify: boolean = false): number => { 10 | // Get random number 11 | const n = Math.floor(Math.random() * 10000); 12 | 13 | // Notify 14 | isSendNotify && toast.success(`Your random number is ${n}`); 15 | 16 | return n; 17 | }; 18 | 19 | /** 20 | * TemplateTestPage component 21 | * 22 | * @returns {JSX.Element} 23 | */ 24 | const TemplateTestPage: React.FC = () => { 25 | // State 26 | const [randomNumber, setRandomNumber] = React.useState( 27 | getRadomNumber() 28 | ); 29 | 30 | // Variables redux 31 | const reduxDispatch = useReduxDispatch(); 32 | const { isThemeDark } = useThemeApp(); 33 | 34 | return ( 35 |
36 | {/* Title */} 37 |

38 | Hello world in React 19 - Laravel 12 - Inertia - Tailwind 4.0 - Typescript 39 |

40 | 41 | {/* Count */} 42 |

43 | Your random number is {randomNumber} 44 |

45 | 46 |
47 | {/* Button update theme */} 48 | 64 | 65 | {/* Button update n */} 66 | 74 |
75 | 76 | {/* List of routes */} 77 |
78 | {["form", "modal", "404"].map((route, i) => ( 79 | 84 | 85 | {`Go to ${route} example`} 86 | 87 | 88 | ))} 89 |
90 |
91 | ); 92 | }; 93 | 94 | export default TemplateTestPage; 95 | -------------------------------------------------------------------------------- /config/cache.php: -------------------------------------------------------------------------------- 1 | env('CACHE_STORE', 'database'), 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Cache Stores 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may define all of the cache "stores" for your application as 26 | | well as their drivers. You may even define multiple stores for the 27 | | same cache driver to group types of items stored in your caches. 28 | | 29 | | Supported drivers: "array", "database", "file", "memcached", 30 | | "redis", "dynamodb", "octane", "null" 31 | | 32 | */ 33 | 34 | 'stores' => [ 35 | 36 | 'array' => [ 37 | 'driver' => 'array', 38 | 'serialize' => false, 39 | ], 40 | 41 | 'database' => [ 42 | 'driver' => 'database', 43 | 'connection' => env('DB_CACHE_CONNECTION'), 44 | 'table' => env('DB_CACHE_TABLE', 'cache'), 45 | 'lock_connection' => env('DB_CACHE_LOCK_CONNECTION'), 46 | 'lock_table' => env('DB_CACHE_LOCK_TABLE'), 47 | ], 48 | 49 | 'file' => [ 50 | 'driver' => 'file', 51 | 'path' => storage_path('framework/cache/data'), 52 | 'lock_path' => storage_path('framework/cache/data'), 53 | ], 54 | 55 | 'memcached' => [ 56 | 'driver' => 'memcached', 57 | 'persistent_id' => env('MEMCACHED_PERSISTENT_ID'), 58 | 'sasl' => [ 59 | env('MEMCACHED_USERNAME'), 60 | env('MEMCACHED_PASSWORD'), 61 | ], 62 | 'options' => [ 63 | // Memcached::OPT_CONNECT_TIMEOUT => 2000, 64 | ], 65 | 'servers' => [ 66 | [ 67 | 'host' => env('MEMCACHED_HOST', '127.0.0.1'), 68 | 'port' => env('MEMCACHED_PORT', 11211), 69 | 'weight' => 100, 70 | ], 71 | ], 72 | ], 73 | 74 | 'redis' => [ 75 | 'driver' => 'redis', 76 | 'connection' => env('REDIS_CACHE_CONNECTION', 'cache'), 77 | 'lock_connection' => env('REDIS_CACHE_LOCK_CONNECTION', 'default'), 78 | ], 79 | 80 | 'dynamodb' => [ 81 | 'driver' => 'dynamodb', 82 | 'key' => env('AWS_ACCESS_KEY_ID'), 83 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 84 | 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), 85 | 'table' => env('DYNAMODB_CACHE_TABLE', 'cache'), 86 | 'endpoint' => env('DYNAMODB_ENDPOINT'), 87 | ], 88 | 89 | 'octane' => [ 90 | 'driver' => 'octane', 91 | ], 92 | 93 | ], 94 | 95 | /* 96 | |-------------------------------------------------------------------------- 97 | | Cache Key Prefix 98 | |-------------------------------------------------------------------------- 99 | | 100 | | When utilizing the APC, database, memcached, Redis, and DynamoDB cache 101 | | stores, there might be other applications using the same cache. For 102 | | that reason, you may prefix every cache key to avoid collisions. 103 | | 104 | */ 105 | 106 | 'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_cache_'), 107 | 108 | ]; 109 | -------------------------------------------------------------------------------- /config/mail.php: -------------------------------------------------------------------------------- 1 | env('MAIL_MAILER', 'log'), 18 | 19 | /* 20 | |-------------------------------------------------------------------------- 21 | | Mailer Configurations 22 | |-------------------------------------------------------------------------- 23 | | 24 | | Here you may configure all of the mailers used by your application plus 25 | | their respective settings. Several examples have been configured for 26 | | you and you are free to add your own as your application requires. 27 | | 28 | | Laravel supports a variety of mail "transport" drivers that can be used 29 | | when delivering an email. You may specify which one you're using for 30 | | your mailers below. You may also add additional mailers if needed. 31 | | 32 | | Supported: "smtp", "sendmail", "mailgun", "ses", "ses-v2", 33 | | "postmark", "resend", "log", "array", 34 | | "failover", "roundrobin" 35 | | 36 | */ 37 | 38 | 'mailers' => [ 39 | 40 | 'smtp' => [ 41 | 'transport' => 'smtp', 42 | 'scheme' => env('MAIL_SCHEME'), 43 | 'url' => env('MAIL_URL'), 44 | 'host' => env('MAIL_HOST', '127.0.0.1'), 45 | 'port' => env('MAIL_PORT', 2525), 46 | 'username' => env('MAIL_USERNAME'), 47 | 'password' => env('MAIL_PASSWORD'), 48 | 'timeout' => null, 49 | 'local_domain' => env('MAIL_EHLO_DOMAIN', parse_url(env('APP_URL', 'http://localhost'), PHP_URL_HOST)), 50 | ], 51 | 52 | 'ses' => [ 53 | 'transport' => 'ses', 54 | ], 55 | 56 | 'postmark' => [ 57 | 'transport' => 'postmark', 58 | // 'message_stream_id' => env('POSTMARK_MESSAGE_STREAM_ID'), 59 | // 'client' => [ 60 | // 'timeout' => 5, 61 | // ], 62 | ], 63 | 64 | 'resend' => [ 65 | 'transport' => 'resend', 66 | ], 67 | 68 | 'sendmail' => [ 69 | 'transport' => 'sendmail', 70 | 'path' => env('MAIL_SENDMAIL_PATH', '/usr/sbin/sendmail -bs -i'), 71 | ], 72 | 73 | 'log' => [ 74 | 'transport' => 'log', 75 | 'channel' => env('MAIL_LOG_CHANNEL'), 76 | ], 77 | 78 | 'array' => [ 79 | 'transport' => 'array', 80 | ], 81 | 82 | 'failover' => [ 83 | 'transport' => 'failover', 84 | 'mailers' => [ 85 | 'smtp', 86 | 'log', 87 | ], 88 | 'retry_after' => 60, 89 | ], 90 | 91 | 'roundrobin' => [ 92 | 'transport' => 'roundrobin', 93 | 'mailers' => [ 94 | 'ses', 95 | 'postmark', 96 | ], 97 | 'retry_after' => 60, 98 | ], 99 | 100 | ], 101 | 102 | /* 103 | |-------------------------------------------------------------------------- 104 | | Global "From" Address 105 | |-------------------------------------------------------------------------- 106 | | 107 | | You may wish for all emails sent by your application to be sent from 108 | | the same address. Here you may specify a name and address that is 109 | | used globally for all emails that are sent by your application. 110 | | 111 | */ 112 | 113 | 'from' => [ 114 | 'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'), 115 | 'name' => env('MAIL_FROM_NAME', 'Example'), 116 | ], 117 | 118 | ]; 119 | -------------------------------------------------------------------------------- /config/queue.php: -------------------------------------------------------------------------------- 1 | env('QUEUE_CONNECTION', 'database'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Queue Connections 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Here you may configure the connection options for every queue backend 24 | | used by your application. An example configuration is provided for 25 | | each backend supported by Laravel. You're also free to add more. 26 | | 27 | | Drivers: "sync", "database", "beanstalkd", "sqs", "redis", "null" 28 | | 29 | */ 30 | 31 | 'connections' => [ 32 | 33 | 'sync' => [ 34 | 'driver' => 'sync', 35 | ], 36 | 37 | 'database' => [ 38 | 'driver' => 'database', 39 | 'connection' => env('DB_QUEUE_CONNECTION'), 40 | 'table' => env('DB_QUEUE_TABLE', 'jobs'), 41 | 'queue' => env('DB_QUEUE', 'default'), 42 | 'retry_after' => (int) env('DB_QUEUE_RETRY_AFTER', 90), 43 | 'after_commit' => false, 44 | ], 45 | 46 | 'beanstalkd' => [ 47 | 'driver' => 'beanstalkd', 48 | 'host' => env('BEANSTALKD_QUEUE_HOST', 'localhost'), 49 | 'queue' => env('BEANSTALKD_QUEUE', 'default'), 50 | 'retry_after' => (int) env('BEANSTALKD_QUEUE_RETRY_AFTER', 90), 51 | 'block_for' => 0, 52 | 'after_commit' => false, 53 | ], 54 | 55 | 'sqs' => [ 56 | 'driver' => 'sqs', 57 | 'key' => env('AWS_ACCESS_KEY_ID'), 58 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 59 | 'prefix' => env('SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'), 60 | 'queue' => env('SQS_QUEUE', 'default'), 61 | 'suffix' => env('SQS_SUFFIX'), 62 | 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), 63 | 'after_commit' => false, 64 | ], 65 | 66 | 'redis' => [ 67 | 'driver' => 'redis', 68 | 'connection' => env('REDIS_QUEUE_CONNECTION', 'default'), 69 | 'queue' => env('REDIS_QUEUE', 'default'), 70 | 'retry_after' => (int) env('REDIS_QUEUE_RETRY_AFTER', 90), 71 | 'block_for' => null, 72 | 'after_commit' => false, 73 | ], 74 | 75 | ], 76 | 77 | /* 78 | |-------------------------------------------------------------------------- 79 | | Job Batching 80 | |-------------------------------------------------------------------------- 81 | | 82 | | The following options configure the database and table that store job 83 | | batching information. These options can be updated to any database 84 | | connection and table which has been defined by your application. 85 | | 86 | */ 87 | 88 | 'batching' => [ 89 | 'database' => env('DB_CONNECTION', 'sqlite'), 90 | 'table' => 'job_batches', 91 | ], 92 | 93 | /* 94 | |-------------------------------------------------------------------------- 95 | | Failed Queue Jobs 96 | |-------------------------------------------------------------------------- 97 | | 98 | | These options configure the behavior of failed queue job logging so you 99 | | can control how and where failed jobs are stored. Laravel ships with 100 | | support for storing failed jobs in a simple file or in a database. 101 | | 102 | | Supported drivers: "database-uuids", "dynamodb", "file", "null" 103 | | 104 | */ 105 | 106 | 'failed' => [ 107 | 'driver' => env('QUEUE_FAILED_DRIVER', 'database-uuids'), 108 | 'database' => env('DB_CONNECTION', 'sqlite'), 109 | 'table' => 'failed_jobs', 110 | ], 111 | 112 | ]; 113 | -------------------------------------------------------------------------------- /config/auth.php: -------------------------------------------------------------------------------- 1 | [ 17 | 'guard' => env('AUTH_GUARD', 'web'), 18 | 'passwords' => env('AUTH_PASSWORD_BROKER', 'users'), 19 | ], 20 | 21 | /* 22 | |-------------------------------------------------------------------------- 23 | | Authentication Guards 24 | |-------------------------------------------------------------------------- 25 | | 26 | | Next, you may define every authentication guard for your application. 27 | | Of course, a great default configuration has been defined for you 28 | | which utilizes session storage plus the Eloquent user provider. 29 | | 30 | | All authentication guards have a user provider, which defines how the 31 | | users are actually retrieved out of your database or other storage 32 | | system used by the application. Typically, Eloquent is utilized. 33 | | 34 | | Supported: "session" 35 | | 36 | */ 37 | 38 | 'guards' => [ 39 | 'web' => [ 40 | 'driver' => 'session', 41 | 'provider' => 'users', 42 | ], 43 | ], 44 | 45 | /* 46 | |-------------------------------------------------------------------------- 47 | | User Providers 48 | |-------------------------------------------------------------------------- 49 | | 50 | | All authentication guards have a user provider, which defines how the 51 | | users are actually retrieved out of your database or other storage 52 | | system used by the application. Typically, Eloquent is utilized. 53 | | 54 | | If you have multiple user tables or models you may configure multiple 55 | | providers to represent the model / table. These providers may then 56 | | be assigned to any extra authentication guards you have defined. 57 | | 58 | | Supported: "database", "eloquent" 59 | | 60 | */ 61 | 62 | 'providers' => [ 63 | 'users' => [ 64 | 'driver' => 'eloquent', 65 | 'model' => env('AUTH_MODEL', App\Models\User::class), 66 | ], 67 | 68 | // 'users' => [ 69 | // 'driver' => 'database', 70 | // 'table' => 'users', 71 | // ], 72 | ], 73 | 74 | /* 75 | |-------------------------------------------------------------------------- 76 | | Resetting Passwords 77 | |-------------------------------------------------------------------------- 78 | | 79 | | These configuration options specify the behavior of Laravel's password 80 | | reset functionality, including the table utilized for token storage 81 | | and the user provider that is invoked to actually retrieve users. 82 | | 83 | | The expiry time is the number of minutes that each reset token will be 84 | | considered valid. This security feature keeps tokens short-lived so 85 | | they have less time to be guessed. You may change this as needed. 86 | | 87 | | The throttle setting is the number of seconds a user must wait before 88 | | generating more password reset tokens. This prevents the user from 89 | | quickly generating a very large amount of password reset tokens. 90 | | 91 | */ 92 | 93 | 'passwords' => [ 94 | 'users' => [ 95 | 'provider' => 'users', 96 | 'table' => env('AUTH_PASSWORD_RESET_TOKEN_TABLE', 'password_reset_tokens'), 97 | 'expire' => 60, 98 | 'throttle' => 60, 99 | ], 100 | ], 101 | 102 | /* 103 | |-------------------------------------------------------------------------- 104 | | Password Confirmation Timeout 105 | |-------------------------------------------------------------------------- 106 | | 107 | | Here you may define the amount of seconds before a password confirmation 108 | | window expires and users are asked to re-enter their password via the 109 | | confirmation screen. By default, the timeout lasts for three hours. 110 | | 111 | */ 112 | 113 | 'password_timeout' => env('AUTH_PASSWORD_TIMEOUT', 10800), 114 | 115 | ]; 116 | -------------------------------------------------------------------------------- /app/Services/MailService.php: -------------------------------------------------------------------------------- 1 | $mailers 13 | */ 14 | private $mailers = ["smtp", "smtp_2", "smtp_3", "smtp_4"]; 15 | 16 | /** 17 | * @var string $nameMailerCache 18 | */ 19 | private $nameMailerCache = "current_mailer_index"; 20 | 21 | /** 22 | * Enviar invitacion unica por email 23 | * 24 | * @throws \Exception 25 | * 26 | * @return void 27 | */ 28 | // public function sendInvitationUnica(InvitacionUnica $invitacion): void 29 | // { 30 | // try { 31 | // // Obtenemos datos 32 | // $refCrypt = $invitacion->referencia_encriptada; 33 | // $invitado = $invitacion->invitado; 34 | 35 | // // ? No existe referencia 36 | // if (!$refCrypt) { 37 | // throw new Exception("La referencia no fue encontrada"); 38 | // } 39 | 40 | // // ? No existe invitado 41 | // if (!$invitado) { 42 | // throw new Exception("El invitado no fue encontrado"); 43 | // } 44 | 45 | // // Obtenemos la URL de la invitacion 46 | // $url = $this->getUrlInvitacionEmail("un", $refCrypt); 47 | 48 | // // Enviamos el email 49 | // $this->sendInvitation("15240863@uagro.mx", $url, $invitado->nombre); // PRUEBAS 50 | // // $this->sendInvitation($invitado->email, $url, $invitado->nombre); // PRODUCCIÓN 51 | 52 | // // Actualizamos el registro de emails enviados 53 | // $invitado->update([ 54 | // 'emails_enviados' => $invitado->emails_enviados + 1, 55 | // ]); 56 | // } catch (\Throwable $th) { 57 | // throw new Exception("Error al enviar el email, " . $th->getMessage()); 58 | // } 59 | // } 60 | 61 | 62 | /** 63 | * Obtener url de la invitacion 64 | * 65 | * @throws \Exception 66 | * 67 | * @param string $tipo [un | mt] 68 | * @param string $ref 69 | * 70 | * @return string 71 | */ 72 | private function getUrlInvitacionEmail(string $tipo, string $ref): string 73 | { 74 | 75 | // Obtenemos url del frondEnd 76 | $urlFrond = env("URL_FROND_END"); 77 | 78 | // ? Existe url o la url no es valida 79 | if (!$urlFrond || !filter_var($urlFrond, FILTER_VALIDATE_URL)) { 80 | throw new Exception("La URL del frontend no es válida o no está configurada"); 81 | } 82 | 83 | // Creamos url 84 | $url = $urlFrond . "/invitacion?tp=" . $tipo . "&ref=" . $ref; 85 | 86 | // ? La url es valida 87 | if (filter_var($url, FILTER_VALIDATE_URL)) { 88 | return $url; 89 | } 90 | 91 | // ! Error 92 | throw new Exception("No se encontró la url a la pagina principal"); 93 | } 94 | 95 | /** 96 | * Enviar invitacion por email 97 | * 98 | * @throws \Exception 99 | * 100 | * @param string $url 101 | * @param ?string $nombre 102 | * 103 | * @return void 104 | */ 105 | // private function sendInvitation(string $destinatario, string $url, ?string $nombre = null): void 106 | // { 107 | // try { 108 | // // Obtener el mailer en orden 109 | // $mailer = $this->getNextMailer(); 110 | 111 | // // Enviar el correo 112 | // // Mail::mailer($mailer)->to($destinatario)->send(new InvitationMail($url, $nombre)); 113 | 114 | // // ! Error 115 | // } catch (\Throwable $th) { 116 | // throw new Exception($th->getMessage()); 117 | // } 118 | // } 119 | 120 | /** 121 | * Obtener el siguiente mailer en orden 122 | * 123 | * @return string 124 | */ 125 | private function getNextMailer(): string 126 | { 127 | // Obtener el índice actual de mailer de la caché o 0 si no existe 128 | $currentMailerIndex = Cache::get($this->nameMailerCache, 0); 129 | 130 | // Obtener el mailer correspondiente 131 | $nextMailer = isset($this->mailers[$currentMailerIndex]) 132 | ? $this->mailers[$currentMailerIndex] 133 | : $this->mailers[0]; 134 | 135 | // Calcular el próximo índice 136 | $nextMailerIndex = ($currentMailerIndex + 1) % count($this->mailers); 137 | 138 | // Guardar el próximo índice en la caché 139 | Cache::put($this->nameMailerCache, $nextMailerIndex); 140 | 141 | return $nextMailer; 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /config/app.php: -------------------------------------------------------------------------------- 1 | env('APP_NAME', 'Laravel'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Application Environment 21 | |-------------------------------------------------------------------------- 22 | | 23 | | This value determines the "environment" your application is currently 24 | | running in. This may determine how you prefer to configure various 25 | | services the application utilizes. Set this in your ".env" file. 26 | | 27 | */ 28 | 29 | 'env' => env('APP_ENV', 'production'), 30 | 31 | /* 32 | |-------------------------------------------------------------------------- 33 | | Application Debug Mode 34 | |-------------------------------------------------------------------------- 35 | | 36 | | When your application is in debug mode, detailed error messages with 37 | | stack traces will be shown on every error that occurs within your 38 | | application. If disabled, a simple generic error page is shown. 39 | | 40 | */ 41 | 42 | 'debug' => (bool) env('APP_DEBUG', false), 43 | 44 | /* 45 | |-------------------------------------------------------------------------- 46 | | Application URL 47 | |-------------------------------------------------------------------------- 48 | | 49 | | This URL is used by the console to properly generate URLs when using 50 | | the Artisan command line tool. You should set this to the root of 51 | | the application so that it's available within Artisan commands. 52 | | 53 | */ 54 | 55 | 'url' => env('APP_URL', 'http://localhost'), 56 | 57 | /* 58 | |-------------------------------------------------------------------------- 59 | | Application Timezone 60 | |-------------------------------------------------------------------------- 61 | | 62 | | Here you may specify the default timezone for your application, which 63 | | will be used by the PHP date and date-time functions. The timezone 64 | | is set to "UTC" by default as it is suitable for most use cases. 65 | | 66 | */ 67 | 68 | 'timezone' => 'UTC', 69 | 70 | /* 71 | |-------------------------------------------------------------------------- 72 | | Application Locale Configuration 73 | |-------------------------------------------------------------------------- 74 | | 75 | | The application locale determines the default locale that will be used 76 | | by Laravel's translation / localization methods. This option can be 77 | | set to any locale for which you plan to have translation strings. 78 | | 79 | */ 80 | 81 | 'locale' => env('APP_LOCALE', 'en'), 82 | 83 | 'fallback_locale' => env('APP_FALLBACK_LOCALE', 'en'), 84 | 85 | 'faker_locale' => env('APP_FAKER_LOCALE', 'en_US'), 86 | 87 | /* 88 | |-------------------------------------------------------------------------- 89 | | Encryption Key 90 | |-------------------------------------------------------------------------- 91 | | 92 | | This key is utilized by Laravel's encryption services and should be set 93 | | to a random, 32 character string to ensure that all encrypted values 94 | | are secure. You should do this prior to deploying the application. 95 | | 96 | */ 97 | 98 | 'cipher' => 'AES-256-CBC', 99 | 100 | 'key' => env('APP_KEY'), 101 | 102 | 'previous_keys' => [ 103 | ...array_filter( 104 | explode(',', env('APP_PREVIOUS_KEYS', '')) 105 | ), 106 | ], 107 | 108 | /* 109 | |-------------------------------------------------------------------------- 110 | | Maintenance Mode Driver 111 | |-------------------------------------------------------------------------- 112 | | 113 | | These configuration options determine the driver used to determine and 114 | | manage Laravel's "maintenance mode" status. The "cache" driver will 115 | | allow maintenance mode to be controlled across multiple machines. 116 | | 117 | | Supported drivers: "file", "cache" 118 | | 119 | */ 120 | 121 | 'maintenance' => [ 122 | 'driver' => env('APP_MAINTENANCE_DRIVER', 'file'), 123 | 'store' => env('APP_MAINTENANCE_STORE', 'database'), 124 | ], 125 | 126 | ]; 127 | -------------------------------------------------------------------------------- /config/logging.php: -------------------------------------------------------------------------------- 1 | env('LOG_CHANNEL', 'stack'), 22 | 23 | /* 24 | |-------------------------------------------------------------------------- 25 | | Deprecations Log Channel 26 | |-------------------------------------------------------------------------- 27 | | 28 | | This option controls the log channel that should be used to log warnings 29 | | regarding deprecated PHP and library features. This allows you to get 30 | | your application ready for upcoming major versions of dependencies. 31 | | 32 | */ 33 | 34 | 'deprecations' => [ 35 | 'channel' => env('LOG_DEPRECATIONS_CHANNEL', 'null'), 36 | 'trace' => env('LOG_DEPRECATIONS_TRACE', false), 37 | ], 38 | 39 | /* 40 | |-------------------------------------------------------------------------- 41 | | Log Channels 42 | |-------------------------------------------------------------------------- 43 | | 44 | | Here you may configure the log channels for your application. Laravel 45 | | utilizes the Monolog PHP logging library, which includes a variety 46 | | of powerful log handlers and formatters that you're free to use. 47 | | 48 | | Available drivers: "single", "daily", "slack", "syslog", 49 | | "errorlog", "monolog", "custom", "stack" 50 | | 51 | */ 52 | 53 | 'channels' => [ 54 | 55 | 'stack' => [ 56 | 'driver' => 'stack', 57 | 'channels' => explode(',', env('LOG_STACK', 'single')), 58 | 'ignore_exceptions' => false, 59 | ], 60 | 61 | 'single' => [ 62 | 'driver' => 'single', 63 | 'path' => storage_path('logs/laravel.log'), 64 | 'level' => env('LOG_LEVEL', 'debug'), 65 | 'replace_placeholders' => true, 66 | ], 67 | 68 | 'daily' => [ 69 | 'driver' => 'daily', 70 | 'path' => storage_path('logs/laravel.log'), 71 | 'level' => env('LOG_LEVEL', 'debug'), 72 | 'days' => env('LOG_DAILY_DAYS', 14), 73 | 'replace_placeholders' => true, 74 | ], 75 | 76 | 'slack' => [ 77 | 'driver' => 'slack', 78 | 'url' => env('LOG_SLACK_WEBHOOK_URL'), 79 | 'username' => env('LOG_SLACK_USERNAME', 'Laravel Log'), 80 | 'emoji' => env('LOG_SLACK_EMOJI', ':boom:'), 81 | 'level' => env('LOG_LEVEL', 'critical'), 82 | 'replace_placeholders' => true, 83 | ], 84 | 85 | 'papertrail' => [ 86 | 'driver' => 'monolog', 87 | 'level' => env('LOG_LEVEL', 'debug'), 88 | 'handler' => env('LOG_PAPERTRAIL_HANDLER', SyslogUdpHandler::class), 89 | 'handler_with' => [ 90 | 'host' => env('PAPERTRAIL_URL'), 91 | 'port' => env('PAPERTRAIL_PORT'), 92 | 'connectionString' => 'tls://'.env('PAPERTRAIL_URL').':'.env('PAPERTRAIL_PORT'), 93 | ], 94 | 'processors' => [PsrLogMessageProcessor::class], 95 | ], 96 | 97 | 'stderr' => [ 98 | 'driver' => 'monolog', 99 | 'level' => env('LOG_LEVEL', 'debug'), 100 | 'handler' => StreamHandler::class, 101 | 'handler_with' => [ 102 | 'stream' => 'php://stderr', 103 | ], 104 | 'formatter' => env('LOG_STDERR_FORMATTER'), 105 | 'processors' => [PsrLogMessageProcessor::class], 106 | ], 107 | 108 | 'syslog' => [ 109 | 'driver' => 'syslog', 110 | 'level' => env('LOG_LEVEL', 'debug'), 111 | 'facility' => env('LOG_SYSLOG_FACILITY', LOG_USER), 112 | 'replace_placeholders' => true, 113 | ], 114 | 115 | 'errorlog' => [ 116 | 'driver' => 'errorlog', 117 | 'level' => env('LOG_LEVEL', 'debug'), 118 | 'replace_placeholders' => true, 119 | ], 120 | 121 | 'null' => [ 122 | 'driver' => 'monolog', 123 | 'handler' => NullHandler::class, 124 | ], 125 | 126 | 'emergency' => [ 127 | 'path' => storage_path('logs/laravel.log'), 128 | ], 129 | 130 | ], 131 | 132 | ]; 133 | -------------------------------------------------------------------------------- /resources/ts/src/components/modals/ModalDefault.tsx: -------------------------------------------------------------------------------- 1 | // components/Modal/ModalDefault.tsx 2 | import React from "react"; 3 | import styles from "../../scss/modules/Modal.module.scss"; 4 | 5 | // Props 6 | interface ModalDefaultProps { 7 | children: React.ReactNode; 8 | title?: string; 9 | size?: "sm" | "md" | "lg" | "xl" | "2xl"; 10 | maxHeight?: string; 11 | closeOnBackdropClick?: boolean; 12 | isThemeDark?: boolean; 13 | statusModal: { 14 | isOpen: boolean; 15 | closeModal: () => void; 16 | }; 17 | } 18 | 19 | /** 20 | * Modal por defecto 21 | * 22 | * @param {ModalDefaultProps} props 23 | * 24 | * @returns {JSX.Element} 25 | */ 26 | const ModalDefault: React.FC = ({ 27 | children, 28 | title, 29 | statusModal: { closeModal, isOpen }, 30 | size = "md", 31 | maxHeight = "70vh", 32 | isThemeDark = false, 33 | closeOnBackdropClick = true, 34 | }) => { 35 | // Variables 36 | const [isClosing, setIsClosing] = React.useState(false); 37 | const modalRef = React.useRef(null); 38 | 39 | // Al cerrar el modal 40 | const handleClose = React.useCallback(() => { 41 | setIsClosing(true); 42 | setTimeout(() => { 43 | closeModal(); 44 | setIsClosing(false); 45 | }, 300); 46 | }, [closeModal]); 47 | 48 | // Al hacer click en el fondo 49 | const handleBackdropClick = (e: React.MouseEvent) => { 50 | // ? Si se cierra al hacer click en el fondo 51 | if (closeOnBackdropClick && e.target === e.currentTarget) handleClose(); 52 | }; 53 | 54 | // Efecto para el manejo del modal 55 | React.useEffect(() => { 56 | // Evento para cerrar 57 | const handleKeyDown = (e: KeyboardEvent) => 58 | e.key === "Escape" && handleClose(); 59 | 60 | // ? Esta abierta el modal 61 | if (isOpen) { 62 | // Cambiamos estilos 63 | document.body.style.overflow = "hidden"; 64 | document.documentElement.style.overflow = "hidden"; 65 | const scrollbarWidth = 66 | window.innerWidth - document.documentElement.clientWidth; 67 | document.body.style.paddingRight = `${scrollbarWidth}px`; 68 | 69 | // Evento para cerrar 70 | window.addEventListener("keydown", handleKeyDown); 71 | 72 | // Auto-focus en el primer elemento interactivo 73 | const focusableElements = modalRef.current?.querySelectorAll( 74 | 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])' 75 | ); 76 | 77 | // Auto-focus en el primer elemento interactivo 78 | if (focusableElements?.length) 79 | (focusableElements[0] as HTMLElement).focus(); 80 | } 81 | 82 | return () => { 83 | // Cambiamos estilos 84 | document.body.style.overflow = "auto"; 85 | document.documentElement.style.overflow = "auto"; 86 | document.body.style.paddingRight = ""; 87 | window.removeEventListener("keydown", handleKeyDown); 88 | }; 89 | }, [handleClose, isOpen]); 90 | 91 | // ? Si el modal no está abierto 92 | if (!isOpen) return null; 93 | 94 | return ( 95 |
104 | {/* Modal */} 105 |
e.stopPropagation()} 113 | > 114 | {/* Header */} 115 |
122 | {/* Título */} 123 | 126 | 127 | {/* Botón de cierre */} 128 | 137 |
138 | 139 | {/* Contenido */} 140 | 150 |
151 |
152 | ); 153 | }; 154 | 155 | export default ModalDefault; 156 | -------------------------------------------------------------------------------- /config/database.php: -------------------------------------------------------------------------------- 1 | env('DB_CONNECTION', 'sqlite'), 20 | 21 | /* 22 | |-------------------------------------------------------------------------- 23 | | Database Connections 24 | |-------------------------------------------------------------------------- 25 | | 26 | | Below are all of the database connections defined for your application. 27 | | An example configuration is provided for each database system which 28 | | is supported by Laravel. You're free to add / remove connections. 29 | | 30 | */ 31 | 32 | 'connections' => [ 33 | 34 | 'sqlite' => [ 35 | 'driver' => 'sqlite', 36 | 'url' => env('DB_URL'), 37 | 'database' => env('DB_DATABASE', database_path('database.sqlite')), 38 | 'prefix' => '', 39 | 'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true), 40 | 'busy_timeout' => null, 41 | 'journal_mode' => null, 42 | 'synchronous' => null, 43 | ], 44 | 45 | 'mysql' => [ 46 | 'driver' => 'mysql', 47 | 'url' => env('DB_URL'), 48 | 'host' => env('DB_HOST', '127.0.0.1'), 49 | 'port' => env('DB_PORT', '3306'), 50 | 'database' => env('DB_DATABASE', 'laravel'), 51 | 'username' => env('DB_USERNAME', 'root'), 52 | 'password' => env('DB_PASSWORD', ''), 53 | 'unix_socket' => env('DB_SOCKET', ''), 54 | 'charset' => env('DB_CHARSET', 'utf8mb4'), 55 | 'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'), 56 | 'prefix' => '', 57 | 'prefix_indexes' => true, 58 | 'strict' => true, 59 | 'engine' => null, 60 | 'options' => extension_loaded('pdo_mysql') ? array_filter([ 61 | PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), 62 | ]) : [], 63 | ], 64 | 65 | 'mariadb' => [ 66 | 'driver' => 'mariadb', 67 | 'url' => env('DB_URL'), 68 | 'host' => env('DB_HOST', '127.0.0.1'), 69 | 'port' => env('DB_PORT', '3306'), 70 | 'database' => env('DB_DATABASE', 'laravel'), 71 | 'username' => env('DB_USERNAME', 'root'), 72 | 'password' => env('DB_PASSWORD', ''), 73 | 'unix_socket' => env('DB_SOCKET', ''), 74 | 'charset' => env('DB_CHARSET', 'utf8mb4'), 75 | 'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'), 76 | 'prefix' => '', 77 | 'prefix_indexes' => true, 78 | 'strict' => true, 79 | 'engine' => null, 80 | 'options' => extension_loaded('pdo_mysql') ? array_filter([ 81 | PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), 82 | ]) : [], 83 | ], 84 | 85 | 'pgsql' => [ 86 | 'driver' => 'pgsql', 87 | 'url' => env('DB_URL'), 88 | 'host' => env('DB_HOST', '127.0.0.1'), 89 | 'port' => env('DB_PORT', '5432'), 90 | 'database' => env('DB_DATABASE', 'laravel'), 91 | 'username' => env('DB_USERNAME', 'root'), 92 | 'password' => env('DB_PASSWORD', ''), 93 | 'charset' => env('DB_CHARSET', 'utf8'), 94 | 'prefix' => '', 95 | 'prefix_indexes' => true, 96 | 'search_path' => 'public', 97 | 'sslmode' => 'prefer', 98 | ], 99 | 100 | 'sqlsrv' => [ 101 | 'driver' => 'sqlsrv', 102 | 'url' => env('DB_URL'), 103 | 'host' => env('DB_HOST', 'localhost'), 104 | 'port' => env('DB_PORT', '1433'), 105 | 'database' => env('DB_DATABASE', 'laravel'), 106 | 'username' => env('DB_USERNAME', 'root'), 107 | 'password' => env('DB_PASSWORD', ''), 108 | 'charset' => env('DB_CHARSET', 'utf8'), 109 | 'prefix' => '', 110 | 'prefix_indexes' => true, 111 | // 'encrypt' => env('DB_ENCRYPT', 'yes'), 112 | // 'trust_server_certificate' => env('DB_TRUST_SERVER_CERTIFICATE', 'false'), 113 | ], 114 | 115 | ], 116 | 117 | /* 118 | |-------------------------------------------------------------------------- 119 | | Migration Repository Table 120 | |-------------------------------------------------------------------------- 121 | | 122 | | This table keeps track of all the migrations that have already run for 123 | | your application. Using this information, we can determine which of 124 | | the migrations on disk haven't actually been run on the database. 125 | | 126 | */ 127 | 128 | 'migrations' => [ 129 | 'table' => 'migrations', 130 | 'update_date_on_publish' => true, 131 | ], 132 | 133 | /* 134 | |-------------------------------------------------------------------------- 135 | | Redis Databases 136 | |-------------------------------------------------------------------------- 137 | | 138 | | Redis is an open source, fast, and advanced key-value store that also 139 | | provides a richer body of commands than a typical key-value system 140 | | such as Memcached. You may define your connection settings here. 141 | | 142 | */ 143 | 144 | 'redis' => [ 145 | 146 | 'client' => env('REDIS_CLIENT', 'phpredis'), 147 | 148 | 'options' => [ 149 | 'cluster' => env('REDIS_CLUSTER', 'redis'), 150 | 'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'), 151 | 'persistent' => env('REDIS_PERSISTENT', false), 152 | ], 153 | 154 | 'default' => [ 155 | 'url' => env('REDIS_URL'), 156 | 'host' => env('REDIS_HOST', '127.0.0.1'), 157 | 'username' => env('REDIS_USERNAME'), 158 | 'password' => env('REDIS_PASSWORD'), 159 | 'port' => env('REDIS_PORT', '6379'), 160 | 'database' => env('REDIS_DB', '0'), 161 | ], 162 | 163 | 'cache' => [ 164 | 'url' => env('REDIS_URL'), 165 | 'host' => env('REDIS_HOST', '127.0.0.1'), 166 | 'username' => env('REDIS_USERNAME'), 167 | 'password' => env('REDIS_PASSWORD'), 168 | 'port' => env('REDIS_PORT', '6379'), 169 | 'database' => env('REDIS_CACHE_DB', '1'), 170 | ], 171 | 172 | ], 173 | 174 | ]; 175 | -------------------------------------------------------------------------------- /database/migrations/2025_04_09_195002_create_permission_tables.php: -------------------------------------------------------------------------------- 1 | engine('InnoDB'); 29 | $table->bigIncrements('id'); // permission id 30 | $table->string('name'); // For MyISAM use string('name', 225); // (or 166 for InnoDB with Redundant/Compact row format) 31 | $table->string('guard_name'); // For MyISAM use string('guard_name', 25); 32 | $table->timestamps(); 33 | 34 | $table->unique(['name', 'guard_name']); 35 | }); 36 | 37 | Schema::create($tableNames['roles'], static function (Blueprint $table) use ($teams, $columnNames) { 38 | // $table->engine('InnoDB'); 39 | $table->bigIncrements('id'); // role id 40 | if ($teams || config('permission.testing')) { // permission.testing is a fix for sqlite testing 41 | $table->unsignedBigInteger($columnNames['team_foreign_key'])->nullable(); 42 | $table->index($columnNames['team_foreign_key'], 'roles_team_foreign_key_index'); 43 | } 44 | $table->string('name'); // For MyISAM use string('name', 225); // (or 166 for InnoDB with Redundant/Compact row format) 45 | $table->string('guard_name'); // For MyISAM use string('guard_name', 25); 46 | $table->timestamps(); 47 | if ($teams || config('permission.testing')) { 48 | $table->unique([$columnNames['team_foreign_key'], 'name', 'guard_name']); 49 | } else { 50 | $table->unique(['name', 'guard_name']); 51 | } 52 | }); 53 | 54 | Schema::create($tableNames['model_has_permissions'], static function (Blueprint $table) use ($tableNames, $columnNames, $pivotPermission, $teams) { 55 | $table->unsignedBigInteger($pivotPermission); 56 | 57 | $table->string('model_type'); 58 | $table->unsignedBigInteger($columnNames['model_morph_key']); 59 | $table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_permissions_model_id_model_type_index'); 60 | 61 | $table->foreign($pivotPermission) 62 | ->references('id') // permission id 63 | ->on($tableNames['permissions']) 64 | ->onDelete('cascade'); 65 | if ($teams) { 66 | $table->unsignedBigInteger($columnNames['team_foreign_key']); 67 | $table->index($columnNames['team_foreign_key'], 'model_has_permissions_team_foreign_key_index'); 68 | 69 | $table->primary([$columnNames['team_foreign_key'], $pivotPermission, $columnNames['model_morph_key'], 'model_type'], 70 | 'model_has_permissions_permission_model_type_primary'); 71 | } else { 72 | $table->primary([$pivotPermission, $columnNames['model_morph_key'], 'model_type'], 73 | 'model_has_permissions_permission_model_type_primary'); 74 | } 75 | 76 | }); 77 | 78 | Schema::create($tableNames['model_has_roles'], static function (Blueprint $table) use ($tableNames, $columnNames, $pivotRole, $teams) { 79 | $table->unsignedBigInteger($pivotRole); 80 | 81 | $table->string('model_type'); 82 | $table->unsignedBigInteger($columnNames['model_morph_key']); 83 | $table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_roles_model_id_model_type_index'); 84 | 85 | $table->foreign($pivotRole) 86 | ->references('id') // role id 87 | ->on($tableNames['roles']) 88 | ->onDelete('cascade'); 89 | if ($teams) { 90 | $table->unsignedBigInteger($columnNames['team_foreign_key']); 91 | $table->index($columnNames['team_foreign_key'], 'model_has_roles_team_foreign_key_index'); 92 | 93 | $table->primary([$columnNames['team_foreign_key'], $pivotRole, $columnNames['model_morph_key'], 'model_type'], 94 | 'model_has_roles_role_model_type_primary'); 95 | } else { 96 | $table->primary([$pivotRole, $columnNames['model_morph_key'], 'model_type'], 97 | 'model_has_roles_role_model_type_primary'); 98 | } 99 | }); 100 | 101 | Schema::create($tableNames['role_has_permissions'], static function (Blueprint $table) use ($tableNames, $pivotRole, $pivotPermission) { 102 | $table->unsignedBigInteger($pivotPermission); 103 | $table->unsignedBigInteger($pivotRole); 104 | 105 | $table->foreign($pivotPermission) 106 | ->references('id') // permission id 107 | ->on($tableNames['permissions']) 108 | ->onDelete('cascade'); 109 | 110 | $table->foreign($pivotRole) 111 | ->references('id') // role id 112 | ->on($tableNames['roles']) 113 | ->onDelete('cascade'); 114 | 115 | $table->primary([$pivotPermission, $pivotRole], 'role_has_permissions_permission_id_role_id_primary'); 116 | }); 117 | 118 | app('cache') 119 | ->store(config('permission.cache.store') != 'default' ? config('permission.cache.store') : null) 120 | ->forget(config('permission.cache.key')); 121 | } 122 | 123 | /** 124 | * Reverse the migrations. 125 | */ 126 | public function down(): void 127 | { 128 | $tableNames = config('permission.table_names'); 129 | 130 | if (empty($tableNames)) { 131 | throw new \Exception('Error: config/permission.php not found and defaults could not be merged. Please publish the package configuration before proceeding, or drop the tables manually.'); 132 | } 133 | 134 | Schema::drop($tableNames['role_has_permissions']); 135 | Schema::drop($tableNames['model_has_roles']); 136 | Schema::drop($tableNames['model_has_permissions']); 137 | Schema::drop($tableNames['roles']); 138 | Schema::drop($tableNames['permissions']); 139 | } 140 | }; 141 | -------------------------------------------------------------------------------- /config/permission.php: -------------------------------------------------------------------------------- 1 | [ 6 | 7 | /* 8 | * When using the "HasPermissions" trait from this package, we need to know which 9 | * Eloquent model should be used to retrieve your permissions. Of course, it 10 | * is often just the "Permission" model but you may use whatever you like. 11 | * 12 | * The model you want to use as a Permission model needs to implement the 13 | * `Spatie\Permission\Contracts\Permission` contract. 14 | */ 15 | 16 | 'permission' => Spatie\Permission\Models\Permission::class, 17 | 18 | /* 19 | * When using the "HasRoles" trait from this package, we need to know which 20 | * Eloquent model should be used to retrieve your roles. Of course, it 21 | * is often just the "Role" model but you may use whatever you like. 22 | * 23 | * The model you want to use as a Role model needs to implement the 24 | * `Spatie\Permission\Contracts\Role` contract. 25 | */ 26 | 27 | 'role' => Spatie\Permission\Models\Role::class, 28 | 29 | ], 30 | 31 | 'table_names' => [ 32 | 33 | /* 34 | * When using the "HasRoles" trait from this package, we need to know which 35 | * table should be used to retrieve your roles. We have chosen a basic 36 | * default value but you may easily change it to any table you like. 37 | */ 38 | 39 | 'roles' => 'roles', 40 | 41 | /* 42 | * When using the "HasPermissions" trait from this package, we need to know which 43 | * table should be used to retrieve your permissions. We have chosen a basic 44 | * default value but you may easily change it to any table you like. 45 | */ 46 | 47 | 'permissions' => 'permissions', 48 | 49 | /* 50 | * When using the "HasPermissions" trait from this package, we need to know which 51 | * table should be used to retrieve your models permissions. We have chosen a 52 | * basic default value but you may easily change it to any table you like. 53 | */ 54 | 55 | 'model_has_permissions' => 'model_has_permissions', 56 | 57 | /* 58 | * When using the "HasRoles" trait from this package, we need to know which 59 | * table should be used to retrieve your models roles. We have chosen a 60 | * basic default value but you may easily change it to any table you like. 61 | */ 62 | 63 | 'model_has_roles' => 'model_has_roles', 64 | 65 | /* 66 | * When using the "HasRoles" trait from this package, we need to know which 67 | * table should be used to retrieve your roles permissions. We have chosen a 68 | * basic default value but you may easily change it to any table you like. 69 | */ 70 | 71 | 'role_has_permissions' => 'role_has_permissions', 72 | ], 73 | 74 | 'column_names' => [ 75 | /* 76 | * Change this if you want to name the related pivots other than defaults 77 | */ 78 | 'role_pivot_key' => null, // default 'role_id', 79 | 'permission_pivot_key' => null, // default 'permission_id', 80 | 81 | /* 82 | * Change this if you want to name the related model primary key other than 83 | * `model_id`. 84 | * 85 | * For example, this would be nice if your primary keys are all UUIDs. In 86 | * that case, name this `model_uuid`. 87 | */ 88 | 89 | 'model_morph_key' => 'model_id', 90 | 91 | /* 92 | * Change this if you want to use the teams feature and your related model's 93 | * foreign key is other than `team_id`. 94 | */ 95 | 96 | 'team_foreign_key' => 'team_id', 97 | ], 98 | 99 | /* 100 | * When set to true, the method for checking permissions will be registered on the gate. 101 | * Set this to false if you want to implement custom logic for checking permissions. 102 | */ 103 | 104 | 'register_permission_check_method' => true, 105 | 106 | /* 107 | * When set to true, Laravel\Octane\Events\OperationTerminated event listener will be registered 108 | * this will refresh permissions on every TickTerminated, TaskTerminated and RequestTerminated 109 | * NOTE: This should not be needed in most cases, but an Octane/Vapor combination benefited from it. 110 | */ 111 | 'register_octane_reset_listener' => false, 112 | 113 | /* 114 | * Events will fire when a role or permission is assigned/unassigned: 115 | * \Spatie\Permission\Events\RoleAttached 116 | * \Spatie\Permission\Events\RoleDetached 117 | * \Spatie\Permission\Events\PermissionAttached 118 | * \Spatie\Permission\Events\PermissionDetached 119 | * 120 | * To enable, set to true, and then create listeners to watch these events. 121 | */ 122 | 'events_enabled' => false, 123 | 124 | /* 125 | * Teams Feature. 126 | * When set to true the package implements teams using the 'team_foreign_key'. 127 | * If you want the migrations to register the 'team_foreign_key', you must 128 | * set this to true before doing the migration. 129 | * If you already did the migration then you must make a new migration to also 130 | * add 'team_foreign_key' to 'roles', 'model_has_roles', and 'model_has_permissions' 131 | * (view the latest version of this package's migration file) 132 | */ 133 | 134 | 'teams' => false, 135 | 136 | /* 137 | * The class to use to resolve the permissions team id 138 | */ 139 | 'team_resolver' => \Spatie\Permission\DefaultTeamResolver::class, 140 | 141 | /* 142 | * Passport Client Credentials Grant 143 | * When set to true the package will use Passports Client to check permissions 144 | */ 145 | 146 | 'use_passport_client_credentials' => false, 147 | 148 | /* 149 | * When set to true, the required permission names are added to exception messages. 150 | * This could be considered an information leak in some contexts, so the default 151 | * setting is false here for optimum safety. 152 | */ 153 | 154 | 'display_permission_in_exception' => false, 155 | 156 | /* 157 | * When set to true, the required role names are added to exception messages. 158 | * This could be considered an information leak in some contexts, so the default 159 | * setting is false here for optimum safety. 160 | */ 161 | 162 | 'display_role_in_exception' => false, 163 | 164 | /* 165 | * By default wildcard permission lookups are disabled. 166 | * See documentation to understand supported syntax. 167 | */ 168 | 169 | 'enable_wildcard_permission' => false, 170 | 171 | /* 172 | * The class to use for interpreting wildcard permissions. 173 | * If you need to modify delimiters, override the class and specify its name here. 174 | */ 175 | // 'permission.wildcard_permission' => Spatie\Permission\WildcardPermission::class, 176 | 177 | /* Cache-specific settings */ 178 | 179 | 'cache' => [ 180 | 181 | /* 182 | * By default all permissions are cached for 24 hours to speed up performance. 183 | * When permissions or roles are updated the cache is flushed automatically. 184 | */ 185 | 186 | 'expiration_time' => \DateInterval::createFromDateString('24 hours'), 187 | 188 | /* 189 | * The cache key used to store all permissions. 190 | */ 191 | 192 | 'key' => 'spatie.permission.cache', 193 | 194 | /* 195 | * You may optionally indicate a specific cache driver to use for permission and 196 | * role caching using any of the `store` drivers listed in the cache.php config 197 | * file. Using 'default' here means to use the `default` set in cache.php. 198 | */ 199 | 200 | 'store' => 'default', 201 | ], 202 | ]; 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TEMPLATE LARAVEL 12 - REACT 19 - INERTIA - TS 2 | 3 | ## 📌 Contacto 4 | 5 | 📌 **Portafolio:** [astralzz.io](https://astralzz.github.io/) 6 | 📩 **Email:** [edain.cortez@outlook.com](mailto:edain.cortez@outlook.com) 7 | 📱 **Telegram:** [t.me/lAstralz](https://t.me/lAstralz) 8 | 🔗 **LinkedIn:** [linkedin.com/in/Edain](https://linkedin.com/in/edain-jesus-cortez-ceron-23b26b155) 9 | 😺 **GitHub:** [github.com/Astralzz](https://github.com/Astralzz) 10 | 11 | --- 12 | 13 | ## 📌 Introducción 14 | 15 | Hola amigos 👋 Esta plantilla está diseñada para facilitar el desarrollo de aplicaciones modernas usando Laravel 12, integrando herramientas como React 19, Tailwind CSS 4.0, TypeScript e Inertia. Todo viene preconfigurado para que puedas empezar rápido y enfocarte en construir, no en configurar. Ideal para proyectos nuevos o para aprender un entorno moderno. 🚀 16 | 17 | ### 📦 Librerías Incluidas 18 | 19 | Composer: 20 | 21 | - **Inertia**: gestión de rutas y conexión a react. 22 | - **Laravel-permission**: gestión de roles y permisos. 23 | 24 | React: 25 | 26 | - **React Inertia**: gestión de rutas y conexión a laravel. 27 | - **Redux Toolkit**: gestión del estado. 28 | - **Tailwind CSS 4.0**: estilos rápidos y eficientes. 29 | - **Vite**: bundler para un desarrollo más rápido. 30 | - **Formik**: gestión de formularios y validaciones. 31 | - **Yup**: validación de esquemas en tiempo de ejecución. 32 | - **Sass**: Usos de sass para un mejor manejo de estilos. 33 | - **React hot toast**: Notificaciones minimistas. 34 | 35 | ### ⚙️ Configuraciones Realizadas 36 | 37 | Composer: 38 | 39 | - **Permisos y roles**: Roles y permisos ya configurados asi como modelo user configurado. 40 | - **Vistas de ejemplo**: Vistas para probar este template en lo que tiene en **routes/web.php** en el apartado `develop`. 41 | - **Comandos útiles creados**: Comandos para limpiar rápidamente, probar, actualizar, migrar, etc creados en **routes/console.php**. 42 | 43 | React (en `resources/ts`): 44 | 45 | - **TypeScript**: ya configurado en toda la app para una mejor experiencia de desarrollo. 46 | - **Redux Toolkit**: configuración lista en **src/redux/**, incluyendo store y middleware. 47 | - **Tailwind CSS 4.0**: configurado en **src/main.css**. 48 | - **Tema**: gestión de tema en **src/redux/slices/themeSlice.ts**, integrado con Redux. 49 | - **Formik & Yup**: formulario con validaciones listo para usar. 50 | - **Página 404**: ya implementada y funcional. 51 | - **Modal**: implementado y listo para usar en **src/components/modals/ModalDefault.tsx**. 52 | 53 | --- 54 | 55 | ## 🚀 Uso 56 | 57 | ### 🔧 Instalación 58 | 59 | 1. Clona este repositorio: 60 | 61 | ```sh 62 | git clone https://github.com/Astralzz/template-laravel-react-full 63 | cd template-laravel-react-full 64 | ``` 65 | 66 | 2. Instala las dependencias: 67 | 68 | ```bash 69 | npm install 70 | ``` 71 | 72 | ```bash 73 | composer install 74 | ``` 75 | 76 | 3. Inicia el entorno de desarrollo: 77 | 78 | ```bash 79 | composer run dev 80 | ``` 81 | 82 | ### 📜 Scripts Útiles 83 | 84 | COMPOSER: 85 | 86 | - **`composer run dev`**: Inicia el servidor en modo desarrollo del back y frond conminados. 87 | - **`php artisan serve`**: Inicia el servidor en modo desarrollo del backend. 88 | - **`php artisan clear-all-app`**: Limpia toda la app (creado en **routes/console.php**) 89 | 90 | NPM: 91 | 92 | - **`npm run dev`**: Inicia el servidor en modo desarrollo solo del frontend. 93 | - **`npm run build`**: Compila la aplicación para producción. 94 | - **`npm run preview`**: Ejecuta la versión compilada de la app. 95 | - **`npm run lint`**: Verifica errores en el código. 96 | - **`npm run format`**: Aplica formato automático con Prettier. 97 | - **`npm run test`**: Ejecuta las pruebas automatizadas. 98 | 99 | --- 100 | 101 | ## 🛠️ Configuraciones de react destacadas 102 | 103 | ### **Redux Configurado** 104 | 105 | Redux Toolkit está preconfigurado con TypeScript en **src/redux/**, incluyendo el store y los slices: 106 | 107 | ```tsx 108 | import { configureStore } from "@reduxjs/toolkit"; 109 | import themeSlice from "./slices/themeSlice"; 110 | 111 | export const store = configureStore({ 112 | reducer: { 113 | stateTheme: themeSlice, 114 | }, 115 | }); 116 | 117 | // Tipos de TypeScript 118 | export type RootState = ReturnType; 119 | export type AppDispatch = typeof store.dispatch; 120 | ``` 121 | 122 | ### **Tailwind CSS 4.0** 123 | 124 | La configuración de Tailwind está en **src/main.css**. Se puede personalizar fácilmente: 125 | 126 | ```css 127 | @import "tailwindcss"; 128 | 129 | @theme { 130 | --color-primary-50: rgba(245, 245, 245, 1); 131 | --color-primary-500: rgba(50, 50, 50, 1); 132 | --color-primary-900: rgba(0, 0, 0, 1); 133 | } 134 | ``` 135 | 136 | ### **Gestión de Tema con Redux** 137 | 138 | El estado del tema se gestiona en **src/redux/slices/themeSlice.ts**. 139 | 140 | ```tsx 141 | import { useReduxSelector } from './redux/hook'; 142 | 143 | const App: React.FC = () => { 144 | const theme = useReduxSelector((state) => state.stateTheme.theme); 145 | return
; 146 | }; 147 | ``` 148 | 149 | ### **Formularios con Formik & Yup** 150 | 151 | La validación de formularios está lista en **src/components/forms/EmailForm.tsx**. 152 | 153 | ```tsx 154 | const EmailForm: React.FC = () => { 155 | // Action form 156 | const handleSubmit = React.useCallback( 157 | ( 158 | values: { asunto: string; }, 159 | { 160 | setSubmitting, 161 | resetForm, 162 | }: { 163 | setSubmitting: (isSubmitting: boolean) => void; 164 | resetForm: () => void; 165 | } 166 | ): void => { 167 | console.log("Email enviado:", values); 168 | }, 169 | [] 170 | ); 171 | 172 | return ( 173 | 178 | {/* Está enviando, Es válido, Sucio */} 179 | {({ isSubmitting, isValid, dirty }) => ( 180 |
181 | {/* Asunto */} 182 | 183 | {/* Button action */} 184 | 191 | 192 | )} 193 |
194 | ); 195 | }; 196 | ``` 197 | 198 | ### **404 Page** 199 | 200 | Pagina 404 funcionando correctamente en **src/redux/slices/themeSlice.ts**. se puede cambiar y configurar sin problema. 201 | 202 | ```tsx 203 | /** 204 | * 404 page 205 | * 206 | * @returns {JSX.Element} 207 | */ 208 | const NotFoundPage: React.FC = () => { 209 | // Variables redux 210 | const theme = useReduxSelector((state) => state.stateTheme.theme); 211 | 212 | return ( 213 |
214 |
215 | {/* Header */} 216 |

404

217 | {/* Message */} 218 |

Página no encontrada

219 | {/* Button */} 220 | 224 | Volver al inicio 225 | 226 |
227 |
228 | ); 229 | }; 230 | ``` 231 | 232 | --- 233 | 234 | ## 📜 Conclusión 235 | 236 | Esta plantilla te permite comenzar rápidamente con **React, Laravel, Inertia, Tailwind y TypeScript**, sin preocuparte por la configuración inicial. 🚀 237 | 238 | --- 239 | -------------------------------------------------------------------------------- /config/session.php: -------------------------------------------------------------------------------- 1 | env('SESSION_DRIVER', 'database'), 22 | 23 | /* 24 | |-------------------------------------------------------------------------- 25 | | Session Lifetime 26 | |-------------------------------------------------------------------------- 27 | | 28 | | Here you may specify the number of minutes that you wish the session 29 | | to be allowed to remain idle before it expires. If you want them 30 | | to expire immediately when the browser is closed then you may 31 | | indicate that via the expire_on_close configuration option. 32 | | 33 | */ 34 | 35 | 'lifetime' => (int) env('SESSION_LIFETIME', 120), 36 | 37 | 'expire_on_close' => env('SESSION_EXPIRE_ON_CLOSE', false), 38 | 39 | /* 40 | |-------------------------------------------------------------------------- 41 | | Session Encryption 42 | |-------------------------------------------------------------------------- 43 | | 44 | | This option allows you to easily specify that all of your session data 45 | | should be encrypted before it's stored. All encryption is performed 46 | | automatically by Laravel and you may use the session like normal. 47 | | 48 | */ 49 | 50 | 'encrypt' => env('SESSION_ENCRYPT', false), 51 | 52 | /* 53 | |-------------------------------------------------------------------------- 54 | | Session File Location 55 | |-------------------------------------------------------------------------- 56 | | 57 | | When utilizing the "file" session driver, the session files are placed 58 | | on disk. The default storage location is defined here; however, you 59 | | are free to provide another location where they should be stored. 60 | | 61 | */ 62 | 63 | 'files' => storage_path('framework/sessions'), 64 | 65 | /* 66 | |-------------------------------------------------------------------------- 67 | | Session Database Connection 68 | |-------------------------------------------------------------------------- 69 | | 70 | | When using the "database" or "redis" session drivers, you may specify a 71 | | connection that should be used to manage these sessions. This should 72 | | correspond to a connection in your database configuration options. 73 | | 74 | */ 75 | 76 | 'connection' => env('SESSION_CONNECTION'), 77 | 78 | /* 79 | |-------------------------------------------------------------------------- 80 | | Session Database Table 81 | |-------------------------------------------------------------------------- 82 | | 83 | | When using the "database" session driver, you may specify the table to 84 | | be used to store sessions. Of course, a sensible default is defined 85 | | for you; however, you're welcome to change this to another table. 86 | | 87 | */ 88 | 89 | 'table' => env('SESSION_TABLE', 'sessions'), 90 | 91 | /* 92 | |-------------------------------------------------------------------------- 93 | | Session Cache Store 94 | |-------------------------------------------------------------------------- 95 | | 96 | | When using one of the framework's cache driven session backends, you may 97 | | define the cache store which should be used to store the session data 98 | | between requests. This must match one of your defined cache stores. 99 | | 100 | | Affects: "apc", "dynamodb", "memcached", "redis" 101 | | 102 | */ 103 | 104 | 'store' => env('SESSION_STORE'), 105 | 106 | /* 107 | |-------------------------------------------------------------------------- 108 | | Session Sweeping Lottery 109 | |-------------------------------------------------------------------------- 110 | | 111 | | Some session drivers must manually sweep their storage location to get 112 | | rid of old sessions from storage. Here are the chances that it will 113 | | happen on a given request. By default, the odds are 2 out of 100. 114 | | 115 | */ 116 | 117 | 'lottery' => [2, 100], 118 | 119 | /* 120 | |-------------------------------------------------------------------------- 121 | | Session Cookie Name 122 | |-------------------------------------------------------------------------- 123 | | 124 | | Here you may change the name of the session cookie that is created by 125 | | the framework. Typically, you should not need to change this value 126 | | since doing so does not grant a meaningful security improvement. 127 | | 128 | */ 129 | 130 | 'cookie' => env( 131 | 'SESSION_COOKIE', 132 | Str::slug(env('APP_NAME', 'laravel'), '_').'_session' 133 | ), 134 | 135 | /* 136 | |-------------------------------------------------------------------------- 137 | | Session Cookie Path 138 | |-------------------------------------------------------------------------- 139 | | 140 | | The session cookie path determines the path for which the cookie will 141 | | be regarded as available. Typically, this will be the root path of 142 | | your application, but you're free to change this when necessary. 143 | | 144 | */ 145 | 146 | 'path' => env('SESSION_PATH', '/'), 147 | 148 | /* 149 | |-------------------------------------------------------------------------- 150 | | Session Cookie Domain 151 | |-------------------------------------------------------------------------- 152 | | 153 | | This value determines the domain and subdomains the session cookie is 154 | | available to. By default, the cookie will be available to the root 155 | | domain and all subdomains. Typically, this shouldn't be changed. 156 | | 157 | */ 158 | 159 | 'domain' => env('SESSION_DOMAIN'), 160 | 161 | /* 162 | |-------------------------------------------------------------------------- 163 | | HTTPS Only Cookies 164 | |-------------------------------------------------------------------------- 165 | | 166 | | By setting this option to true, session cookies will only be sent back 167 | | to the server if the browser has a HTTPS connection. This will keep 168 | | the cookie from being sent to you when it can't be done securely. 169 | | 170 | */ 171 | 172 | 'secure' => env('SESSION_SECURE_COOKIE'), 173 | 174 | /* 175 | |-------------------------------------------------------------------------- 176 | | HTTP Access Only 177 | |-------------------------------------------------------------------------- 178 | | 179 | | Setting this value to true will prevent JavaScript from accessing the 180 | | value of the cookie and the cookie will only be accessible through 181 | | the HTTP protocol. It's unlikely you should disable this option. 182 | | 183 | */ 184 | 185 | 'http_only' => env('SESSION_HTTP_ONLY', true), 186 | 187 | /* 188 | |-------------------------------------------------------------------------- 189 | | Same-Site Cookies 190 | |-------------------------------------------------------------------------- 191 | | 192 | | This option determines how your cookies behave when cross-site requests 193 | | take place, and can be used to mitigate CSRF attacks. By default, we 194 | | will set this value to "lax" to permit secure cross-site requests. 195 | | 196 | | See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#samesitesamesite-value 197 | | 198 | | Supported: "lax", "strict", "none", null 199 | | 200 | */ 201 | 202 | 'same_site' => env('SESSION_SAME_SITE', 'lax'), 203 | 204 | /* 205 | |-------------------------------------------------------------------------- 206 | | Partitioned Cookies 207 | |-------------------------------------------------------------------------- 208 | | 209 | | Setting this value to true will tie the cookie to the top-level site for 210 | | a cross-site context. Partitioned cookies are accepted by the browser 211 | | when flagged "secure" and the Same-Site attribute is set to "none". 212 | | 213 | */ 214 | 215 | 'partitioned' => env('SESSION_PARTITIONED_COOKIE', false), 216 | 217 | ]; 218 | -------------------------------------------------------------------------------- /routes/console.php: -------------------------------------------------------------------------------- 1 | call('cache:clear'); 26 | $this->call('config:clear'); 27 | $this->call('view:clear'); 28 | $this->info('Caché limpiada con éxito.'); 29 | 30 | // ! Error 31 | } catch (\Throwable $th) { 32 | $this->error('No se limpio el env correctamente, ' . $th->getMessage()); 33 | } 34 | })->purpose('Limpiar la caché del .env de la aplicación'); 35 | 36 | // * php artisan clear-cache-app 37 | Artisan::command('clear-cache-app', function () { 38 | try { 39 | 40 | // Limpiamos 41 | $this->call('clear-compiled'); 42 | $this->call('cache:clear'); 43 | $this->call('config:cache'); 44 | $this->call('config:clear'); 45 | $this->call('route:clear'); 46 | $this->call('route:cache'); 47 | $this->call('view:clear'); 48 | $this->info('Caché limpiada con éxito.'); 49 | 50 | // ! Error 51 | } catch (\Throwable $th) { 52 | $this->error('No se limpio la app correctamente, ' . $th->getMessage()); 53 | } 54 | })->purpose('Limpiar la caché de la aplicación'); 55 | 56 | // * php artisan optimize-app 57 | Artisan::command('optimize-app', function () { 58 | $this->call('clear-compiled'); 59 | $this->call('optimize:clear'); 60 | $this->call('config:cache'); 61 | $this->call('route:cache'); 62 | $this->info('Optimización completada.'); 63 | })->purpose('Optimizar la aplicación para un mejor rendimiento'); 64 | 65 | // * php artisan clear-all-app 66 | Artisan::command('clear-all-app', function () { 67 | $this->call('clear-env-app'); 68 | $this->call('optimize-app'); 69 | $this->call('clear-cache-app'); 70 | $this->info('Limpieza total de la app realizada con éxito.'); 71 | })->purpose('Limpiar al completo la app'); 72 | 73 | /* STUB - INFORMACIÓN 74 | 75 | 1. php artisan inf-server 76 | 2. php artisan inf-server-connection 77 | 3. php artisan list-packages 78 | 4. php artisan env-info 79 | 80 | */ 81 | 82 | // * php artisan inf-server 83 | Artisan::command('inf-server', function () { 84 | $this->line(''); 85 | $this->comment('TEMPLATE REACT - LARAVEL'); 86 | $this->line(''); 87 | $this->line('Desarrollador ..................... Ing Edain Jesus Cortez Ceron'); 88 | $this->line(''); 89 | $this->comment("CONTACTO DESARROLLADOR:"); 90 | $this->line(''); 91 | $this->info('Email ............. daiinxd13@gmail.com'); 92 | $this->info('GitHub ............. https://github.com/Astralzz'); 93 | $this->line(''); 94 | })->purpose('Obtener información del servidor'); 95 | 96 | // * php artisan inf-server-connection 97 | Artisan::command('inf-server-connection', function () { 98 | try { 99 | // Verificar la conexión a la BD 100 | DB::connection()->getPdo(); 101 | 102 | // Éxito 103 | $this->info('La conexión a la base de datos es correcta.'); 104 | 105 | // Obtener información del servidor 106 | $serverInfo = [ 107 | 'Sistema operativo' => PHP_OS, 108 | 'Versión de PHP' => phpversion(), 109 | 'Versión de Laravel' => app()->version(), 110 | ]; 111 | 112 | // Mostrar información 113 | $this->table(array_keys($serverInfo), [$serverInfo]); 114 | } catch (\Exception $e) { 115 | $this->error('Error en la conexión a la base de datos: ' . $e->getMessage()); 116 | } 117 | })->purpose('Obtener información del servidor y verificar la conexión a la base de datos.'); 118 | 119 | // * php artisan list-packages 120 | Artisan::command('list-packages', function () { 121 | 122 | try { 123 | 124 | // Obtenemos inf del archivo 125 | $composerJsonPath = base_path('composer.json'); 126 | 127 | // ? Existe 128 | if (file_exists($composerJsonPath)) { 129 | 130 | // Decodificamos 131 | $composerJson = json_decode(file_get_contents($composerJsonPath), true); 132 | 133 | // ? Existen paquetes 134 | if (isset($composerJson['require'])) { 135 | 136 | $this->info('Paquetes instalados:'); 137 | 138 | // Recorremos 139 | foreach ($composerJson['require'] as $package => $version) { 140 | $this->line("- {$package}: {$version}"); 141 | } 142 | 143 | return; 144 | } 145 | 146 | throw new \Exception('No se encontraron paquetes instalados en composer.json.'); 147 | } 148 | 149 | // ! Archivo no encontrado 150 | throw new \Exception('No se encontró el archivo composer.json en la ubicación predeterminada.'); 151 | 152 | // ! Error 153 | } catch (\Throwable $th) { 154 | $this->error('No se obtuvieron los paquetes correctamente, ' . $th->getMessage()); 155 | } 156 | })->purpose('Listar los paquetes instalados en el proyecto Laravel'); 157 | 158 | // * php artisan env-info 159 | Artisan::command('env-info', function () { 160 | $this->line('Información del entorno:'); 161 | $this->info('Versión de PHP: ' . phpversion()); 162 | })->purpose('Mostrar información del entorno'); 163 | 164 | /* STUB - ACCIONES 165 | 166 | 1. php artisan generate-key lg n 167 | 168 | ! PASS CONSOLE 169 | 170 | 1. php artisan migrate-app 171 | 2. php artisan migrate-refresh-app 172 | 3. php artisan update-key-app 173 | 4. php artisan update-app 174 | 5. php artisan update-app 175 | 6. php artisan clear-storage-app {directorio} 176 | 177 | */ 178 | 179 | // * php artisan generate-key lg n 180 | Artisan::command('generate-key {length} {n}', function ($length = 32, $n = 1) { 181 | try { 182 | 183 | // ? Número entero positivo y no mayor a 120 184 | if (!ctype_digit($length) || $length < 1 || $length > 120) { 185 | throw new \Exception("La longitud debe ser un número entero positivo menor o igual a 120."); 186 | } 187 | 188 | for ($i = 1; $i <= $n; $i++) { 189 | // Generar una clave única 190 | $uniqueKey = \Illuminate\Support\Str::random($length); 191 | 192 | // Mostrar la clave única 193 | $this->info('Clave única ' . $i . ': ' . $uniqueKey); 194 | } 195 | 196 | // ! Error 197 | } catch (\Throwable $th) { 198 | $this->error('No se pudieron crear las keys correctamente, ' . $th->getMessage()); 199 | } 200 | })->purpose('Generar n claves únicas'); 201 | 202 | // * php artisan migrate-app 203 | Artisan::command('migrate-app', function () { 204 | try { 205 | 206 | // Solicitar la clave para usar la consola 207 | $keyConsole = $this->secret('Ingrese la clave para usar la consola'); 208 | 209 | // ? Probamos 210 | ConsoleHelper::probateKeyConsole($keyConsole); 211 | 212 | $this->call('migrate'); 213 | $this->call('db:seed'); 214 | 215 | $this->info('Migraciones y semillas ejecutadas correctamente.'); 216 | // ! Error 217 | } catch (\Throwable $th) { 218 | $this->error('No se hizo la migración correctamente, ' . $th->getMessage()); 219 | } 220 | })->purpose('Ejecutar migraciones y semillas en la base de datos'); 221 | 222 | // * php artisan migrate-refresh-app 223 | Artisan::command('migrate-refresh-app', function () { 224 | try { 225 | 226 | // Solicitar la clave para usar la consola 227 | $keyConsole = $this->secret('Ingrese la clave para usar la consola'); 228 | 229 | // ? Probamos 230 | ConsoleHelper::probateKeyConsole($keyConsole); 231 | 232 | $this->call('migrate:refresh', [ 233 | '--seed' => true, 234 | ]); 235 | 236 | $this->info('Migraciones y semillas ejecutadas correctamente.'); 237 | } catch (\Throwable $th) { 238 | $this->error('No se hizo la migración correctamente, ' . $th->getMessage()); 239 | } 240 | })->purpose('Refrescar y ejecutar migraciones y semillas en la base de datos'); 241 | 242 | // * php artisan update-key-app 243 | Artisan::command('update-key-app', function () { 244 | try { 245 | 246 | // Solicitar la clave para usar la consola 247 | $keyConsole = $this->secret('Ingrese la clave para usar la consola'); // Ocultar data 248 | 249 | // ? Probamos 250 | ConsoleHelper::probateKeyConsole($keyConsole); 251 | 252 | $this->call('key:generate'); 253 | $this->info('La clave de la aplicación se actualizo con éxito.'); 254 | 255 | // ! Error 256 | } catch (\Throwable $th) { 257 | $this->error('No se creo una nueva key del servidor correctamente, ' . $th->getMessage()); 258 | } 259 | })->purpose('Crear nueva clave de aplicación'); 260 | 261 | // * php artisan update-app 262 | Artisan::command('update-app', function () { 263 | 264 | try { 265 | 266 | // Solicitar la clave para usar la consola 267 | $keyConsole = $this->secret('Ingrese la clave para usar la consola'); // Ocultar data 268 | 269 | // ? Probamos 270 | ConsoleHelper::probateKeyConsole($keyConsole); 271 | 272 | $this->call('composer update'); 273 | $this->info('Actualización y migración completadas con éxito.'); 274 | 275 | // ! Error 276 | } catch (\Throwable $th) { 277 | $this->error('No se actualizo el servidor correctamente, ' . $th->getMessage()); 278 | } 279 | })->purpose('Actualizar dependencias y ejecutar migraciones'); 280 | 281 | // * php artisan clear-storage-app {directorio} 282 | Artisan::command('clear-storage-app {directory}', function (string $directory) { 283 | try { 284 | 285 | // Solicitar la clave para usar la consola 286 | $keyConsole = $this->secret('Ingrese la clave para usar la consola'); 287 | 288 | // ? Probamos 289 | ConsoleHelper::probateKeyConsole($keyConsole); 290 | 291 | // Inyectar el servicio 292 | FileService::clearDirectoryStorageApp($directory); 293 | 294 | // Éxito 295 | $this->info('El directorio se vació correctamente'); 296 | 297 | // ! Error 298 | } catch (\Throwable $th) { 299 | $this->error('No se vació el directorio correctamente, ' . $th->getMessage()); 300 | } 301 | })->purpose('Vaciar un directorio de storage app/public/'); 302 | 303 | /* STUB - REQUIRED PACKAGES 304 | 305 | # LINK - https://spatie.be/docs/laravel-permission/v6/introduction 306 | 307 | # NOTE - php artisan generate-migration-roles-app 308 | 309 | */ 310 | 311 | // * php artisan generate-migration-roles-app 312 | Artisan::command('generate-migration-roles-app', function () { 313 | try { 314 | 315 | // Solicitar la clave para usar la consola 316 | $keyConsole = $this->secret('Ingrese la clave para usar la consola'); // Ocultar data 317 | 318 | // ? Probamos 319 | ConsoleHelper::probateKeyConsole($keyConsole); 320 | 321 | // Ejecutar el comando vendor:publish 322 | Artisan::call('vendor:publish', [ 323 | '--provider' => 'Spatie\Permission\PermissionServiceProvider', 324 | ]); 325 | 326 | $this->info('Migración de roles generada correctamente.'); 327 | 328 | // ! Error 329 | } catch (\Throwable $th) { 330 | $this->error('No se pudo crear la migración de roles correctamente, ' . $th->getMessage()); 331 | } 332 | })->purpose('Generar la migración de roles única'); 333 | 334 | 335 | --------------------------------------------------------------------------------