06 May, 2023
05 May, 2023
Lemon Squeezy for Laravel
Programing Coderfunda
May 05, 2023
No comments
04 May, 2023
Small but powerful CLI apps with Minicli
Programing Coderfunda
May 04, 2023
No comments
03 May, 2023
LDAP Framework for PHP
Programing Coderfunda
May 03, 2023
No comments
02 May, 2023
Use ChatGTP to ask a question to the Laravel Docs
Programing Coderfunda
May 02, 2023
No comments
01 May, 2023
Why does caching feels slower?
Programing Coderfunda
May 01, 2023
No comments
30 April, 2023
How to manage data and perform CRUD operations on a "models" that are stored in YAML files rather than in my database?
Programing Coderfunda
April 30, 2023
No comments
29 April, 2023
Top 10 Laravel Audit Security Issues
Programing Coderfunda
April 29, 2023
No comments
28 April, 2023
Laravel 10.9 Multiple Image Upload In PHP
Programing Coderfunda
April 28, 2023
Laravel
No comments
<form action="uploading.php" method="POST" enctype="multipart/form-data">
<input type="file" name="image_path[]">
</form>
$files = $request->file('image_path');
//upload multipal file one row diffrent name with seprate comma
$i = 0;
if($request->hasfile('image_path')){
foreach ($files as $file) {
// $name = $file->getClientOriginalName();
//with $i help you save diffrent name file
$name = time() . $i . '.' . $file->getClientOriginalExtension();
//movie file in folder location
$file->move(public_path().'/backend/image/',$name);
$datavk[] = $name;
//save data in database with diffrent name with comma
$user->document_name = implode(",",$datavk);
$i++;
}
}
Using attributes to add value
Programing Coderfunda
April 28, 2023
No comments
27 April, 2023
Laravel 10.9 Released
Programing Coderfunda
April 27, 2023
No comments
26 April, 2023
Going past Actions in Laravel
Programing Coderfunda
April 26, 2023
No comments
25 April, 2023
Laravel Vapor application observability with Inspector
Programing Coderfunda
April 25, 2023
No comments
24 April, 2023
Weekly /r/Laravel Help Thread
Programing Coderfunda
April 24, 2023
No comments
23 April, 2023
SpinLock VB.Net Example From MSDN Possibly Produces Incorrect Behaviour
Programing Coderfunda
April 23, 2023
No comments
22 April, 2023
laracon US 2023 lodging
Programing Coderfunda
April 22, 2023
No comments
Generate String Acronyms with this Laravel Macro
Programing Coderfunda
April 22, 2023
No comments
21 April, 2023
How to implement chat GPT in Laravel
Programing Coderfunda
April 21, 2023
Laravel
No comments
Install the
guzzlehttp/guzzlepackage using Composer:bashcomposer require guzzlehttp/guzzleCreate a new controller that will handle the chatbot logic:
gophp artisan make:controller ChatbotControllerIn the
ChatbotController, import theGuzzleHttp\Clientclass:arduinouse GuzzleHttp\Client;Create a function that will handle the chatbot requests. In this function, you will make a POST request to the ChatGPT API endpoint and pass the user's message as a parameter:
phppublic function chatbot(Request $request) { $client = new Client(); $response = $client->post('https://api.openai.com/v1/engine/<ENGINE-ID>/completions', [ 'headers' => [ 'Authorization' => 'Bearer <API-KEY>', 'Content-Type' => 'application/json', ], 'json' => [ 'prompt' => $request->message, 'max_tokens' => 50, 'temperature' => 0.7, ], ]); $result = json_decode($response->getBody()->getContents(), true); return response()->json(['message' => $result['choices'][0]['text']]); }In the
routes/web.phpfile, create a new route that will point to thechatbotfunction in theChatbotController:cssRoute::post('/chatbot', 'ChatbotController@chatbot');Finally, in your front-end, create a form that will submit the user's message to the
chatbotroute using AJAX:php<form id="chat-form"> <input type="text" name="message" placeholder="Type your message..."> <button type="submit">Send</button> </form> <div id="chat-messages"></div> <script> $('#chat-form').submit(function(e) { e.preventDefault(); $.ajax({ type: 'POST', url: '/chatbot', data: $('#chat-form').serialize(), success: function(response) { $('#chat-messages').append('<p>You: ' + $('#chat-form input[name=message]').val() + '</p>'); $('#chat-messages').append('<p>Chatbot: ' + response.message + '</p>'); $('#chat-form input[name=message]').val(''); }, }); }); </script>
That's it! With these steps, you should now be able to implement ChatGPT in Laravel










