PHP code example of seangly / laravel-csrm
1. Go to this page and download the library: Download seangly/laravel-csrm 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/ */
seangly / laravel-csrm example snippets
// Read operations
$user = $repository->find(1);
$users = $repository->all();
$users = $repository->paginate(15);
$user = $repository->findBy('email', '[email protected] ');
// Write operations
$created = $repository->create($data);
$updated = $repository->update($id, $data);
$deleted = $repository->delete($id);
public function create(array $data): User
{
// Add validation, transformation, logging, etc.
return $this->repository->create($data);
}
public function update(int $id, array $data): User
{
// Add business logic before/after update
return $this->repository->update($id, $data);
}
public function delete(int $id): bool
{
// Add cleanup, cascading operations, etc.
return $this->repository->delete($id);
}
$this->app->bind(
\App\Repositories\Contracts\UserRepositoryInterface::class,
\App\Repositories\UserRepository::class,
);
public function __construct(UserRepositoryInterface $repository)
{
$this->repository = $repository;
}
use App\Http\Controllers\Api\ArticleController;
Route::apiResource('articles', ArticleController::class);
// app/Services/ArticleService.php
public function publishArticles()
{
return $this->repository->query()->whereNotNull('published_at')->get();
}
public function archiveOldArticles($months = 12)
{
return $this->repository->where(
'created_at', '<', now()->subMonths($months)
)->delete();
}
// app/Services/ArticleStatisticsService.php
public function __construct(
ArticleRepositoryInterface $repository,
UserRepositoryInterface $userRepository
)
{
$this->repository = $repository;
$this->userRepository = $userRepository;
}
bash
php artisan list | grep csrm
bash
php artisan csrm:install
bash
php artisan csrm:install --force
bash
php artisan csrm:make Post
bash
php artisan csrm:make Product --only=model,migration,repository
bash
php artisan csrm:make Order --force
app/
├── Http/
│ ├── Controllers/
│ │ ├── BaseController.php
│ │ ├── UserController.php
│ │ └── ...
├── Models/
│ ├── User.php
│ └── ...
├── database/
│ └── migrations/
│ └── *_create_users_table.php
├── Repositories/
│ ├── Contracts/
│ │ ├── BaseRepositoryInterface.php
│ │ ├── UserRepositoryInterface.php
│ │ └── ...
│ ├── BaseRepository.php
│ ├── UserRepository.php
│ └── ...
├── Services/
│ ├── BaseService.php
│ ├── UserService.php
│ └── ...
└── Providers/
└── AppServiceProvider.php (updated with repository bindings)
bash
php artisan vendor:publish --tag=csrm-stubs
bash
php artisan migrate
bash
php artisan cache:clear
php artisan config:cache
bash
composer dump-autoload
bash
php artisan optimize:clear