Difference between revisions of "Creating models in Laravel Nova"

From Wiki | Valse Technologies
Jump to navigation Jump to search
 
(4 intermediate revisions by the same user not shown)
Line 5: Line 5:
  
 
2. Create the same Model.php in app/Nova
 
2. Create the same Model.php in app/Nova
   - Create manually in app/Nova or type 'php artisan nova:resource Post' in composer.
+
   - Create manually in app/Nova or type 'php artisan nova:resource User' in composer.
 +
 
 +
3. Validation
 +
  - Required fields: put '''->rules('required'),'''
 +
 
 +
4. Grouping resources
 +
  - Put 'public static $group = 'Admin';' if you wish to put the model is under '''Admin''' heading in the sidebar menu
 +
 
 +
5. Multi-Tenancy
 +
  - Multi tenancy involves relationship between models
 +
  - For example: 'Store' creates 'Clerk'
 +
  - In laravel (Clerk.php) model, put '''public function store()'''
 +
  - In Nova model, put BelongsTo function
 +
  - For example: In Clerk model, put '''BelongsTo::make('Store')'''
 +
 
 +
6. Policies
 +
  - To limit which users may view, create, update, or delete resources.
 +
  - Using composer, type 'php artisan make:policy UserPolicy --model=User'
 +
  - The file will be edited in app/Policies.

Latest revision as of 08:24, 20 November 2019

1. Using composer, type 'php artisan make:model Model'

  - Model are named after table in database in singular term. 
  - Eg. users(table) --> User.php (models)
  - Folder: app/Model.php

2. Create the same Model.php in app/Nova

  - Create manually in app/Nova or type 'php artisan nova:resource User' in composer.

3. Validation

  - Required fields: put ->rules('required'),

4. Grouping resources

  - Put 'public static $group = 'Admin';' if you wish to put the model is under Admin heading in the sidebar menu

5. Multi-Tenancy

  - Multi tenancy involves relationship between models
  - For example: 'Store' creates 'Clerk'
  - In laravel (Clerk.php) model, put public function store()
  - In Nova model, put BelongsTo function
  - For example: In Clerk model, put BelongsTo::make('Store')

6. Policies

  - To limit which users may view, create, update, or delete resources.
  - Using composer, type 'php artisan make:policy UserPolicy --model=User'
  - The file will be edited in app/Policies.