承接 dizatech/helper 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

dizatech/helper

最新稳定版本:v0.3.1

Composer 安装命令:

composer require dizatech/helper

包简介

This is a package of simple helper functions which may be useful in any laravel project.

README 文档

README

Dizatech is a package developed to add validation, banking and view helpers to Laravel projects with Iranian/Persian projects' needs in mind. This package is highly inspired by the works of my dear friend and colleague @imvahid.

Installation

  1. Require the package via composer
composer require dizatech/helper
  1. Run the following command to publish package files
php artisan vendor:publish --provider=Dizatech\Helper\DizatechHelperServiceProvider

Validation Rules

National Code

برای اعتبار سنجی کد ملی شخص حقیقی

Add new NationalCode() to validation rules array. String passed for validation must be 10 characters long. National codes with zero(s) in the begining should be passed as string with their leading zeros. It's recommended to zero-pad national codes before using them for any purpose, including validation.

Zero-padding example

Bare php:
$national_code = str_pad($code, 10, '0', STR_PAD_LEFT);
Inside Laravel reuest file:
<?php

namespace App\Http\Requests;

use Dizatech\Helper\Rules\NationalCode;
use Illuminate\Foundation\Http\FormRequest;

class MyRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'national_code' => ['required', new NationalCode()],
        ];
    }

    public function prepareForValidation()
    {
        if ($this->has('national_code')) {
            $this->merge([
                'national_code' => str_pad($this->national_code, 10, '0', STR_PAD_LEFT)
            ]);
        }
    }
}
Validation in laravel controller:
public function handleForm(Request $request)
{
    if ($request->has('national_code')) {
        $request->merge(
            ['national_code' => str_pad($this->national_code, 10, '0', STR_PAD_LEFT)]
        );
    }
    $rules = [
        'national_code' => ['required', new NationalCode()],
    ];
    $request->validate($rules);
});

National Id

برای اعتبار سنجی شناسه ملی شخص حقوقی

Add new Nationalid() to validation rules array. String passed for validation must be 11 characters long.

Internationalization

If you haven't run php artisan vendor:publish command yet, first run the floowing command to publish language files:

php artisan vendor:publish --provider=Dizatech\Helper\DizatechHelperServiceProvider

Language files will be copied to en and fa folders inside lang folder of your project. You can customize error message as desired. Make sure you set coorect locale for your app in config/app.php. For Farsi it shuld be set as:

'locale' => 'fa'

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-11-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固