1. Go to this page and download the library: Download artflow-studio/snippets 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/ */
artflow-studio / snippets example snippets
use Livewire\Attributes\On;
class MyComponent extends Component
{
#[On('afdropdown:selected')]
public function customerSelected($payload)
{
$customerId = $payload['id'];
$customerData = $payload['data'];
// Handle selection...
}
}
#[On('afdropdown:selected')]
public function handleSelection($payload)
{
// $payload['id'] - Model ID
// $payload['label'] - Display label
// $payload['data'] - Full model data
// $payload['model'] - Model class name
}
#[On('afdropdown:cleared')]
public function handleClear()
{
// Search was cleared
}
use ArtFlowStudio\Snippets\Traits\GeneratesUniqueIds;
class Invoice extends Model
{
use GeneratesUniqueIds;
protected $uniqueIdColumn = 'invoice_number';
protected $uniqueIdStrategy = '6digit'; // or 'base36'
}
// Usage
$invoice = Invoice::create([...]);
// invoice_number is auto-generated: "123456" or "ABC123D"
use ArtFlowStudio\Snippets\Traits\FormatsData;
class Customer extends Model
{
use FormatsData;
}
// Pakistani phone number formatting
Customer::formatPhoneNumber('03001234567'); // +92-300-1234567
// CNIC formatting
Customer::formatCNIC('12345-1234567-1'); // 12345-1234567-1
#[On('afdropdown:selected')]
public function selected($payload) { }
// Component
class CreateOrder extends Component
{
public ?int $customerId = null;
#[On('afdropdown:selected')]
public function customerSelected($payload)
{
$this->customerId = $payload['id'];
}
public function render()
{
return view('create-order');
}
}
// View
@livewire('afdropdown', [
'model' => 'App\Models\Customer',
'column' => 'name',
'placeholder' => 'Search customers...',
])
[
'id' => 123, // Primary key of selected item
'label' => 'John Doe', // Value of search column
'class' => 'App\\Models\\Customer', // Full model class name
'data' => [ // Complete model data
'id' => 123,
'name' => 'John Doe',
'email' => '[email protected]',
// ... all model attributes
]
]
namespace App\Livewire\BranchManager\Invoices;
use Livewire\Attributes\On;
use Livewire\Component;
class CreateInvoice extends Component
{
public $customer_id = '';
public $customer_name = '';
#[On('afdropdown-selected')]
public function handleCustomerSelected($data)
{
// Only process Customer model selections
if ($data['class'] === 'App\\Models\\Customer') {
$this->customer_id = $data['id'];
$this->customer_name = $data['label'];
// You can also access complete model data
$email = $data['data']['email'] ?? null;
// Emit event to other components if needed
$this->dispatch('customer-selected', ['id' => $this->customer_id]);
}
}
public function render()
{
return view('livewire.invoices.create-invoice');
}
}
#[On('afdropdown-selected')]
public function handleSelection($data)
{
match ($data['class']) {
'App\\Models\\Customer' => $this->handleCustomer($data),
'App\\Models\\Supplier' => $this->handleSupplier($data),
'App\\Models\\Product' => $this->handleProduct($data),
default => null
};
}
private function handleCustomer($data)
{
$this->customer_id = $data['id'];
}
private function handleSupplier($data)
{
$this->supplier_id = $data['id'];
}
private function handleProduct($data)
{
$this->product_id = $data['id'];
}
#[On('afdropdown-cleared')]
public function handleSearchCleared()
{
$this->customer_id = '';
$this->customer_name = '';
}
namespace App\Livewire;
use Livewire\Component;
class CreateInvoice extends Component
{
public $customer_id = '';
#[On('afdropdown-selected')]
public function handleCustomerSelected($data)
{
if ($data['class'] === 'App\\Models\\Customer') {
$this->customer_id = $data['id'];
}
}
public function render()
{
return view('livewire.invoices.create-invoice');
}
}
public function getListeners()
{
return [
'afdropdown-selected' => 'handleCustomerSelected',
];
}
public function handleCustomerSelected($data)
{
if ($data['class'] === 'App\\Models\\Customer') {
$this->customer_id = $data['id'];
}
}
namespace App\Livewire;
use ArtFlowStudio\Snippets\Http\Livewire\AFdropdown;
class CustomCustomerDropdown extends AFdropdown
{
public function loadResults()
{
$this->results = [];
if (strlen($this->search) >= $this->minSearchLength && class_exists($this->model)) {
try {
$model = new $this->model;
$query = $model->where($this->column, 'like', '%' . $this->search . '%')
->where('is_active', true) // Only active customers
->where('branch_id', auth()->user()->branch_id) // User's branch only
->whereNull('deleted_at'); // Not deleted
$items = $query->limit($this->resultLimit)->get();
$this->results = $items->map(function($item) {
return $this->formatResult($item);
})->toArray();
} catch (\Exception $e) {
$this->results = [];
}
}
}
}
class YourLivewireComponent extends Component
{
public $city = '';
protected $listeners = ['updateField' => 'setField'];
public function setField($field, $value)
{
$this->$field = $value;
}
}
// Generate unique ID for a model
$uniqueId = generateUniqueID(User::class, 'user_id');
// Generate 6-digit unique ID
$id = unique6digitID(); // Returns: "123456"
// Generate Base36 unique ID
$id = generateUniqueBase36ID(); // Returns: "AB12CD"
// In your model
class User extends Model
{
protected static function boot()
{
parent::boot();
static::creating(function ($model) {
$model->user_id = generateUniqueID(self::class, 'user_id');
});
}
}
// Format Pakistani phone numbers
echo formatContactPK('03001234567'); // +923001234567
echo formatContactPK('00923001234567'); // +923001234567
echo formatContactPK('+923001234567'); // +923001234567
echo formatContactPK('923001234567'); // +923001234567
// International numbers pass through
echo formatContactPK('+12345678901'); // +12345678901
class User extends Model
{
// Automatically format phone on save
public function setPhoneAttribute($value)
{
$this->attributes['phone'] = formatContactPK($value);
}
// Automatically format CNIC on save
public function setCnicAttribute($value)
{
$this->attributes['cnic'] = formatCnicPK($value);
}
}