baconfy/support 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

baconfy/support

最新稳定版本:1.7.1

Composer 安装命令:

composer require baconfy/support

包简介

Some functionalities

README 文档

README

A handy Laravel support package offering reusable traits for common model behavior like UUIDs and slugs — perfect for keeping your code clean and consistent.

🚀 Features

  • ✅ Auto UUID generation for Eloquent models
  • 🔗 Unique slugs (with optional soft delete awareness)
  • 🧩 Drop-in traits — quick to use, easy to maintain
  • 🔄 Minimal setup, maximum utility

📦 Installation

composer require baconfy/support

⚙️ Usage

Casts

Storage cast for eloquent models

<?php

declare(strict_types=1);

namespace App\Models;

use Baconfy\Support\Casts\AsStorage;
use Database\Factories\UserFactory;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

final class User extends Authenticatable implements MustVerifyEmail
{
    /** @use HasFactory<UserFactory> */
    use HasFactory, Notifiable, SoftDeletes;

    /**
     * The attributes that should be hidden for serialization.
     *
     * @var list<string>
     */
    protected $hidden = [
        'password',
        'remember_token',
    ];

    /**
     * Get the attributes that should be cast.
     *
     * @return array<string, string>
     */
    public function casts(): array
    {
        return [
            'email_verified_at' => 'datetime',
            'password' => 'hashed',
            'avatar' => AsStorage::class,
        ];
    }
}

FormRequest

A better way to validate your forms. Available methods: authorize, view, store, update, destroy.

<?php

declare(strict_types=1);

namespace App\Http\Requests;

use App\Models\User;
use Baconfy\Support\Http\FormRequest;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Validation\Rule;

final class ProfileRequest extends FormRequest
{
    /**
     * Get the validation rules that apply to the post request.
     *
     * @return array<string, ValidationRule|array<mixed>|string>
     */
    public function store(): array
    {
        return [
            'name' => ['required', 'string', 'max:255'],
            'email' => ['required', 'string', 'lowercase', 'email', 'max:255', Rule::unique(User::class)],
        ];
    }
    
    /**
     * Get the validation rules that apply to the put/patch request.
     *
     * @return array<string, ValidationRule|array<mixed>|string>
     */
    public function update(): array
    {
        return [
            'name' => ['required', 'string', 'max:255'],
            'email' => ['required', 'string', 'lowercase', 'email', 'max:255', Rule::unique(User::class)->ignore($this->user()->id)],
        ];
    }
}

UUIDs

Add automatic UUIDs to your models:

use Baconfy\Support\Concerns\Uuid;

class User extends Model
{
    use Uuid;
}

Slugs

Generate unique slugs from an attribute:

use Baconfy\Support\Concerns\Slugfy;

class Post extends Model
{
    use Slugfy;
}

✨ If the slug already exists, a suffix is added automatically to keep it unique — even with soft deletes!

📄 License

MIT — do what you want, just give credit.
Made with ❤️ by Baconfy

统计信息

  • 总下载量: 1.34k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-01-18