Skip to content

Instantly share code, notes, and snippets.

@anaxamaxan
anaxamaxan / ide_helper.php
Created March 30, 2012 20:28
Laravel3 IDE Helper
<?php
class Auth extends Laravel\Auth {}
/**
* @method static add(string $name, string $source, array $dependencies = array(), array $attributes = array())
* @method static string styles()
* @method static string scripts()
*/
class Asset extends Laravel\Asset {}
class Autoloader extends Laravel\Autoloader {}
class Bundle extends Laravel\Bundle {}
@anaxamaxan
anaxamaxan / gist:9907466
Created April 1, 2014 04:00
args in a Laravel 4 auth filter
<?php
// in my controller constructor, I apply a filter with arguments:
$this->beforeFilter('auth.hasRole:admin,staff,developer', ['except' => 'getLogoutas',]);
// in my global filters.php
/**
* Verify that the logged-in user has a specified role
*/
Route::filter('auth.hasRole', function($route, $request, $value)
@anaxamaxan
anaxamaxan / LogServiceProvider.php
Created April 18, 2014 04:16
app/services/Log/LogServiceProvider.php
<?php namespace Sa\Services\Log;
use Illuminate\Log\LogServiceProvider as LaravelLogServiceProvider;
use Illuminate\Log\Writer;
class LogServiceProvider extends LaravelLogServiceProvider
{
/**
* Register the service provider.
*
@anaxamaxan
anaxamaxan / Logger.php
Created April 18, 2014 04:18
app/services/Log/Logger.php
<?php namespace Sa\Services\Log;
class Logger extends \Monolog\Logger
{
/**
* @param string $name The logging channel
* @param \Monolog\Handler\HandlerInterface[] $handlers Optional stack of handlers, the first one in the array is called first, etc.
* @param callable[] $processors Optional array of processors
*/
@anaxamaxan
anaxamaxan / global.php
Created April 25, 2014 05:41
Catching ModelNotFoundException
App::error(function(\Illuminate\Database\Eloquent\ModelNotFoundException $e){
Log::error($e);
if (Request::ajax() or Request::is('api/*')) {
return Response::json(['flash'=>trans('application.resource_not_found')],404);
}
});
@anaxamaxan
anaxamaxan / Process description
Last active August 29, 2015 14:03
Proessing Blade Templates for Consumption by Angular (or other JS framework)
Basically, we compile all view templates into a single ng.html template that our frontend app consumes. This app is currently in private development, so I can't give a link to demo it, but the process is simple:
1. Create a Command to process the relevant Blade templates and concatenate into a single static HTML file, with each view encapsulated in a <script type="text/html"> element. That static file gets served by webserver from the public directory, gzipped by server and cached by browser. Could be served via CDN.
2a. On dev machines, add a gulp watcher to call this command whenever a file within the view directory changes.
2b. On production, call the process command in deploy script.
In our case, we put all blade templates intended for the front end in app/views/angular -- this keeps other blade templates separate, such as email messages.
I've included 5 files here:
1. The actual Command script that processes the Angular view files.
@anaxamaxan
anaxamaxan / URL.php
Created August 22, 2014 01:11
Allow curly braces in Laravel URL::route() parameters array
<?php namespace Cego\Facades;
class URL extends \Illuminate\Support\Facades\URL
{
public static function route($name, $parameters = array(), $absolute = true, $route = null)
{
$urlGenerator = static::$app['url'];
/* @var \Illuminate\Routing\UrlGenerator $urlGenerator */
$route = $urlGenerator->route($name, $parameters, $absolute, $route);
@anaxamaxan
anaxamaxan / gist:b5298a8455339f879b3c
Created February 26, 2015 17:09
small tweak for tessa
UPDATE `tbl_name` SET
`first_name` = IF(
LOCATE(' ', `name`) > 0,
SUBSTRING(`name`, 1, LOCATE(' ', `name`) - 1),
`name`
),
`last_name` = IF(
LOCATE(' ', `name`) > 0,
SUBSTRING_INDEX(`name`, ' ' - 1), /* Changed line */
NULL
@anaxamaxan
anaxamaxan / testResponseTrait.php
Last active December 8, 2015 09:44
Quick test of a trait method
public function testIsForbiddenResponse()
{
$obj = new class(){
use \App\Http\Controllers\Traits\JsonMessagesTrait;
};
$this->assertEquals(403, $obj->isForbiddenResponse()->getStatusCode());
}
# in Homestead and typical Ubuntu, put this in /etc/mysql/my.cnf
# right after explicit_defaults_for_timestamp
sql-mode = "ALLOW_INVALID_DATES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
# Also, if you execute .sql file from an older MySQL version, you might get errors befause the ROW_FORMAT=FIXED is no
# longer a valid option. Search all ROW_FORMAT=FIXED replace with ROW_FORMAT=DYNAMIC