It’s been a long while since I last posted anything related to coding. I haven’t really stopped, but from Android app development, I switched back to PHP. Life has become occupied with other things, but when I do code, it’s in WordPress with WooCommerce. It’s for my online shop. In my opinion, WordPress is not […]
PHP
Laravel 5.X directory permissions / ownership setup
According to the Laravel docs, “After installing Laravel, you may need to configure some permissions. Directories within the storage and the bootstrap/cache directories should be writable by your web server or Laravel will not run”. After running this command to install Laravel via Composer:
1 |
composer create-project --prefer-dist laravel/laravel blog |
Change directory ownership by running these commands:
1 2 |
sudo chown -R www-data:www-data /path/to/your/project/storage sudo chown -R www-data:www-data /path/to/your/project/bootstrap/cache |
Then you […]
Installing Laravel 5 on Apache in Mac OS X El Capitan
Last time, I wrote a guide on How to install Laravel 5 in Windows with XAMPP. I’ve been coding more often on Mac computers recently, and now I need to setup Laravel on a MacBook Pro, so I decided I’ll write a guide on how to install Laravel 5 on Mac OS X El Capitan […]
PHP: Parse Dates in CSV with inconsistent date formats
A friend was having trouble with a CSV file that she needs to process via PHP before saving to database. The CSV files uploaded to the server have inconsistent date formats such as:
1 2 3 4 5 |
November 1, 2016 Dec.6,2016 nov-10-2016 12122016 12/10/2016 |
So I prepared a PHP script that lists possible date formats in an array $possible_date_formats and then iterates through the dates […]
Laravel 5: create route group that is only available during testing (Middleware)
Today I needed to protect a group of routes from everything except my testing environment. I need to run PHPUnit tests that depend on certain routes, but I don’t want those routes to be available anywhere else. I’ll share in this blog post what I did to get what I need. Assumptions in this tutorial: […]
Laravel 5: activate API token guard and print “Unauthorized” instead of login redirect
In Laravel 5, I wrap my API routes in a route group like this:
1 2 3 |
Route::group(['middleware' => ['auth:api','throttle']], function() { // API routes here }); |
Notice that I use auth:api and throttle on my middleware array. auth:api turns on the auth middleware with API token as guard, while throttle activates rate limiter for APIs. To get started with API token authentication, you may read https://gistlog.co/JacobBennett/090369fbab0b31130b51. […]
Laravel 5 RESTful API with Basic Auth: PHPUnit Testing
I’ve been using PHPUnit to test my RESTful API. PHPUnit is ready to use in Laravel. In my Laravel-based RESTful API, I have an endpoint /api/users which returns JSON data when you send a GET request. The API will only return such data if the client sends the corrent username and password (Basic Authentication). The […]
Laravel update from v.5.0.35 to v.5.2.32 hiccups and solutions
I tried to update Laravel 5 today and here were the steps I had to take. First checked my Laravel version before the update:
1 2 |
$ php artisan --version Laravel Framework version 5.0.35 |
Edited composer.json in my laravel’s root folder like such:
1 2 3 |
"require": { "laravel/framework": "5.2.*" } |
Run this on command line:
1 |
composer update |
You might need to delete root folder’s composer.lock file before the update can actually […]
Laravel 5: Create controller under new folder and routing
So here I am on a Sunday, trying to make progress with a personal Laravel 5 site I need to work on. As I bear with the noise outside in the street (some crazy neighbors set up a swimming pool IN THE STREET! :oops:), I’m trying to figure out how too create a new Laravel […]
PHP dynamic variable names tutorial
I think it’s very convenient for us developers, being able to name our variables dynamically. I’ll show you how to do it in PHP. 🙂 For example, we have variable $foo with “bar” as value like this:
1 2 |
<?php $foo = "bar"; |
If we want to create a variable named based on the “value” of variable $foo, this is […]