Skip to content

Instantly share code, notes, and snippets.

View nkeena's full-sized avatar
🏠
Working from home

Neil Keena nkeena

🏠
Working from home
View GitHub Profile
@nkeena
nkeena / RedirectToLowercase.php
Created July 7, 2017 15:04
Middleware to redirect uppercase URLs to lowercase ones
<?php
namespace App\Http\Middleware;
use Closure;
class RedirectToLowercase
{
/**
* Handle an incoming request.
@nkeena
nkeena / HasFilters.php
Created February 5, 2020 04:52
A simple trait that provides robust filtering by a model's attributes
<?php
namespace App\Traits;
use Illuminate\Support\Str;
trait HasFilters
{
public function scopeFilter($query, $filters = [])
{
@nkeena
nkeena / Download.php
Last active January 19, 2023 19:23
Download a file using Laravel Livewire
<?php
use Livewire\Component;
class Download extends Component
{
public function download()
{
// get the path to the file
$path = "";
@nkeena
nkeena / search_concatenated_nullable_columns.php
Last active June 11, 2021 16:45
Search concatenated columns in MySQL while Ignoring NULL values
<?php
public function scopeSearch($query, $search)
{
$search = addslashes($search); // in case the search has quotes
$query->when(
$search,
fn ($q) => $q->whereRaw(
"CONCAT_WS(' ', title, first_name, last_name, suffix) LIKE '{$search}%'"
@nkeena
nkeena / StaticModel.php
Created July 28, 2021 20:10
Static model using sushi that can be extended by other models
<?php
namespace App;
use Illuminate\Database\Eloquent\Model as EloquentModel;
use Sushi\Sushi;
class StaticModel extends EloquentModel
{
use Sushi;
@nkeena
nkeena / Country.php
Created July 28, 2021 20:12
Country model that uses CSV data
<?php
namespace App\Models;
use App\StaticModel;
class Country extends StaticModel
{
protected $schema = [
'calling_code' => 'string',
@nkeena
nkeena / Region.php
Created July 28, 2021 20:13
Region model that uses CSV data
<?php
namespace App\Models;
use App\StaticModel;
class Region extends StaticModel
{
protected $schema = [
'id' => 'string',
@nkeena
nkeena / countries.csv
Created July 28, 2021 20:15
country data
id calling_code capital_city code_2 code_3 continent_id currency_id flag name
ad 376 Andorra la Vella ad and eu eur 🇦🇩 Andorra
ae 971 Abu Dhabi ae are as aed 🇦🇪 United Arab Emirates
af 93 Kabul af afg as afn 🇦🇫 Afghanistan
ag 1268 St. John's ag atg na xcd 🇦🇬 Antigua and Barbuda
ai 1264 The Valley ai aia na xcd 🇦🇮 Anguilla
al 355 Tirana al alb eu all 🇦🇱 Albania
am 374 Yerevan am arm as amd 🇦🇲 Armenia
ao 244 Luanda ao ago af aoa 🇦🇴 Angola
aq 672 aq ata an 🇦🇶 Antarctica
@nkeena
nkeena / regions.csv
Created July 28, 2021 20:15
regions data
id code country_id name
ad-02 ad-02 ad Canillo
ad-03 ad-03 ad Encamp
ad-04 ad-04 ad La Massana
ad-05 ad-05 ad Ordino
ad-06 ad-06 ad Sant Julia de Loria
ad-07 ad-07 ad Andorra la Vella
ad-08 ad-08 ad Escaldes-Engordany
ae-aj ae-aj ae Ajman
ae-az ae-az ae Abu Zaby