Skip to content

Instantly share code, notes, and snippets.

@antonioribeiro
antonioribeiro / gist:96ce9675e5660c317bcc
Created July 23, 2014 21:49
Codeception, Javascript and Laravel Homestead

You can use Codeception to test Javascript, like DOM manipulations and Ajax requests. Out of the box it can manipulate DOM elements but can't execute Javascript code, like most testing frameworks. But it gives you the option to use a WebDriver, to connect to a headless browser, and mimic a user browsing your website. It gives you some options: Selenium2, ZombieJS and, the easiest to configure, PhantomJS.

This article covers the installation and usage of PhantomJS, and assumes you are using Laravel Homestead, but it will work on any relatively new Debian based distro, like Ubuntu 14.04.

###Install PhantomJS

Just run those commands to install it:

sudo apt-get update
@antonioribeiro
antonioribeiro / gist:6f7a4c9a1336f798fa65
Last active March 9, 2022 05:20
Add more conditions to your Laravel Relations
public function connections()
{
	$relation = $this
		->belongsToMany(static::class, 'connections', 'requestor_id', 'requested_id')
		->withTimestamps();

	/// delete the already built inner join
	$relation
		->getQuery() // Eloquent\Builder
@antonioribeiro
antonioribeiro / gist:24a19f22cffd0beaa7e3
Last active September 13, 2021 19:17
The Laravel Forge, NGINX, PHP-FPM & A Blank Page Debugging Tale

After an apt-get upgrade on my Forge box, both php and nginx got upgraded, and while browsing my sites, PHP FPM was being hit by nginx, but it returned nothing, zilch, nada.

Nothing on laravel.log.

Something in the nginx log:

10.10.10.10 - - [23/Sep/2014:11:52:09 -0300] "GET / HTTP/1.1" 200 31 "-" "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36"

Class and helpers below are in a package, so I just have to pull it, set the detectenvironment call:

$env = $app->detectEnvironment(
	\PragmaRX\Support\Environment::getDetectionClosure(__DIR__.'/../.environment')
);

And create a .environment file:

###Edit this file

/etc/nginx/nginx.conf

###Add this line anywhere inside the http { } block:

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

###Go to your Forge panel and restart Nginx

##What’s wrong with Annotations in PHP

####App logic and structure expressed in COMMENTS, which is enchanting for beginners (Look’ma no PHP, magic!), but terrible for real development. We are developers, we write and debug code. But Annotations is a COMMENTS parser. I really don’t want to debug any string based parser instead of my code. COMMENTS should be just, well..., comments!, not a source of truth!


People may see a really big difference between DocBlocks and comments, but as a matter of fact they are comments, block comments. If they were not supposed to be comments, then they should have completely changed the delimiters, which, I know could be a problem to the compiler...

Block comments in PHP are C & C++ block comments:

#####Let's say someone has this class

<?php 

// 

class Load {

 public static function load($file)
# Tail Laravel and Webserver (NGINX & Apache 2) log files
# Compatible with Laravel 4 & 5
#
alias tl="ls -d /var/log/nginx/* /var/log/apache2/* storage/logs/* app/storage/logs/* storage/laravel.log | grep -v 'gz$' | grep -v '1$' | xargs tail -f"

Copy the whole folder to to a subfolder on your project and add a reference to in in your package composer.json. I had to do this with jasonlewis/resource-watcher, so this is now my package autoload section:

"autoload": {
    "psr-4": {
        "PragmaRX\\Ci\\": "src/"
    },
    "psr-0": {
        "JasonLewis\\ResourceWatcher": "src/Support/jasonlewis/resource-watcher/src"
    }

},

###Form Request (Validation)

class Update extends FormRequest {

	public function rules()
	{
		return [
			... whatever
 ];