jymden.com


  • (PHP) Get a list of run database queries in Laravel

    This is great if you want to see what queries are actually run when using Eloquent. [php] // Get all querys run $queries = DB::getQueryLog(); // If you want to sort them by time this works usort($queries, function ($a, $b) { return $a[‘time’] < $b[‘time’]; }); // Print them on screen in a readable way…

  • (PHP) Log Laravel execution time to console

    Put this in app/start/global.php to get Laravels execution time to the browser console log. L4 [php] $start = microtime(true); App::finish(function() use ($start) { echo "<script>console.log(‘App finish: ".round((microtime(true) – $start) * 1000, 3)." ms’)</script>"; }); [/php] This works with L5: [html] This page took {{ (microtime(true) – LARAVEL_START) }} seconds to render [/html]

  • Convert CSV to SQL

    This tool is fantastic! It saved me many hours of work, when I had complex CSV files I needed to turn into SQL tables http://www.convertcsv.com/csv-to-sql.htm

  • (HTML) Form element arrays

    Sometimes you might want to group form elements in arrays. Here’s a way to do that: [html] <form> <input type="text" name="textboxes[]"> <input type="text" name="textboxes[]"> <input type="text" name="textboxes[]"> </form> [/html] The structure of the $_POST array will then be: [php] Array ( [textboxes] => Array ( [0] => value 1 [1] => value 2 [2] =>…

  • (PHP) sorting an array on a specific value

    Simple way to sort an array with usort on a specific value using a comparator. [php] usort($myArray, function ($a, $b) { return $a[‘foo’] > $b[‘foo’]; }); [/php]

  • (CSS) How to center a div without width

    I needed to center a div with dynamic content, so I couldn’t set a fixed width. Since margin: 0 auto; really won’t do anything if the element doesn’t have a fixed width you can solve it like this: HTML [html] <div id="container"> <div class="centered">My dynamic content, that will be centerd</div> </div> [/html] CSS [css] .centered…

  • (PHP) Allow any delimiter in CSV file

    In a Laravel app I made the users would upload CSV files. The problem was that fgetcsv only allows a single delimiter character, and it needs to be defined. The problem with that is that when a user exports a CSV from MS Excel – it could end up using a wide array of delimiters depending on the locality…

  • Test localhost email with a simplified SMTP server

    For checking the emails going out from your local server (without actually sending them). Use papercut. https://papercut.codeplex.com/   If you’re using Laravel, then make sure to setup your app/config/mail.php correctly: ‘driver’ => ‘smtp’, ‘host’ => ‘localhost’, ‘port’ => <your papercut port>, ‘encryption’ => ”,

  • (PHP) Eloquent doodles for Laravel

    [php] // Get model by primary key $myModel = MyModel::find($id); //Where can use short syntax for equal comparison. $myModels = MyModel::where(‘someAttribute’, ‘=’, ‘someValue’)->get(); $myModels = MyModel::where(‘someAttribute’, ‘someValue’)->get(); // Delete models $affectedRows = MyModel::where(‘someAttribute’, ‘someValue’)->delete(); // Select distinct $distincts = MyModel::distinct()->select(‘someAttribute’)->where(‘someAttribute’, ‘someValue’)->get(); // Select with Limit and offset $myModels = MyModel::limit(30)->get(); $myModels = MyModel::limit(30)->offset(30)->get(); [/php] Different…

  • (PHP) Using route groups in Laravel to protect routes

    To protect routes, in Laravel, from unauthorized visits you can use route groups. All routes in group will be affected by the auth before filter. [php] Route::group(array(‘before’ => ‘auth’), function() { Route::get(‘controlpanel’, ‘CustomerPanel@showPanel’); Route::get(‘secret’, ‘Secret@showSecret’); Route::post(‘setup’, ‘SetupController@doSetup’); }); [/php]