klik

Experience

230

0 Best Reply Awards

  • Member Since 6 Months Ago
  • 0 Lessons Completed
  • 0 Favorites

5th October, 2018

klik left a reply on Lumen Connection With Postgresql On Heroku • 1 week ago

Since I wrote that subject, I installed Lumen 3 times on heroku using always fresh installation. Finally I connected to DB. I can migrate and retrieve data from DB.

Thank you for help.

But one problem left. When I add this logging instructions -

    $monolog->pushHandler(new \Monolog\Handler\StreamHandler('php://stderr', \Monolog\Logger::WARNING));
    return $monolog;
});

to app.php then I have error:

In app.php line 29:

Call to undefined method Laravel\Lumen\Application::configureMonologUsing()

Any advice please?

klik left a reply on Lumen Connection With Postgresql On Heroku • 1 week ago

Correct, 1 table.

klik left a reply on Lumen Connection With Postgresql On Heroku • 1 week ago

I did it and I had correct informations.

klik started a new conversation Lumen Connection With Postgresql On Heroku • 1 week ago

Hi. I have a problem with connection to DB on heroku.

So far I have done the following steps:

  1. Created fresh Lumen project.
  2. Deployed project on heroku using this guide - https://devcenter.heroku.com/articles/getting-started-with-laravel
  3. Created fresh DB instance using this guide - https://mattstauffer.com/blog/laravel-on-heroku-using-a-postgresql-database/
  4. Installed plugin to have access to artisan commands - https://github.com/flipboxstudio/lumen-generator
  5. Created database configuration file to get access to postgresql db in heroku.
  6. Configured logging sysystem.

Finally on my localhost xampp everything works prefect. But the problem is on heroku.

When I try to do "php artisan migrate" then I have following error: " In Connection.php line 664:

SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from inform ation_schema.tables where table_schema = forge and table_name = migrations)

In Connector.php line 70:

SQLSTATE[HY000] [2002] No such file or directory"

But this above error appears only when I remove logging instruction from "bootstrap.php/app.php" file. When I add instructions then I have this error: "In app.php line 33:

Call to undefined method Laravel\Lumen\Application::configureMonologUsing()"

So I added some tables to DB manually but when I try retrieve data from DB then in my browser see error code 500 and this information. "Whoops, looks like something went wrong." And my log in heroku shows me only this information:

2018-10-05T14:57:26.092216+00:00 heroku[router]: at=info method=GET path="/" host=still-harbor-30058.herokuapp.com request_id=68d0c450-70b8-4259-aa01-9b6ea3ac672f fwd="2.121.94.235" dyno=web.1 connect=0ms service=116ms status=500 bytes=1845 protocol=https

2018-10-05T14:57:26.089888+00:00 app[web.1]: 10.95.199.248 - - [05/Oct/2018:14:57:25 +0000] "GET / HTTP/1.1" 500 1621 "-" "Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0

And again on my localhost everything works perfect.

Please advice me how should write correct lumen configuration to work on heroku.

Before I try to deploy Lumen, I installed Laravel on heroku and then everything was fine.

Code bellow:

.env

APP_ENV=local
APP_DEBUG=true
APP_KEY=base64:hixVqQUz1Fw2MgQZK0pDJDmEhn9nvP52JWvYQlR2sEE=
APP_TIMEZONE=UTC

LOG_CHANNEL=stack
LOG_SLACK_WEBHOOK_URL=

CACHE_DRIVER=file
QUEUE_CONNECTION=sync

"bootstrap/app.php"

<?php

require_once __DIR__.'/../vendor/autoload.php';

try {
    (new Dotenv\Dotenv(dirname(__DIR__)))->load();
} catch (Dotenv\Exception\InvalidPathException $e) {
    //
}


$app = new Laravel\Lumen\Application(
    dirname(__DIR__)
);
$app->register(Flipbox\LumenGenerator\LumenGeneratorServiceProvider::class);
$app->register(Appzcoder\LumenRoutesList\RoutesCommandServiceProvider::class);
$app->withFacades();
$app->configure('database');
$app->withEloquent();
$app->configureMonologUsing(function($monolog) {
    $monolog->pushHandler(new \Monolog\Handler\StreamHandler('php://stderr', \Monolog\Logger::WARNING));
    return $monolog;
});

$app->singleton(
    Illuminate\Contracts\Debug\ExceptionHandler::class,
    App\Exceptions\Handler::class
);

$app->singleton(
    Illuminate\Contracts\Console\Kernel::class,
    App\Console\Kernel::class
);

// $app->middleware([
//     App\Http\Middleware\ExampleMiddleware::class
// ]);

// $app->routeMiddleware([
//     'auth' => App\Http\Middleware\Authenticate::class,
// ]);

// $app->register(App\Providers\AppServiceProvider::class);
// $app->register(App\Providers\AuthServiceProvider::class);
// $app->register(App\Providers\EventServiceProvider::class);

$app->router->group([
    'namespace' => 'App\Http\Controllers',
], function ($router) {
    require __DIR__.'/../routes/web.php';
});

return $app;

"config/database.php"

<?php
$url = parse_url(getenv("DATABASE_URL"));

$host = $url["host"];
$username = $url["user"];
$password = $url["pass"];
$database = substr($url["path"], 1);
return [

   

    'fetch' => PDO::FETCH_CLASS,

    'default' => env('DB_CONNECTION', 'pgsql'),

 
    'connections' => [

        'testing' => [
            'driver' => 'sqlite',
            'database' => ':memory:',
        ],

        'sqlite' => [
            'driver'   => 'sqlite',
            'database' => env('DB_DATABASE', base_path('database/database.sqlite')),
            'prefix'   => env('DB_PREFIX', ''),
        ],

        'mysql' => [
            'driver'    => 'mysql',
            'host'      => env('DB_HOST', '127.0.0.1'),
            'port'      => env('DB_PORT', 3306),
            'database'  => env('DB_DATABASE', 'forge'),
            'username'  => env('DB_USERNAME', 'forge'),
            'password'  => env('DB_PASSWORD', ''),
            'charset'   => env('DB_CHARSET', 'utf8mb4'),
            'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'),
            'prefix'    => env('DB_PREFIX', ''),
            'timezone'  => env('DB_TIMEZONE', '+00:00'),
            'strict'    => env('DB_STRICT_MODE', false),
        ],

        'pgsql' => [
            'driver'   => 'pgsql',
            'host'     => $host,
            'database' => $database,
            'username' => $username,
            'password' => $password,
            'charset'  => 'utf8',
            'prefix'   => '',
            'schema'   => 'public',
        ],

        'sqlsrv' => [
            'driver'   => 'sqlsrv',
            'host'     => env('DB_HOST', 'localhost'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset'  => env('DB_CHARSET', 'utf8'),
            'prefix'   => env('DB_PREFIX', ''),
        ],

    ],


    'migrations' => 'migrations',
 
    'redis' => [

        'client' => 'predis',

        'cluster' => env('REDIS_CLUSTER', false),

        'default' => [
            'host'     => env('REDIS_HOST', '127.0.0.1'),
            'port'     => env('REDIS_PORT', 6379),
            'database' => env('REDIS_DATABASE', 0),
            'password' => env('REDIS_PASSWORD', null),
        ],

    ],

];

23rd May, 2018

klik left a reply on Can't Display Preg_match Return Array. • 4 months ago

I know, it's only test code. Thx.

klik left a reply on Can't Display Preg_match Return Array. • 4 months ago

That match[0] exists in every case. Now I did a test using explode method and I have the same situation. Index dosn't exist but var_dump() shows it exists. Is it a bug?

klik left a reply on Can't Display Preg_match Return Array. • 4 months ago

Hi. WTF?

This one works.

return $match[0] ?? '';

But this one doesn't.

return $match[0];

But what is a difference? In both cases match[0] exist, so why in your example I can return value but no when do return $match[0]?

Thank you.

22nd May, 2018

klik started a new conversation Can't Display Preg_match Return Array. • 4 months ago

Hi. I created new helper file and added function that using preg_match to check string.

In HTML: {{commentAnswerTo($comment->content)}}

In helper: function commentAnswerTo(string $text) { preg_match("/[|][a-z0-9_ąśżźćńłóę]+[|]/i",$text,$match); var_dump($match); }

As a result I have: array(1) { [0]=> string(7) "|Usuri|" } And result is absolutely correct.

But when I try get value from array:

echo $match[0];

then I have error: Undefined offset: 0 (View: \resources\views\post\view.blade.php).

Why I can't get this value?

I did a test adding string in function:

function commentAnswerTo(string $text) { $test = '|Usuri| This is a random text in comment'

preg_match("/[|][a-z0-9_ąśżźćńłóę]+[|]/i",$test,$match);
echo $match[0];   

}

And then I can get a value from array. So why I can't when I pass string as a function parameter?

Thank you.

14th May, 2018

klik left a reply on Display Formated Text From TinyMCE And Prevent XSS • 5 months ago

Thank you.

12th May, 2018

klik started a new conversation Display Formated Text From TinyMCE And Prevent XSS • 5 months ago

Hi. In my website I would like to let users add text using TinyMCE editor with some basic html tags (p, br, span, strong etc.). Later of course I would like to display added post with that formatted text.

And now I have a problem. If I use {{ $post->content_text }} then laravel remove all html tags. I can use {!! $post->content_text !!} and display proper formatted text but then I leave the door wide open for XSS attack.

So what is a solution to display formatted text and prevent XSS?

Thank you.

4th May, 2018

klik left a reply on Show Popular [tag] By How Much The Tag Count Per Post • 5 months ago

Hi. Your solution "jovanita" works fine for me. Thank you. I have only one question, how to get name of tags next to tags id.

Regards

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.