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 […]

Eloquent — join clause with string value rather than column heading

Another best way to achieve same is : $result = DB::connection() ->table(‘destinations AS d1’) ->select(array(‘d1.title AS level1’, ‘d2.title AS level2’)) ->leftJoin(‘taxonomy AS t1’, function($join) { $join->on(‘t1.parent_id’, ‘=’, ‘d1.id’); $join->where(‘t1.parent_type’, ‘=’, ‘Destination’); }) ->leftJoin(‘destinations AS d2’, ‘d2.id’, ‘=’, ‘t1.child_id’) ->where(‘d1.slug’, ‘=’, $slug) ->get(); Replace your on with where

How do I pass command line arguments to a Node.js program?

Standard Method (no library) The arguments are stored in process.argv Here are the node docs on handling command line args: process.argv is an array containing the command line arguments. The first element will be ‘node’, the second element will be the name of the JavaScript file. The next elements will […]

Github create empty branch

What’s wrong with the —orphan option? If you want a branch that is empty and have no history, this is the way to go… git checkout —orphan empty-branch Then you can remove all the files you’ll have in the staging area (so that they don’t get committed): git rm -rf […]

Use Laravel without global scopes

6 If you want to explicitly avoid a global scope for a given query, you may use the withoutGlobalScope() method. The method accepts the class name of the global scope as its only argument. $ingredient->withoutGlobalScope(LocaleScope::class)->touch(); $ingredient->withoutGlobalScopes()->touch(); Since you’re not calling touch() directly, in your case it will require a bit […]