klik

klik

Member Since 9 Months Ago

Experience Points 230
Experience
Level
Lessons Completed 0
Lessons
Completed
Best Reply Awards 0
Best Answer
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • Chatty Cathy Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

05 Oct
3 months ago

klik left a reply on Lumen Connection With Postgresql On Heroku

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

I did it and I had correct informations.

klik started a new conversation Lumen Connection With Postgresql On Heroku

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),
        ],

    ],

];
23 May
7 months ago

klik left a reply on Can't Display Preg_match Return Array.

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

klik left a reply on Can't Display Preg_match Return Array.

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.

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.

22 May
7 months ago

klik started a new conversation Can't Display Preg_match Return Array.

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.

14 May
8 months ago
12 May
8 months ago

klik started a new conversation Display Formated Text From TinyMCE And Prevent XSS

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.

04 May
8 months ago

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

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