Laravel 8 using graylog - unicode problem - unicode

I need to integrate Graylog packet. I found this 'https://github.com/hedii/laravel-gelf-logger'
This is my config file
config/logging.php
'default' => 'stack',
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['single', 'gelf'],
],
'gelf' => [
'driver' => 'custom',
'via' => \Hedii\LaravelGelfLogger\GelfLoggerFactory::class,
'processors' => [
\Hedii\LaravelGelfLogger\Processors\NullStringProcessor::class,
// another processor...
],
'level' => 'debug',
'name' => 'bms-admin',
'system_name' => null,
'transport' => 'udp',
'host' => '192.168.41.112',
'port' => '5141',
'path' => null,
'max_length' => null,
'context_prefix' => null,
'extra_prefix' => null,
],
'single' => [
'driver' => 'single',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
],
]
When Laravel logged something, I received

Related

Disabling the past dates

I want to disable the past dates from the laravel-backpack component date-range-picker.
`$this->crud->addField([
'name' => ['event_start_date', 'event_end_date'],
'type' => 'date_range',
'label' => "Start Date",
'wrapperAttributes'=>['class'=>'form-group col-md-6'],
'default' => [date("Y-m-d"), date("Y-m-d")],
'date_range_options' => [
'todayBtn' => 'linked',
'timePicker' => true,
'format' => 'YYYY-MM-DD'
],
'allows_null' => true,
]);`
How can I do that?
$this->crud->addField([
'name' => ['event_start_date', 'event_end_date'],
'type' => 'date_range',
'label' => "Start Date",
'wrapperAttributes'=>['class'=>'form-group col-md-6'],
//'default' => [date("Y-m-d"), date("Y-m-d")],
'date_range_options' => [
'todayBtn' => 'linked',
// options sent to daterangepicker.js
//'timePicker' => true,
'startDate' => date("Y-m-d"),
'endDate' => date("Y-m-d"),
'minDate'=> date("Y-m-d"),
'locale' => ['format' => 'YYYY-MM-DD']
],
'allows_null' => true,
]);

Zend routing issue

I'm working on converting a (quite sloppily put together) zend expressive website to a zend framework 3 website for a local restaurant. When I set up the routing on the expressive website I would load a location based on a query parameter looking like this.
website.com/location?location=xxx
On my new website the routing looks like this
website.com/locations/view/xxx
I need to set up a route that redirects the old url to the new url. So far I have set up a route that looks for the
/location?location=[/:location]
hoping that it would recognize this 'Segment' route and load the appropriate LocationsController. Right now it is giving me a route not found error.
My code looks like below.
module.config.php
namespace Application;
use Zend\Router\Http\Literal;
use Zend\Router\Http\Segment;
use Zend\ServiceManager\Factory\InvokableFactory;
return [
'router' => [
'routes' => [
'home' => [
'type' => Literal::class,
'options' => [
'route' => '/',
'defaults' => [
'controller' => Controller\IndexController::class,
'action' => 'index',
],
],
],
'locations-old' => [
'type' => Segment::class,
'options' => [
'route' => '/location?location=[/:location]',
'defaults' => [
'controller' => Controller\LocationController::class,
'action' => 'index',
],
],
],
'locations' => [
'type' => Segment::class,
'options' => [
'route' => '/locations[/:action[/:location]]',
'constraints' => [
'action' => '[a-zA-Z]*',
'location' => '[a-zA-Z]*',
],
'defaults' => [
'controller' => Controller\LocationController::class,
'action' => 'index',
],
],
],
'locations.html' => [
'type' => Literal::class,
'options' => [
'route' => '/locations.html',
'constraints' => [
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'location' => '[a-zA-Z][a-zA-Z0-9_-]*',
],
'defaults' => [
'controller' => Controller\IndexController::class,
'action' => 'index',
],
],
],
'about' => [
'type' => Literal::class,
'options' => [
'route' => '/about',
'defaults' => [
'controller' => Controller\AboutController::class,
'action' => 'index',
],
],
],
'employ' => [
'type' => Literal::class,
'options' => [
'route' => '/employ',
'defaults' => [
'controller' => Controller\EmployController::class,
'action' => 'index',
],
],
],
'news' => [
'type' => Literal::class,
'options' => [
'route' => '/news',
'defaults' => [
'controller' => Controller\NewsController::class,
'action' => 'index',
],
],
],
],
],
'view_manager' => [
'display_not_found_reason' => true,
'display_exceptions' => true,
'doctype' => 'HTML5',
'not_found_template' => 'error/404',
'exception_template' => 'error/index',
'template_map' => [
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
],
'template_path_stack' => [
__DIR__ . '/../view',
],
],
];
LocationController.php
namespace Application\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Application\Model\StoreTable;
use Zend\View\Model\ViewModel;
class LocationController extends AbstractActionController
{
private $table;
public function __construct(StoreTable $table)
{
$this->table = $table;
}
public function indexAction()
{
if($_GET['location'] && $this->table->doesExist($_GET['location'])) {
$location = $_GET['location'];
$this->redirect()->toRoute('locations', ['action' => 'view', 'location' => $location])->setStatusCode(302);
} else {
$this->redirect()->toUrl('/#locations')->setStatusCode(301);
}
}
public function viewAction()
{
$location = (string) $this->params()->fromRoute('location');
$store = $this->table->getStore($location);
return new ViewModel([
'store' => $store,
]);
}
}
Any help would be greatly appreciated and I can provide more info if needed.
Thanks!
configure your route as following, this will be handle query based url as you given "website.com/location?location=xxx",
In below route ":key" variable implies ?location=xxx
'locations-old' => [
'type' => Segment::class,
'options' => [
'route' => '/location/:key',
'defaults' => [
'controller' => Controller\LocationController::class,
'action' => 'index',
],
'constraints' => [
'key' => '[a-z0-9]+',
],
],
'child_routes' => [
'query' => ['type' => 'query'],
],
]

Setting up mongodb config in Laravel with Compose.io

Its my first time use compose.io as my mongodb hosting.
I was trying to configure compose.io mongodb with Laravel but ended up this error:
ConnectionTimeoutException in Collection.php line 432:
No suitable servers found (`serverSelectionTryOnce` set)
I was using https://github.com/jenssegers/laravel-mongodb package to add mongodb support to Laravel.
My mongodb config:
'mongodb' => [
'driver' => 'mongodb',
'host' => ['aws-us-east-1-portal.25.dblayer.com:20020/admin', 'aws-us-east-1-portal.26.dblayer.com:20020/admin'],
'port' => env('MONGO_DB_PORT', 27017),
'database' => env('MONGO_DB_DATABASE'),
'username' => env('MONGO_DB_USERNAME'),
'password' => env('MONGO_DB_PASSWORD'),
'options' => [
'ssl' => true,
'database' => 'admin', // sets the authentication database required by mongo 3
'replicaSet' => 'set-5939226a8aab5300121d0ef2',
'readPreference' => 'primary',
],
'driver_options' => [
'context' => stream_context_create( [
'ssl' => [
'local_cert' => base_path('mongo.pem'),
'cafile' => base_path('mongo.pem'),
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
'verify_expiry' => false,
'allow_invalid_certificates' => true
]
])
]
]
I am not also sure what is the value for MONGO_REPLICA_SET
Anyone experienced something similar?
Thanks
It works by removing replicaSet option
Final configuration:
'mongodb' => [
'driver' => 'mongodb',
'host' => ['aws-us-east-1-portal.25.dblayer.com', 'aws-us-east-1-portal.26.dblayer.com'],
'port' => env('MONGO_DB_PORT', 27017),
'database' => env('MONGO_DB_DATABASE'),
'username' => env('MONGO_DB_USERNAME'),
'password' => env('MONGO_DB_PASSWORD'),
'options' => [
'ssl' => true,
'database' => env('MONGO_DB_DATABASE'), // sets the authentication database required by mongo 3
],
'driver_options' => [
'context' => stream_context_create( [
'ssl' => [
'cafile' => base_path('mongo.pem'),
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
'verify_expiry' => false,
]
])
]
]

ZF 2.4 File Validator Required False Doesn't Work

Today I updated to ZF 2.4 to use float validator but unfortunately i realized that my file upload form field gives unexpected error messages.
Here is my form object
$this->add([
'name' => 'profileimage',
'type' => '\Zend\Form\Element\File',
'attributes' => [
'id' => 'profileimage',
'class' => 'styled',
],
]
);
And Here is my validator
$inputFilter->add([
'name' => 'profileimage',
'required' => false,
'allow_empty' => true,
'priority' => 300,
'filters' => [
['name' => 'StripTags'],
['name' => 'StringTrim'],
],
'validators' => [
[
'name' => '\Zend\Validator\File\IsImage',
],
[
'name' => '\Zend\Validator\File\UploadFile',
],
[
'name' => '\Zend\Validator\File\ImageSize',
'options' => [
'minWidth' => 300,
'minHeight' => 300,
]
],
[
'name' => '\Zend\Validator\File\Size',
'options' => [
'max' => '20MB',
]
],
]
]);
As you see the image upload field is not required and may be empty. But in my form I get these errors:
array (size=1)
'profileimage' =>
array (size=4)
'fileIsImageNotReadable' => string 'File is not readable or does not exist' (length=38)
'fileUploadFileErrorNoFile' => string 'File was not uploaded' (length=21)
'fileImageSizeNotReadable' => string 'File is not readable or does not exist' (length=38)
'fileSizeNotFound' => string 'File is not readable or does not exist' (length=38)
How can I handle this issue? I need to this field to be optional.
change your filter
$inputFilter->add([
'name' => 'profileimage',
'type' => '\Zend\InputFilter\FileInput',
'required' => false,
'allow_empty' => true,
'priority' => 300,
'filters' => [
['name' => 'StripTags'],
['name' => 'StringTrim'],
],
'validators' => [
[
'name' => '\Zend\Validator\File\IsImage',
],
[
'name' => '\Zend\Validator\File\UploadFile',
],
[
'name' => '\Zend\Validator\File\ImageSize',
'options' => [
'minWidth' => 300,
'minHeight' => 300,
]
],
[
'name' => '\Zend\Validator\File\Size',
'options' => [
'max' => '20MB',
]
],
]
]);
read about it here: http://framework.zend.com/manual/current/en/modules/zend.input-filter.file-input.html

yii2 always redirect to frontend/web

When i want to access to backend yii2 always redirect me to frontend.
Example:
I have installed the yii2-user (dektrium) module in frontend and backend and yii2-admin (mdm) module only in backend . And when i want to acess to
http://localhost/american_eshop/yii-application/frontend/web/**user/admin/index**"
yii2 in the first place accessing to this route and after redirect me to "http://localhost/american_eshop/yii-application/frontend/web/".
I.E. i can get access to resourse but it always redirect me and i cannot undestand where i am in my site.
Sorry for my poor english...
backend cofigs:
main.php
<?php
$params = array_merge(
require(__DIR__ . '/../../common/config/params.php'),
require(__DIR__ . '/../../common/config/params-local.php'),
require(__DIR__ . '/params.php'),
require(__DIR__ . '/params-local.php')
);
return [
'id' => 'app-backend',
'basePath' => dirname(__DIR__),
'controllerNamespace' => 'backend\controllers',
'bootstrap' => ['log'],
'modules' => [],
'components' => [
'user' => [
'identityClass' => 'dektrium\user\models\User',
'enableAutoLogin' => true,
],
'authManager' => [
'class' => 'yii\rbac\DbManager'
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
],
'errorHandler' => [
'errorAction' => 'site/error',
],
],
'params' => $params,
];
main-local:
<?php
$config = [
'components' => [
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => 'QuXcvHHNSiT3mEGgBln9c85IYF7uVkoU',
],
],
'modules' => [
'user' => [
'class' => 'backend\modules\user\Module',
'viewPath' => '#dektrium/user/views',
'enableUnconfirmedLogin' => true,
'confirmWithin' => 21600,
'cost' => 14,
'admins' => ['Admin']
],
]
];
if (!YII_ENV_TEST) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = 'yii\debug\Module';
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = 'yii\gii\Module';
}
return $config;
frontend:
main:
<?php
$params = array_merge(
require(__DIR__ . '/../../common/config/params.php'),
require(__DIR__ . '/../../common/config/params-local.php'),
require(__DIR__ . '/params.php'),
require(__DIR__ . '/params-local.php')
);
return [
'id' => 'app-frontend',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'controllerNamespace' => 'frontend\controllers',
'components' => [
'user' => [
'identityClass' => 'dektrium\user\models\User',
'enableAutoLogin' => true,
],
'authManager' => [
'class' => 'yii\rbac\DbManager'
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
],
],
'params' => $params,
];
main-local:
<?php
$config = [
'components' => [
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => 'xlEFSbBB0pjvAJHtEOfY6r5BhDOTIAtB',
],
],
'modules' => [
'user' => [
'class' => 'frontend\modules\user\Module',
'viewPath' => '#dektrium/user/views',
'enableUnconfirmedLogin' => true,
'confirmWithin' => 21600,
'cost' => 14,
'admins' => ['Admin']
],
],
];
if (!YII_ENV_TEST) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = 'yii\debug\Module';
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = 'yii\gii\Module';
}
return $config;