PHP code example of sawmainek / apitoolz

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

    

sawmainek / apitoolz example snippets


// app/Services/CustomSmsService.php
namespace App\Services;

use Sawmainek\Apitoolz\Contracts\SmsSenderInterface;
use Illuminate\Support\Facades\Log;

class CustomSmsService implements SmsSenderInterface
{
    public function send(string $to, string $message): void
    {
        // Use your preferred SMS provider (e.g., Twilio, ClickSend, etc.)
        // Example log output for testing
        Log::info("Sending SMS to {$to}: {$message}");

        // You can integrate your SMS provider's API here
    }
}

// app/Providers/AppServiceProvider.php
namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Sawmainek\Apitoolz\Contracts\SmsSenderInterface;
use App\Services\CustomSmsService;
use Sawmainek\Apitoolz\Notifications\Channels\SmsChannel;
use Illuminate\Support\Facades\Notification;

class AppServiceProvider extends ServiceProvider
{
    public function register()
    {
        // Bind the SmsSenderInterface to the CustomSmsService implementation
        $this->app->bind(SmsSenderInterface::class, CustomSmsService::class);
    }

    public function boot()
    {
        // Extend the notification system to 

namespace App\Observers;

use Sawmainek\Apitoolz\Models\User;
use Illuminate\Support\Facades\Log;
//use App\Jobs\NotifyUserUpdateJob;

class UserObserver
{
    public function creating(User $user)
    {
        Log::info('Before creating user', ['data' => $user->toArray()]);
        // $user->status = $user->status ?? 'pending'; // Set default status
    }

    public function created(User $user)
    {
        Log::info('After creating user', ['id' => $user->id]);
        // dispatch(new NotifyUserUpdateJob($user)); // Trigger async job
    }

    public function updating(User $user)
    {
        Log::info('Before updating user', ['id' => $user->id]);
    }

    public function updated(User $user)
    {
        Log::info('After updating user', ['id' => $user->id]);
    }

    public function deleting(User $user)
    {
        Log::info('Before deleting user', ['id' => $user->id]);
    }

    public function deleted(User $user)
    {
        Log::info('After deleting user', ['id' => $user->id]);
    }

    public function restoring(User $user)
    {
        Log::info('Before restoring user', ['id' => $user->id]);
    }

    public function restored(User $user)
    {
        Log::info('After restoring user', ['id' => $user->id]);
    }
}

namespace App\Jobs;

use Sawmainek\Apitoolz\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;

class NotifyUserUpdateJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public function __construct(public User $user) {}

    public function handle()
    {
        Log::info('Async notification triggered for user', ['id' => $this->user->id]);
        // Add notification logic here
    }
}
shell
php artisan migrate
php artisan db:seed --class=APIToolzSeeder
php artisan vendor:publish --tag=apitoolz-config
shell
php artisan vendor:publish --tag=apitoolz-ui
shell
php artisan apitoolz:activate
shell
php artisan apitoolz:react-frontend Frontend --path=resources/js --theme=blue --vite --tailwind --typescript --eslint --storybook --force
shell
    php artisan apitoolz:model Product --table=products
    
shell
    php artisan apitoolz:model Customer --rebuild
    
shell
    php artisan apitoolz:model Sale --force-delete
    
shell
php artisan apitoolz:datatable customers --soft-delete
shell
php artisan apitoolz:datatable customers --remove
shell
php artisan apitoolz:datatable customers --add-field=gender --type=string --field-after=email --not-null --default=other
shell
php artisan apitoolz:datatable customers --update-field=phone_number --type=string --not-null
shell
    php artisan apitoolz:request Sale --field=sale_date --validator="
shell
    php artisan apitoolz:request Incident --field=description --criteria-key=type --criteria-value=help --position=1
    
shell
    php artisan apitoolz:request Sale --field=sale_date --reset
    
shell
    php artisan apitoolz:response Product --field=name --label="Product Name" --visible=true --export=true --position=1
    
shell
    php artisan apitoolz:response Product --field=internal_notes --visible=false
    
shell
    php artisan apitoolz:summary Product --title="Total Products" --type=kpi --icon=box --method=count
    
shell
    php artisan apitoolz:summary Product --doc
    
shell
    php artisan apitoolz:relation Customer --title=phone --relation-model=Phone --relation-type=hasOne
    
shell
php artisan apitoolz:relation Customer --title=orders --relation-model=Order --relation-type=hasMany --display-field=order_number
shell
php artisan apitoolz:rebuild --model=Customer
shell
php artisan apitoolz:model Customer --remove
shell
    php artisan apitoolz:export --
shell
    php artisan apitoolz:export --model=Customer --
shell
php artisan queue:work
shell
php artisan queue:work --queue=high
shell
php artisan queue:work --daemon