Skip to content

Instantly share code, notes, and snippets.

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:

@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"
@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: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:e12fdf54bab87243128a
Created July 23, 2014 19:12
boot laravel on codeception _bootstrap
<?php
include __DIR__ . '/../vendor/autoload.php';
$app = require_once __DIR__ . '/../bootstrap/start.php';
$app->boot();
\Codeception\Util\Autoload::registerSuffix('Page', __DIR__.DIRECTORY_SEPARATOR.'_pages');
\Codeception\Util\Autoload::registerSuffix('Steps', __DIR__.DIRECTORY_SEPARATOR.'_steps');

###Laravel Forge & StarCom Free SSL certificates

Firefox, and probably other browsers, complaint about StartSSL certificates if you don't provide your site's SSL certificate togheter with the StarCom's ones. To fix this, you just have to download those certificates:

http://www.startssl.com/certs/ca.pem
http://www.startssl.com/certs/sub.class1.server.ca.pem

And paste them in the "Certificate" textarea, alongside with your current site certificate. Having all three certificates in the same textarea, save, activate it and you should be good to go.

Routes By Name

Having a route of

Route::get('user/{id}', ['as' => 'user.profile', 'use' => 'UsersController@profile']);
<?php
namespace A {
class ClassA {
public function doA()
{
try
{
<?php
$user = User::find(15); /// will find the user in Domino or Locally
class User Extends Eloquent {
protected $table = 'users';
public static function find($id)
{