PHP code example of fukibay / laravel-starter-pack
1. Go to this page and download the library: Download fukibay/laravel-starter-pack 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/ */
fukibay / laravel-starter-pack example snippets
// app/Services/UserService.php (Otomatik oluşturulan kod)
namespace App\Services;
use App\Repositories\Contracts\UserRepositoryInterface;
use Fukibay\StarterPack\Traits\ProxiesSoftDeletes; // OTOMATİK EKLENDİ!
class UserService extends BaseService
{
use ProxiesSoftDeletes; // OTOMATİK EKLENDİ!
public function __construct(UserRepositoryInterface $userRepository)
{
parent::__construct($userRepository);
}
}
// app/Providers/AppServiceProvider.php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use App\Repositories\Contracts\UserRepositoryInterface;
use App\Repositories\PostgreSql\UserRepository; // Yapılandırmanıza göre doğru yolu seçin
class AppServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->app->bind(
UserRepositoryInterface::class,
UserRepository::class
);
}
// ...
}
// Bir Controller veya başka bir Service içinde...
use App\Services\UserService;
use App\Repositories\Criteria\QueryParameters;
class UserController extends Controller
{
public function __construct(private UserService $userService) {}
public function index()
{
$criteria = new QueryParameters(
filters: [
'status' => 'approved',
'score' => ['>', 80],
'exists' => ['profile'], // 'profile' ilişkisi olanlar
],
relations: ['profile', 'posts'], // Eager loading
orderBy: ['created_at' => 'desc']
);
$users = $this->userService->paginate($criteria);
// ...
}
}
// Örnek bir Controller'da
use App\Traits\ApiResponder;
class UserController extends Controller
{
use ApiResponder;
public function show($id)
{
$user = $this->userService->findById($id);
if (!$user) {
return $this->error('Kullanıcı bulunamadı', 404);
}
return $this->success(new UserResource($user));
}
}
// Örnek bir Service'te
use App\Traits\HandlesFiles;
class UserService extends BaseService
{
use HandlesFiles;
public function updateUserAvatar(int $userId, UploadedFile $avatar)
{
$user = $this->findByIdOrFail($userId);
// Eski avatarı silip yenisini yükler ve yolunu döner
$path = $this->updateFile($avatar, 'avatars', $user->avatar_path);
return $this->update($userId, ['avatar_path' => $path]);
}
}