Skip to content

Instantly share code, notes, and snippets.

<?php
Builder::macro('deferredPaginate', function ($perPage = null, $columns = ['*'], $pageName = 'page', $page = null) {
$model = $this->newModelInstance();
$key = $model->getKeyName();
$table = $model->getTable();
$paginator = $this->clone()
// We don't need them for this query, they'll remain
// on the query that actually gets the records.
@miken32
miken32 / Cidr.php
Last active October 24, 2023 07:27
Laravel CIDR validation rule
<?php
namespace App\Rules;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use const FILTER_FLAG_IPV4;
use const FILTER_FLAG_IPV6;
use const FILTER_VALIDATE_INT;
@juampi92
juampi92 / RequestBuilder.php
Created November 7, 2019 10:02
Build Requests with routes on Laravel for testing.
<?php
use Illuminate\Http\Request;
use Illuminate\Routing\Route;
use Illuminate\Support\Facades\Route as Router;
class RequestBuilder
{
/**
* Will create a request with the correct fullUrl, route parameters and input parameters.
@Akimkin
Akimkin / tzlist.php
Last active December 8, 2022 08:46
Get list of timezones translated to given language in PHP
<?php
/**
* Get list of timezones translated in given language
*
* Requires PHP Intl extension to be present & active in your PHP setup
*
* @param string $langcode - an ISO 639-1 language code
* @return array
*/
@cse031sust02
cse031sust02 / push.php
Created January 24, 2018 11:23
Send push notification using Firebase
<?php
use GuzzleHttp;
$access_token = 'FIREBASE CLOUD MESSAGING SERVER KEY';
$reg_id = 'DEVICE REGISTRATION ID';
$message = [
'notification' => [
@Alymosul
Alymosul / README.md
Last active May 9, 2024 13:37
[Laravel] Seeding data in testing as part of the application build.

SeedDatabase trait along with SeedDatabaseState class gives your Laravel project the ability to seed the testing database once before running the full suite tests, which improves the speed of the tests than seeding the testing database before each test.

Also, it has the option to run custom seeders instead of the seeders that are called in the run() method of the DatabaseSeeder class you can achieve that as follows

...in the Testcase.php

public function setUp()

{

@paulofreitas
paulofreitas / AuthServiceProvider.php
Last active July 7, 2023 13:15
Extending the default Eloquent User Provider (Laravel 5.4+)
<?php
namespace App\Providers;
use App\Auth\UserProvider;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
class AuthServiceProvider extends ServiceProvider
{
/**
@joshbuchea
joshbuchea / semantic-commit-messages.md
Last active May 14, 2024 08:22
Semantic Commit Messages

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example

@JaseHadd
JaseHadd / ioslocaleidentifiers.csv
Last active March 31, 2022 08:23 — forked from jacobbubu/ioslocaleidentifiers.csv
iOS Locale Identifiers
localeIdentifier Description
eu Basque
hr_BA Croatian (Bosnia & Herzegovina)
en_CM English (Cameroon)
rw_RW Kinyarwanda (Rwanda)
en_SZ English (Swaziland)
tk_Latn Turkmen (Latin)
he_IL Hebrew (Israel)
ar Arabic
uz_Arab Uzbek (Arabic)
@anjan011
anjan011 / php-get-vimeo-video-id-from-url.php
Created November 11, 2015 14:39
php - get vimeo video id from url
<?php
/**
* Get Vimeo video id from url
*
* Supported url formats -
*
* https://vimeo.com/11111111
* http://vimeo.com/11111111