think.studio/laravel-forms-entries 问题修复 & 功能扩展

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

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

think.studio/laravel-forms-entries

最新稳定版本:3.2.0

Composer 安装命令:

composer require think.studio/laravel-forms-entries

包简介

Package to save forms entries and send notifications.

README 文档

README

Packagist License Packagist Version Total Downloads Build Status Code Coverage Scrutinizer Code Quality

Package to save forms entries (like contact us forms ...) and send notifications

Installation

Install the package via composer:

composer require think.studio/laravel-forms-entries

You can publish the assets file with:

php artisan vendor:publish --provider="FormEntries\ServiceProvider" --tag="config"
php artisan vendor:publish --provider="FormEntries\ServiceProvider" --tag="lang"

To disable default migrations add this code to app service provider:

use FormEntries\Forms\Form;
use FormEntries\Forms\FormContent;

\FormEntries\FormEntryManager::ignoreMigrations()

Form::typesMap([
    'form-contact' => ContactUsForm::class,
]);
FormContent::typesMap([
    'contact-us' => ContactUsFormContent::class,
]);

You can add default routes to your web.php

\FormEntries\Facades\FormEntryManager::routes();

Usage

Use predefined classes

In case you do not need custom classes with validation.

$formEntry = \FormEntries\Forms\UniversalForm::make()
                ->enableStoringData()
                ->enableNotifications()
                ->process($request);

Use custom form and content

// /app/Http/FormEntries/FormContent/ContactUsFormContent.php
class ContactUsFormContent extends FormContent
{
    protected array $requestKeysToSave = ['email', 'message'];

    public function validateRequest(Request $request): static
    {
        $request->validate([
            'email'   => ['required', 'email'],
            'message' => ['required', 'min:10', 'max:500'],
        ]);

        return $this;
    }
}
// /app/Http/FormEntries/Forms/ContactUsForm.php
class ContactUsForm extends Form
{
    protected string $formContentClass = ContactUsFormContent::class;

    public function notify(FormEntry $model): bool
    {
        Notification::route('mail', 'tester@test.admin')
                    ->notify(new ($this->getFormNotificationClass())($model->content));

        return true;
    }
}
<form action="{{route('forms-entries.submit')}}"
      method="post"
>
    @csrf
    <input type="hidden"
           name="{{config('forms-entries.routing.form_name_parameter')}}"
           value="{{\App\Http\FormEntries\Forms\FolioMetricsForm::getType()}}">
    Other fields
    <button type="submit">Submit</button>
</form>

Credits

  • Think Studio

统计信息

  • 总下载量: 26
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 4
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-09-10