laravel-realworld-example-app
laravel-realworld-example-app copied to clipboard
CORS documentation doesn't cover CORS_ALLOWED_ORIGINS
If I look in config\cors.php
it has a line:
'allowedOrigins' => env('CORS_ALLOWED_ORIGINS') ? explode(',', env('CORS_ALLOWED_ORIGINS')) : ['*'],
I was unable to get anything working until I had set an environment variable CORS_ALLOWED_ORIGINS
to match the domain name where the frontend is. When I set that env var to be a string that matched the ORIGIN domain name then things worked (e.g. "frontend-sjm-staging.a3c1.starter-us-west-1.openshiftapps.com" with no protocol).
To shake this off I also bumped to laravel/framework to 5.5.* and barryvdh/laravel-cors to "^0.11.0" I haven't checked whether things works using the early versions on master in this repo.
# set config/cors.php to this help me. thanks simbo1905
'allowedOrigins' => ['*'],
\Illuminate\Database\Eloquent\Builder::callScope
# fix php 7.2 count problem
protected function callScope(callable $scope, $parameters = [])
{
array_unshift($parameters, $this);
$query = $this->getQuery();
// We will keep track of how many wheres are on the query before running the
// scope so that we can properly group the added scope constraints in the
// query as their own isolated nested where statement and avoid issues.
$originalWhereCount = is_array($query->wheres) ? count($query->wheres) : 0;
$result = $scope(...array_values($parameters)) ?: $this;
if (is_array($query->wheres) ? count($query->wheres) : 0 > $originalWhereCount) {
$this->addNewWheresWithinGroup($query, $originalWhereCount);
}
return $result;
}
or use this
if (version_compare(PHP_VERSION, '7.2.0', '>=')) {
// Ignores notices and reports all other kinds... and warnings
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);
// error_reporting(E_ALL ^ E_WARNING); // Maybe this is enough
}
see https://github.com/yiisoft/yii/issues/4167 since 7.2 count(): Parameter must be an array or an object that implements Countable first solution is crutch .
second is turn off notice messages . use in pulic/index.php or set up it in php.ini
Суббота, 22 июня 2019, 22:01 +03:00 от Mihaila Botez Andrei [email protected]:
if (is_array($query->wheres) ? count($query->wheres) : 0 > $originalWhereCount) { $this->addNewWheresWithinGroup($query, $originalWhereCount); }
Could you expand a little your answer? I ask because modifying \Illuminate\Database\Eloquent\Builder::callScope is not working for me(PHP 7.3.2), and I am not sure where to use your second code snippet — You are receiving this because you commented. Reply to this email directly, view it on GitHub , or mute the thread .
Серега Галаев [email protected]