How to specify the ID for ElSelect

I’ve recently used https://element.eleme.io which UI Framework for Vuejs. I got a situation when I was using the ElSelect component that I need passing an object to the value attribute of ElOption component. This is my first init code for this.

            <el-select
              class="xs:w-full"
              v-model="selectedSiblings"
              multiple
              filterable
              allow-create
              default-first-option
              placeholder="Choose sibling for your club">
              <el-option
                v-for="item in siblings"
                :key="item.id"
                :label="`${item.first_name} ${item.last_name}`"
                :value="item">
              </el-option>
            </el-select>

I used the id value for the key attribute. But it did not work. Vuejs showed me an error message said that the ElOption component could not specify the key.

I researched around on Google for a while and found the answer. The answer is we need to set another attribute for ElSelect component to determined the key in this case. It is value-key attribute. So I added it to the ElSelect component and it worked.

            <el-select
              value-key="id"
              class="xs:w-full"
              v-model="selectedSiblings"
              multiple
              filterable
              allow-create
              default-first-option
              placeholder="Choose sibling for your club">
              <el-option
                v-for="item in siblings"
                :key="item.id"
                :label="`${item.first_name} ${item.last_name}`"
                :value="item">
              </el-option>
            </el-select>

Hope this help.

Issue installing Carbon package in Laravel 5.8

Today, I got this error while I’m trying to install Laravel Dusk.

Error message with Carbon package

The error message said that we need to use the new version of Carbon instead of current version 2.18.0. Since Laravel has already used the Carbon as default but it used 2.1*. So I alias the current version as the latest version in composer.json.

    "require": {
        "php": "^7.1.3",
        "fideloper/proxy": "^4.0",
        "laravel/framework": "5.8.*",
        "laravel/tinker": "^1.0",
        "nesbot/carbon": "2.18.0 as 1.34.0"
    },

Finally, I ran the command install the Laravel Dusk again. The error has gone.

The installation Laravel Dusk successfully

The server requested authentication method unknown to the client in MySQL 8

Hello guys,
Today, I got another error when I tried to run migrate artisan command in Laravel. The error said: “The server requested authentication method unknown to the client”. This error appeared after I upgraded MySQL server from 5.7 to latest version as known 8.0.

By default, for some reasons, the default plugin of MySQL 8 is auth_socket. So the Applications will most times expect to log in to your database using a password. If you have not changed your mysql default authentication plugin yet, you can do these:

I have to change MySQL configuration. I edited the my.cnf file and put this line right below the [mysqld] like this.

[mysqld]
default_authentication_plugin= mysql_native_password

Then, I logged in the MySQL as root. Next, I ran these commands in the terminal.

ALTER USER 'admin' IDENTIFIED WITH mysql_native_password BY 'secret';
FLUSH PRIVILEGES;

Replace “secret” with your root password. In case your application does not log in to your database with the root user, replace the “admin” user in the above command with the user that your application uses.

Route Order and Overwrite defined in Package in Laravel

I faced a problem that I have a route which does not work in any case. It always show not found.

After researching around, I know that because of the ordered of the routes. To demonstrate, imagine I have 2 routes:

GET /post/{id} and GET /post/create

So in this case, the second route will be never called. Because Laravel matches the first route and immediately break at this point.

Back to my problem, I comment our all my routes except the problemable route. But it still does not work. I list all routes in the application by php artisan route:list command. And below is my result.

There is another route which defined by Laravel Spark package. It overwrites all my route because it called very first by the application. So I have to find out either call my routes before that route called or overwrite it.

I googled and found this answer https://stackoverflow.com/a/44724330/4184355. The answer said we can overwrite it by rearrange the Service Provider which define in config/app.php. I write RouteServiceProvider before SparkServiceProvider . I access my route again and get this error The bootstrap/cache directory must be present and writable. It means I have to clear the cache. So I run php artisan cache:clear and the problem is gone. My route works again.

Cron Job in Docker Container

I have created a cron job for my project recently. At the beginning, I created it on the host with the command:

* * * * * cd ~/duy/project/test/app && php artisan schedule:run >> /dev/null 2>&1

But it seems my cron was not working. It takes me over 10 mins to figured out that I was on the local machine, so I guessed my php artisan command was not working. So I jumped into the Docker container which contains my source code Laravel and ran above command again. But I got no luck. After 30 mins, my work was still stocking. Therefore, I had to take a break. I got a hot cup of local tea. Drunk it and no longer thinking about the cron job problem is.

At the evening, I came back to the work. I thought I need to know what was going on behind the scene. So I wrote the command line which echoes the test text said “OK” which inserted into a log file every the Cron invoked. Ran the Cron again and checked the log file. Nothing was there. So I researched around on Google. I got this comment on stackoverflow.com https://stackoverflow.com/a/44958097/4184355. Following this post, I have rebuilt my Docker container with including few RUN commands.

I added cron, nano editor to the webserver and a test cronjob.

RUN apt-get update && apt-get -y install cron nano
RUN (crontab -l ; echo "* * * * * echo "Hello world" >> /var/www/html/log.txt") | crontab

If the cronjob work, It will write the “Hello world” text every minute into the log.txt file. Then, I was waiting for a few minutes and came back to check the log.txt file. No text was there :(. I kept googling. I found out that I could check whether the cronjob working or not by the command service cron status. Then it said:


Finally, I found this post https://www.bigbrus.com/2015/12/15/cron-death-cant-lock-varruncrond-pid-otherpid-may-be/. The post showed me a few solutions. I tried to one of them kill -9 $(cat /var/run/crond.pid)

Then, I checked the cronjob again by the command service cron status. Now it showed ok.

To ensure that the cronjob is working fine, I opened the log.txt file. There were many “Hello world” in there. So my problem solved. The next part is appending the cronjob for the schedule command Laravel.