Skip to content

Laravel 12 React starter kit. Basic User CRUD with roles and permissions.

Notifications You must be signed in to change notification settings

mrlinnth/laravel12-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel 12 starter template

🆘 WARNING Repo is still work in progress. Check the to-do list for current status. ‼️

To Do

  • generate basic React CRUD pages
  • to do CRUD with spatie media upload
  • role CRUD
  • user CRUD with role
  • example for Authorization based on role and permission
  • prefix sub-directory (eg: admin, frontend) with generate commands
  • one command to generate both backend and frontend files
  • impersonate as a user
  • example REST api endpoint and usage in React code

⚠️ ATTENTION This is a starter template. Clone or fork this repo. Develop and commit in a new repo. Do not commit to this repo. ‼️

Requirements

  • php 8.2 or 8.3
  • composer 2.8.1
  • node 22.14.0
  • pnpm install guide
  • mysql
  • apache/nginx

Installation

  1. clone or fork git@github.com:mrlinnth/laravel12-starter.git
  2. create database
  3. change to project directory
  4. copy .env.example to .env
  5. update .env with correct settings
  6. run composer install
  7. run php artisan key:generate
  8. run php artisan migrate:refresh --seed
  9. run pnpm install
  10. run pnpm dev for local development or pnpm build for deployment

Use

Laravel Packages

Node Packages

Tips

Project Structure

laravel12-starter
├── app
│   ├── Console
│   │   └── Commands
│   │       └── ShadcnCrud.php (Custom command to generate React CRUD pages)
│   ├── Enums
│   ├── Exports
│   ├── Http
│   │   ├── Controllers
│   │   │   ├── Auth
│   │   │   ├── Settings
│   │   │   └── PlaygroundController.php
│   │   └── Requests
│   ├── Models
│   ├── Policies
│   └── Providers
├── bootstrap
├── config
├── database
│   ├── factories
│   ├── migrations
│   └── seeders
├── public
├── resources
│   ├── boilerplates (Templates for custom file generate)
│   ├── css
│   ├── js
│   │   ├── components
│   │   │   └── ui (Shadcn components)
│   │   ├── hooks
│   │   ├── layouts
│   │   ├── lib
│   │   ├── pages
│   │   │   ├── auth
│   │   │   ├── settings
│   │   │   ├── dashboard.tsx
│   │   │   └── welcome.tsx
│   │   ├── types
│   │   └── app.tsx
│   └── views
├── routes
│   └── web.php
└── storage

Default users

Name Login Email Password Role Permissions
Super Admin admin@mail.com password god *
Manager User manager@mail.com password manager create,read,update,delete
User user@mail.com password

File Upload

Basic Workflow

💡 Advice Copy and paste existing file/directory. Find and replace. Voila.

Backend - For new entity (eg: Comment)

  1. Generate migration, seeder, model, controller, request files using blueprint for your entity (refer to draft.yaml.example and create your own draft.yaml)
  2. Delete blueprint generated view direcotry under resources/views
  3. Update blueprint generated controller file to return Inertia::render instead of blade view
  4. Update routes/web.php
  5. Make changes to other blueprint generated files if necessary
  6. Run php artisan migrate:refresh --seed

Frontend - For new entity (eg: Comment)

  1. Generate react crud files using php artisan make:shadcn-crud comment (custom artisan command which uses Laravel File Generator package)
  2. Make necessary changes to generated react crud files
  3. Update resources/js/components/app-sidebar.tsx with new route

If you already have migration file (eg: Role)

  1. Create factory and seeder (optional)
  2. If model not exist, create and extends BaseModel
  3. If controller not exist, create a resource controller
  4. If request not exist, create a form request
  5. Update web.php with new route(s)
  6. Generate react crud files using php artisan make:shadcn-crud role
  7. Make necessary changes to generated react crud files
  8. Run php artisan migrate:refresh --seed
  9. Update resources/js/components/app-sidebar.tsx with new route

Authorization

  • Refer to Spatie - Laravel Permission
  • check database/seeders/DatabaseSeeder.php DatabaseSeeder class for how to create role, permission and assign to user
  • app/Models/User.php User model has is_super_admin, main_role, can_do custom attributes
  • for frontend authorization, check resources/js/components/buttons/create-btn.tsx, Create button is hidden for user without create permission
  • for backend authorization, check app/Policies/TodoPolicy.php TodoPolicy class update method and app/Http/Controllers/TodoController.php TodoController class edit and update methods
  • secret route in routes/web.php is available only to super admin user

Generate CRUD API for an entity

Custom action API

  • Check app\Http\Controllers\Api\TodoStatusController.php Api/TodoStatusController
  • Must follow Orion Response object structure to have a consistant API responses

Fetch data using API at Frontend

  • Check resources\js\components\inputs\country-select.tsx CountrySelect component and /playground page

Submit data using API at Frontend

  • Check resources\js\components\todo\todo-status-dropdown.tsx TodoStatusDropdown component and /todos page

About

Laravel 12 React starter kit. Basic User CRUD with roles and permissions.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published