PHP code example of cuongnd88 / jutility

1. Go to this page and download the library: Download cuongnd88/jutility 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/ */

    

cuongnd88 / jutility example snippets


$ composer 

php artisan vendor:publish --provider="Cuongnd88\Jutility\JutilityServiceProvider"

php artisan vendor:publish --provider="Cuongnd88\Jutility\JutilityServiceProvider" --tag=public

. . . .

    <div class="form-group row">
        <label for="email" class="col-md-4 col-form-label text-md-right">{{ __('Post code') }}</label>

        <div class="col-md-6">
            <input id="zip" type="text" class="form-control" name="email" value="" onkeyup="JPostal.capture('#zip', ['#info'])">
        </div>
    </div>

    <div class="form-group row">
        <label for="password" class="col-md-4 col-form-label text-md-right">{{ __('Info') }}</label>

        <div class="col-md-6">
            <input id="info" type="text" class="form-control" name="info">
        </div>
    </div>

. . . .
<script type="text/javascript" src="{{ asset('js/jpostal/jpostal.js') }}"></script>
<script type="text/javascript">
    JPostal.init();
</script>

	<div class="col-md-6">
	    <input id="zip" type="text" class="form-control" name="email" value="" onkeyup="JPostal.capture('#zip', ['.prefecture', '.city', '.area', '.street'])">
	</div>

<script type="text/javascript">
    JPostal.init();

    $( "#zip" ).keyup(function() {
        JPostal.capture('#zip', function(data){
            console.log(data);
        });
    });
</script>

. . . .
    <div class="form-group row">
        <label class="col-md-4 col-form-label text-md-right">{{ __('Prefecture') }}</label>

        <div class="col-md-6">
            <select class="form-control selectPrefecture" id="selectPrefecture">
            </select>
        </div>
    </div>

    <div class="form-group row">
        <label class="col-md-4 col-form-label text-md-right">{{ __('City') }}</label>

        <div class="col-md-6">
            <select class="form-control selectCity" id="selectCity">
            </select>
        </div>
    </div>
. . . .

<script type="text/javascript" src="{{ asset('js/jpostal/jpostal.js') }}"></script>
<script type="text/javascript">
    JPostal.init();

    JPostal.innerPrefecturesHtml(function(prefectures){
        let selectTag = '<option value="">Prefecture</option>';
        for (const [key, value] of Object.entries(prefectures)) {
            selectTag += `<option value="${key}">${value}</option>`;
        }
        $('#selectPrefecture').append(selectTag);
    });

    $("#selectPrefecture").change(function(){
        JPostal.innerCityHtmlByPref('#selectPrefecture', function(cities){
            let selectTag = '<option value="">City</option>';
            for (const item in cities) {
                const {id, name} = cities[item];
                selectTag += `<option value="${id}">${name}</option>`;
            }
            $('#selectCity').append(selectTag);
        });
    });
</script>

dump(jpostal_pref(47));

dump(jpostal_pref_city(47));
dump(jpostal_pref_city(1, '01101));

    dump(jpostal_code('1200000'));
    dump(jpostal_code('120-0000'));

    dump(jlang('Add Team Member'));

. . . .
    'locale' => 'ja',
. . . .

/resources
    /lang
        /en
            messages.php
        /ja
            messages.php

return [
    /*
    |--------------------------------------------------------------------------
    | UTF-8 Bom
    |--------------------------------------------------------------------------
    |
    | The UTF-8 BOM is a sequence of bytes at the start of a text stream (0xEF, 0xBB, 0xBF)
    | that allows the reader to more reliably guess a file as being encoded in UTF-8.
    | Suitable for exporting Japanese data
    |
    */
    'utf-8-bom' => false,

    /*
    |--------------------------------------------------------------------------
    | Validator Support
    |--------------------------------------------------------------------------
    |
    | This is a sample defines how to validate CSV data:
    | - `user.header` is to identify the format of CSV file, that compare the standard header to the CSV header.
    | The "Invalid Header" message of Exception is threw if there is an error
    |
    | - `user.validator` is based on Laravel Validator. If you have multiple user tables or models you may configure multiple
    |       + `user.validator.rules`: set the Laravel validation rules
    |       + `user.validator.messages`: customize the Laravel default error messages
    |       + `user.validator.attributes`: customize the validation attributes
    */
    'user' => [
        'header' => [
            'fname' => 'First Name',
            'lname' => 'Last Name',
            'email' => 'Email',
        ],
        'validator' => [
            'rules' => [
                'fname' => '

. . . .
use Cuongnd88\Jutility\Facades\CSV;

class UserController extends Controller
{
    . . . .
    public function postCSV(Request $request)
    {
        $csv = CSV::read(
                    $request->csv,
                    config('csv.user.header'),
                    config('csv.user.validator')
                )->filter();
        dump($csv);
    }
}
. . . .

    public function postCSV(Request $request)
    {
        $csv = CSV::read(
                    $request->csv,
                    config('csv.user.header'),
                    config('csv.user.validator')
                );
        $data = $csv->get();
        dump($data);
        $errorList = $csv->validatorErrors();
        dump($errorList);
    }

    public function downloadCSV()
    {
        $data = User::all()->toArray();
        $header = ['ID','Fullname','Email','Mobile number', 'Email verified data time', 'Created date time', 'Updated date time'];
        CSV::save('user-data', $data, $header);
    }