时光

时光的时光轴

寄以时间,予以文字
telegram
github
微信公众号

GPT Application Practical Guide: Upgrading Laravel Application

It's hard to imagine, but I can't live without Copilot and ChatGPT in my daily life. They make a great combination, and when I write simple programs, I basically just write comments and keep pressing TAB repeatedly. When I encounter a problem, I copy the error message and ask GPT for help, then search for information based on its reply, and continue with the next program.

I think this is extremely beneficial for daily programming, although I need to clarify my viewpoint before starting:

Artificial intelligence can only assist and help you learn. It helps you improve in the fields you are already familiar with.

Coincidentally, I have a project at hand and I thought about upgrading its framework from Laravel6 to Laravel9 when I had some free time. Since it involves several major versions, if I follow the usual process, I would have to upgrade step by step from 6 to 7, then 8, and finally 9. However, this time I wanted to see if I could use artificial intelligence to help me complete this task in one step.

First, set a prompt#

After adjusting/replacing the relevant dependencies to adapt to Laravel9, the first problem I encountered was a blank screen.

As usual, I checked the logs, but it was strange that Laravel's built-in logs were not generated and Nginx did not report any errors. Basically, nothing was being output. I wondered if it could be a caching issue, so I ran php artisan cache:clear and received an error message:

Call to undefined method App\Exceptions\Handler::render()

I looked into it and found that the code for binding error events was incorrect. I tried asking it what the difference was between the two versions, and it told me that the Exceptions class had been replaced with the Throwable class.

So, could I just replace everything at once?

image

image

I copied and pasted the replacement code, and it worked! Believe it or not, it actually worked!

Then, the second error I encountered was:

Undefined constant Illuminate\Http\Request::HEADER_X_FORWARDED_ALL

I provided some additional information on what I wanted to do:

image

According to the answer given, I just needed to replace the variable.

However, from this point on, you might be able to sense that in the routing class, the Illuminate\Http\Request is usually used at the beginning of the file, and blindly replacing it is not advisable.

Luckily, I was taken directly to the installation page:

image

Recording the debugging process#

Simple error#

During the debugging process, I encountered an issue where a parameter for deleting a file should not be set to null. I looked at the code and realized that I had not handled the case where no file was passed in. I added the necessary check and it worked.

image

Translating for the product#

While making changes, I discovered that the previous English translation for the multilingual feature was incomplete and didn't cover everything. So, I decided to see if I could let it handle this task.

I can only say, it saves effort and money. But it's not very time-saving.

Why?

image
image

At first glance, it looks good, but once the content becomes too long...

image

When you ask it to continue and generate more output, it starts making up stories. The content output in this section is not present in my source file.

And the code formatting is not always preserved exactly, occasionally resulting in missing code. However, the translation quality is really good, and it preserves the variable formatting, which is really convenient.

I wrote at the beginning of the file:

The file was created by outtime and aided with ChatGPT.

to indicate that I took a shortcut. (This sentence was also suggested by ChatGPT)

Adding a checkbox#

image

image

I mean, who wouldn't like this feeling?

This is the first time I've used it to help me with code, besides writing copy. I've seen many people share their experiences of using GPT to generate most of their project's code, but I always worry that using fully generated code will result in more problems than if I had written it myself.

But when you experience something like spending a long time searching on search engines and not finding any usable code, then telling GPT what you need and getting usable code in a matter of seconds, I can only say that I have a high opinion of myself 😂

This is a tool that everyone must master in the future.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.