PHP code example of melsaka / api-builder

1. Go to this page and download the library: Download melsaka/api-builder 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/ */

    

melsaka / api-builder example snippets


return [
    'storage_disk' => 'public', // could be r2, aws, etc..
    'base_path' => 'uploads',
    'format' => 'webp',
    'quality' => 90,
    
    'models' => [
        'user' => [
            'types' => [
                'avatar' => [
                    'sizes' => [
                        'thumbnail' => [
                            'width' => 100,
                            'height' => 100,
                            'mode' => 'cover',
                        ],
                        'medium' => [
                            'width' => 300,
                            'height' => 300,
                            'mode' => 'cover',
                        ],
                    ],
                ],
            ],
        ],
    ],
];



namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Melsaka\ImageManager\Traits\HasImages;

class User extends Model
{
    use HasImages;
    
    // Your model code...
}


class User extends Model
{
    use HasImages;
	    
	public static function supportedImages()
	{
	    return [
	        'profile'   => 'singular', // for singular image upload
	        'gallery'   => 'multiple', // for multiple images upload
	    ];
	}
    // Your model code...
}
bash
php artisan vendor:publish --tag=api-builder-stubs
php artisan vendor:publish --tag=image-manager
bash
php artisan api:scaffold
bash
php artisan api:crud User
bash
php artisan vendor:publish --provider="Melsaka\ImageManager\ImageManagerServiceProvider" --tag="image-manager"
bash
php artisan migrate
bash
php artisan api:crud User