PHP code example of carone / laravel-common

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

    

carone / laravel-common example snippets


use Carone\Common\Search\SearchTerm;
use Carone\Common\Search\SearchCriteria;

$searchTerm = new SearchTerm('john doe');
$criteria = new SearchCriteria($searchTerm, [$statusFilter, $dateFilter]);

// In your repository implementing AppliesSearchCriteria:
$query = $this->applySearchCriteria($criteria);

use Carone\Common\BulkOperations\BulkOperation;

$operation = BulkOperation::create(function($user) {
    $user->activate();
    $user->save();
});

$result = $operation->execute(
    $users,
    successHandler: fn($user) => Log::info("Activated: {$user->id}"),
    failureHandler: fn($user, $e) => Log::error("Failed: {$user->id}")
);

$succeeded = $result->getSucceeded();
$failed = $result->getFailed();
$failedWithErrors = $result->getFailedWithErrors();