PHP code example of salamzadeh / pb-helper

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

    

salamzadeh / pb-helper example snippets


use PBHelper\EloquentHelper;

class User extends Model
{
    use EloquentHelper; // trait
}

$user = User::where(...)->first();
$user->created_at_fa // به صورت کلاس Hekmatinasser\Verta\Verta
$user->created_at_fa_f // 1390/1/1
$user->created_at_fa_ft // 1390/1/1 12:00
$user->created_at_fa_ftt // 1390/1/1 12:00:00
$user->updated_at_fa->format("%B %d %Y") // فروردین 01 1390

$user->created_at_fa = Verta::createJalaliDate(1390, 1, 1);
dd($user->created_at); // Illuminate\Support\Carbon { date: 2011-03-21 }
$user->created_at_fa = "1392/1/1";
dd($user->created_at); // Illuminate\Support\Carbon { date: 2013-03-21 }
$user->created_at_fa = "1395/1/1 14:22:11";
dd($user->created_at); // Illuminate\Support\Carbon { date: 2016-03-20 14:22:11 }

use PBHelper\EloquentHelper;

class User extends Model
{
    use EloquentHelper;

    protected $casts = [
        'birth_date' => 'date',
        // یا
        'released_at' => 'datetime'
    ];
}

$user->birth_date_fa; // Hekmatinasser\Verta\Verta

User::whereJalali('created_at', '1399/01/15 14:00:00')->get();
// یا
User::whereJalali('created_at', Verta::createJalali(1399,01,15, 14, 0, 0))->get();
// شرط با عملگر
User::whereJalali('created_at', '>', '1399/01/15 14:00:00')->get();

User::whereDateJalali('created_at', '1399/01/15')->get();
// یا
User::whereDateJalali('created_at', Verta::createJalaliDate(1399,01,15))->get();
// شرط با عملگر
User::whereDateJalali('created_at', '>', '1399/01/15')->get();

User::whereInMonthJalali('created_at', 3)->get(); // فقط کاربران ایجاد شده در خرداد ماه سال جاری

User::whereInMonthJalali('created_at', 3, 1397)->get(); // فقط کاربران ایجاد شده در خرداد ماه سال 1397

User::whereInYearJalali('created_at')->get(); // فقط کاربران ایجاد شده در سال جاری

User::whereInYearJalali('created_at', 1397)->get(); //فقط کاربران ایجاد شده در سال 1397

User::whereBetweenJalali('created_at', ['1400/03/26 12:00:00', '1400/05/26 12:00:00'])->get(); // فقط کاربران ایجاد شده بین دو تاریخ مشخص شده
// یا
User::whereBetweenJalali('created_at', [Verta::createJalali(1400,01,15, 14, 0, 0), Verta::createJalali(1399,01,15, 14, 0, 0)])->get(); 
// شرط با Not
User::whereNotBetweenJalali('created_at', ['1400/03/26 12:00:00', '1400/05/26 12:00:00'])->get(); // همه کاربران به جز کاربران ایجاد شده در تاریخ مشخص


\PBHelper\Middleware\FixRequestInputs

protected $middleware = [
    ...
    \PBHelper\Middleware\FixRequestInputs::class,
];

public function test(Request $request)
{
    $request->validate([
        'mobile1' => 'ue', // وارد کردن صفر در اول شماره اختیاری
    ]);
}

customImage($path, $width, $height, $prefix)

'image' => $faker->customImage(public_path('uploads/fake'), 640, 480, 'fake/')

$faker->customImages(public_path('uploads/fake'), 640, 480, $faker->numberBetween(1, 3), 'fake/')

$faker->iranMobile

$faker->iranPhone

public function run()
{
    $this->call(\PBHelper\Database\CitiesTableSeeder::class); // سیدر شهر ها و استان ها
}

use PBHelper\Models\City;

City::where('name', 'آمل')->first()

use PBHelper\Models\Province;
use PBHelper\Models\City;

Route::get('test/{province}/{city}', function (Province $province, City $city) {
    abort_if($city->province_id != $province->id, 404);
    // ...
});

Str::slug('test test')

Str::slug('خونه ی مادربزرگه')

str_to_slug('خونه ی مادربزرگه')

'method' => 'str_to_slug',

find_bank_by_card_number("6037697531")

[
    "class" => "bsi",
    "name" => "بانک صادرات ایران",
    "card_prefix" => "603769",
]
bash
php artisan vendor:publish --provider=PBHelper\\PBHelperServiceProvider

config/pb-helper.php
bash
php artisan migrate --seed