PHP code example of anwar / crud-generator

1. Go to this page and download the library: Download anwar/crud-generator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

anwar / crud-generator example snippets


'fields' => [
    ['name' => 'email', 'type' => 'string', 'validation' => 'er|min:18|max:65'],
    ['name' => 'bio', 'type' => 'text', 'validation' => 'nullable|string|max:1000'],
    ['name' => 'avatar', 'type' => 'string', 'validation' => 'nullable|image|max:2048'],
    ['name' => 'settings', 'type' => 'json', 'validation' => 'nullable|array'],
    ['name' => 'salary', 'type' => 'decimal', 'validation' => '

'relationships' => [
    [
        'name' => 'user',
        'type' => 'belongsTo',
        'model' => 'User',
        'foreign_key' => 'user_id'
    ],
    [
        'name' => 'tags',
        'type' => 'belongsToMany',
        'model' => 'Tag',
        'pivot_table' => 'post_tags'
    ]
]

return [
    'model_namespace' => 'App\\Models',
    'controller_namespace' => 'App\\Http\\Controllers',
    'view_path' => 'resources/views',
    
    'features' => [
        'api_generation' => true,
        'test_generation' => true,
        'documentation_generation' => true,
        'soft_deletes' => true,
    ],
    
    'ui' => [
        'theme' => 'bootstrap4',
        'show_preview' => true,
        'enable_live_preview' => true,
    ],
];

'custom_fields' => [
    'phone' => [
        'migration_type' => 'string',
        'validation' => '

// Feature Test Example
public function test_can_create_post()
{
    $data = ['title' => 'Test Post', 'content' => 'Test Content'];
    
    $response = $this->post(route('posts.store'), $data);
    
    $response->assertRedirect(route('posts.index'));
    $this->assertDatabaseHas('posts', $data);
}

// API Test Example  
public function test_api_can_list_posts()
{
    Post::factory(3)->create();
    
    $response = $this->getJson('/api/posts');
    
    $response->assertOk()
             ->assertJsonCount(3, 'data');
}
bash
# 1. BACKUP YOUR DATABASE FIRST!
mysqldump -u user -p database_name > backup.sql

# 2. Install the package
composer endor:publish --tag=crudgenerator-migrations
php artisan vendor:publish --tag=crudgenerator-assets

# 4. Review published migrations first!
ls database/migrations/*anwar*

# 5. Only run if safe
php artisan migrate
bash
   php artisan vendor:publish --tag=anwar-crud-stubs