PHP code example of ashique-ar / laravel-crud-generator
1. Go to this page and download the library: Download ashique-ar/laravel-crud-generator 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/ */
ashique-ar / laravel-crud-generator example snippets
use AshiqueAr\LaravelCrudGenerator\Facades\CrudGenerator;
// Register all CRUD routes with prefix and middleware
CrudGenerator::registerRoutes('api/v1', ['auth:sanctum']);
// Configuration examples for different model locations
'resources' => [
// Simple model in App\Models
'users' => [
'model' => App\Models\User::class,
// ... other config
],
// Model in subfolder
'profiles' => [
'model' => App\Models\User\Profile::class,
// ... other config
],
// Model in admin subfolder
'admin-users' => [
'model' => App\Models\Admin\User::class,
// ... other config
],
// Model in completely different namespace
'products' => [
'model' => Modules\Catalog\Models\Product::class,
// ... other config
]
]
namespace App\Services\Crud;
use AshiqueAr\LaravelCrudGenerator\Services\Crud\BaseCrudLogic;
use App\Models\User;
class UserLogic extends BaseCrudLogic
{
protected string $modelClass = User::class;
public function beforeCreate(array $data, Request $request): array
{
// Add custom logic before creating
$data['created_by'] = auth()->id();
return $data;
}
public function afterCreate(Model $user, Request $request): void
{
// Send welcome email
Mail::to($user)->send(new WelcomeEmail($user));
}
// Override other methods as needed
}