Call all classes that implement an interface in Symfony

The best way is to implement CompilerPass. Here is an example . So, create a registry class (TransportChain class in that example), interface, and all classes that implements that interface, define them as services and give them tag name. After that, you can call that registry service in your action, […]

Disable csrf in laravel for specific route

Since version 5.1 Laravel‘s VerifyCsrfToken middleware allows to specify routes, that are excluded from CSRF validation. In order to achieve that, you need to add the routes to $except array in your App\Http\Middleware\VerifyCsrfToken.php class: <?php namespace App\Http\Middleware; use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier; class VerifyCsrfToken extends BaseVerifier { protected $except = [ […]

How to access GIT repo with my private key from Dockerfile

The error message Host key verification failed. is not complaining about your private key, but rather the host key for github.com. You can do this to add the github hostkey: ssh-keyscan -t rsa github.com > ~/.ssh/known_hosts Perhaps you have your reasons, but in general cloning the git repo in to […]

How to prevent Model events from firing using phpunit

ooking into Laravel Api Model::flushEventListeners() should «Remove all of the event listeners for the model.» You can write a custom method base on this one: public static function flushEventListeners() { if (! isset(static::$dispatcher)) { return; } $instance = new static; foreach ($instance->getObservableEvents() as $event) { static::$dispatcher->forget(«eloquent.{$event}: «.get_called_class()); } } Something […]

How to parse html table to array with symfony dom crawler

table = $crawler->filter(‘table’)->filter(‘tr’)->each(function ($tr, $i) { return $tr->filter(‘td’)->each(function ($td, $i) { return trim($td->text()); }); }); print_r($table); The above example will give you a multidimensional array where the first layer are the table lines «tr» and the second layer are the table columns «td». If you got nested tables, this code […]

Laravel API Enable Cors

Here is my CORS middleware: <?php namespace App\Http\Middleware; use Closure; class CORS { /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { header(«Access-Control-Allow-Origin: *»); // ALLOW OPTIONS METHOD $headers = [ ‘Access-Control-Allow-Methods’=> ‘POST, GET, […]

How to correctly require a specific commit in Composer so that it would be available for dependent packages

139 You’ll have to explicitly require the Gaufrette library at that hash, with a dev flag, in both your library and your application. Something like this should work in the application composer.json: { «name»: «bar/bar-app», «repositories»: [ { «type»: «vcs», «url»: «ssh://git.example.com/foo-lib» } ], «require-dev»: { «foo/foo-lib»: «dev-master», «knplabs/gaufrette»: «dev-master#2633721877cae79ad461f3ca06f3f77fb4fce02e» […]

How to define and use JSON data type in Eloquent?

In your migrations you can do something like: $table->json(‘field_name’); And in your model you add the field to the $casts property to instruct Eloquent to deserialize it from JSON into a PHP array: class SomeModel extends Model { protected $casts = [ ‘field_name’ => ‘array’ ];

CSS Div stretch 100% page height

Here is the solution I finally came up with when using a div as a container for a dynamic background. Remove the z-index for non-background uses. Remove left or right for a full height column. Remove top or bottom for a full width row. EDIT 1: CSS below has been […]