PHP preg_replace let phone=”+17778889999″; let p=phone.replace(/^\+1/,”); PHP isset if (typeof variable !== ‘undefined’) PHP array_pop path_arr.splice(-1,1); //note does not work
Category: PHP
Laravel Query Builder WhereRaw Example
A query builder whereraw tutorial whereRaw($sql, array $bindings = [], $boolean = ‘and’) A couple of examples: $g = TableName::whereRaw(‘LOWER(worker_location)
Laravel Query Performance
Here’s a way to assess the performance of a query: Start tinker in the Laravel project directory php artisan tinker
Laravel Eloquent Collection Tips
Adding a column with constant value to existing collection: $existing_col->map(function ($col) { $col[‘url’] = ‘http://your.url/here’; return $col; }); To add
Laravel Migration
Note: when creating a table with automatically increasing id, for example: $table->increments(‘id’); The type created in a Mysql table is
PHPStorm Quick Keys
Note: I don’t think letters are case sensitive Show class methods- CNTRL+F12 Code settings CNTRL+ALT+S (can set to psr-12 style)
MYSQLI on PHPStorm Build In Web Server
PHPStorm has a build-in web server running at default port 63342. It works fine in general browser files such as
PHP Anonymous Function
$functions = [ ‘function1’ => function ($echo) { echo $echo; } ]; or function do_echo($echo) { echo $echo; } $functions
Laravel Test HTTP Client Calls
Get a test url from https://webhook.site/ Make sure Laravel and Guzzle are installed Go to a directory where Laravel is
Laravel Add a Column to a Table
php artisan make:migration add_colName_to_tableName –table=tableName This will create migration file under the database/migration directory Update in the generated file the