1. Go to this page and download the library: Download teksite/handler 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/ */
teksite / handler example snippets
'providers' => [
// Other Service Providers
Teksite\Handler\HandlerServiceProvider::class,
],
return ServiceWrapper::make()->do(function () {
// your code
})->ifFailed(function () {
// in case your code failed
})->run();
use Teksite\Handler\Facade\FetchData;
use Teksite\Handler\Services\ServiceWrapper;
public function get(mixed $fetchData = [])
{
return ServiceWrapper::make()
->do(function () use ($fetchData) {
return FetchData::get(Post::class, ['title'], ...$fetchData);
})
->ifFailed(function () {
// Handle failure
})
->run(dispatchSuccessEvent: true);
}
use Teksite\Handler\Facade\FetchData;
// Without ServiceWrapper
$posts = FetchData::get(Post::class, ['title']);
$posts = FetchData::only(['id', 'title'])
->with(['user'])
->search(['title', 'category'])
->orderBy('title')
->sort('asc')
->perPage(20)
->limitPagination(100)
->get(Post::class);
// Clear all fluent configuration on a shared instance before reusing it
FetchData::reset();
FetchData::get(
string|Model|Builder|Relation|Closure $model, // Model class, model instance, query builder, relation, or a closure returning a Builder
string|array|null $searchColumns = null, // Search columns with operators
array|string|null $only = null, // Columns to select (defaults to all)
null|int|false $perPage = null, // Items per page (pagination)
null|false|int $limitPagination = null, // Maximum items per page limit
array $with = [], // Relations to eager load
array $withCount = [] // Relations to count
): \Illuminate\Support\Collection|\Illuminate\Pagination\LengthAwarePaginator;
use Teksite\Handler\Services\ResponderServices;
// Success response
$response = ResponderServices::success('Well done!', ['post' => $post], 201);
// Failure response
$response = ResponderServices::failed('Something went wrong', ['auth' => 'forbidden'], 500);
// Redirect as HTTP response
$response->go();
// Return as JSON response (for APIs and AJAX)
$response->reply();
namespace App\Events;
use Illuminate\Foundation\Events\Dispatchable;
class UserCreationSucceeded
{
use Dispatchable;
public function __construct(public $user)
{
//
}
}