PHP code example of nexus-smart-solutions / crud-engine
1. Go to this page and download the library: Download nexus-smart-solutions/crud-engine 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/ */
nexus-smart-solutions / crud-engine example snippets
use Illuminate\Database\Eloquent\Model;
use Nexus\CrudEngine\Contracts\Capabilities\FileUpload;
use Nexus\CrudEngine\Contracts\Capabilities\HasManyRelations;
use Nexus\CrudEngine\Traits\HasFileUrlsTrait;
class Product extends Model implements FileUpload, HasManyRelations
{
use HasFileUrlsTrait; // rewrites file attributes into full URLs in toArray()
public function documentFullPathStore(): string
{
// Any structure you want — the package never assumes one.
return 'products/'.$this->getKey();
}
public function requestKeysForFile(): array
{
return ['cover_image'];
}
public function getHasManyRelations(): array
{
return ['variants'];
}
public function variants()
{
return $this->hasMany(ProductVariant::class);
}
}
use Nexus\CrudEngine\Services\Crud\AbstractStoreService;
class ProductStoreService extends AbstractStoreService
{
public function model(): string
{
return Product::class;
}
public function requestFile(): string
{
return ProductStoreRequest::class; // any class with a public rules(): array method
}
}
class ProductController extends Controller
{
public function store(ProductStoreService $service)
{
$result = $service->store();
return response()->success($result->data, $result->messages, $result->code);
}
}
use Nexus\CrudEngine\Services\Crud\AbstractUpdateService;
use Illuminate\Database\Eloquent\Model;
class ProductUpdateService extends AbstractUpdateService
{
public function __construct(private Product $product, /* ...parent deps via DI... */) { /* ... */ }
public function model(): string { return Product::class; }
public function requestFile(): string { return ProductUpdateRequest::class; }
public function resolveModel(): Model { return $this->product; }
}
use Nexus\CrudEngine\Services\Crud\AbstractBulkDeleteService;
class ProductBulkDeleteService extends AbstractBulkDeleteService
{
public function model(): string
{
return Product::class;
}
}
use Nexus\CrudEngine\Services\Statistics\AbstractStatisticsService;
class ProductStatisticsService extends AbstractStatisticsService
{
public function getModelClass(): string { return Product::class; }
public function getDateColumn(): string { return 'created_at'; }
}
// In a controller:
$service->getStatistics('2026-01-01', '2026-01-31', 'days');
// => ['2026-01-01' => 3, '2026-01-02' => 0, ..., '2026-01-31' => 1]
// Migrations
Schema::create('products', function (Blueprint $table) {
$table->id();
$table->status(); // tinyInteger('status')->default(1)
$table->standardTime(); // created_at, updated_at, soft deletes
});
// Queries
Product::query()->customOrdering('name', 'asc'); // or relation: 'category.name'
Product::query()->datesFiltering(); // reads period_type/from_date/to_date from the request
// Carbon
Carbon::parseOrNow($maybeInvalidDate); // never throws
// Str
Str::snakeToTitle('product_name'); // "Product Name"
Str::humanText('product---name!!'); // "Product Name"
// Responses
return response()->success($data, ['crud-engine::responses.success.created']);
return response()->error('Something specific went wrong.');
Event::listen(RecordCreated::class, function (RecordCreated $event) {
Cache::forget("product:{$event->model->getKey()}");
});