You need to examine the laravel log to determine the error
May 12, 2023
3
Level 63
Working fine on localhost but not on the production server
Hello,
I have this code which works fine on localhost, but it generates a 500 error on the production server when I click on the submit button. Furthermore when I type text in the textarea, the $loading property becomes true on every new caracter whereas it doesn't do that on localhost.
What could be the source of the problem ?
Here is my view and the controller.
<div class="flex flex-col gap-4">
<x-info-card>
Seules les balises ci-contre seront analysées : {{ implode(', ', $tags) }}. Toutes les autres balises seront supprimées.
</x-info-card>
<div class="flex flex-col gap-1">
<label class="flex justify-between items-center text-gray-500">
Texte à paraphraser
@if ($original_text)
<span class="transition-all text-sky-300 cursor-pointer" wire:click="init">
<i class="fa-solid fa-trash-alt"></i> Réinitialiser
</span>
@endif
</label>
<textarea class="outline-none px-3 py-1 border border-sky-300 rounded-lg" name="text" rows="5" wire:ignore wire:model="original_text"></textarea>
@error('text')
<span class="text-sm text-red-500">{{ $message }}</span>
@enderror
</div>
<x-button wire:click="submit">
Paraphraser
</x-button>
<div wire:loading.delay><x-loader></x-loader></div>
@if ($paraphrased_text)
<div
x-data="{
copyToClipboard() {
document.getElementById('result').select();
document.execCommand('copy');
}
}"
class="flex flex-col gap-1"
>
<label class="flex justify-between items-center text-gray-500">
Texte paraphrasé
@if ($paraphrased_text)
<span @click="copyToClipboard" class="transition-all text-sky-300 cursor-pointer">
<i class="fa-solid fa-copy"></i> Copier
</span>
@endif
</label>
<textarea id="result" class="outline-none px-3 py-1 border border-sky-300 rounded-lg read-only" rows="10" wire:ignore wire:model="paraphrased_text"></textarea>
</div>
@endif
<x-button-link href="{{ route('nlp-cloud.options') }}" class="text-center">
Retourner à la liste des options
</x-button-link>
</div>
<?php
namespace App\Http\Livewire\NlpCloud;
use App\Services\NlpCloudService;
use Illuminate\Support\Str;
use Livewire\Component;
use NlpCloud;
use PHPHtmlParser\Dom as Dom;
use PHPHtmlParser\Options as Options;
class Paraphrase extends Component
{
public $loading = false;
public string $original_text = '';
public string $paraphrased_text = '';
public string $message = '';
public $tags = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'ul', 'ol', 'li'];
public $analysedTags = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'li'];
public $minLength = 30;
public function submit()
{
$client = (new NlpCloudService)->getClient();
if ($client) {
$this->loading = true;
$original_text = Str::of($this->original_text)->trim();
// Vérifie si le texte fourni contient des balises
if ($original_text != strip_tags($original_text)) {
$original_text = strip_tags($original_text, $this->tags);
$dom = new Dom;
// $dom->setOptions([
// 'preserveLineBreaks' => true,
// ]);
$dom->loadStr($original_text);
foreach ($this->analysedTags as $tag) {
foreach ($dom->find($tag) as $item) {
$text = Str::of($item->text)->trim();
if (strlen($text) >= $this->minLength) {
if ($text != '') {
$result = $client->paraphrasing($text)->paraphrased_text;
$item->firstChild()->setText($result);
}
}
}
}
$this->paraphrased_text = $dom->outerHtml;
} else {
if (strlen($original_text) >= $this->minLength) {
$this->paraphrased_text = $client->paraphrasing($original_text)->paraphrased_text;
} else {
$this->paraphrased_text = $original_text;
}
}
} else {
$this->message = 'Erreur : le service NlpCloud n\'a pas pu être initialisé.';
}
$this->loading = false;
}
public function init()
{
$this->reset([
'original_text',
'paraphrased_text',
'message'
]);
}
public function render()
{
return view('livewire.nlp-cloud.paraphrase');
}
}
Do you see something wrong ?
Thanks a lot ;).
V
Please or to participate in this conversation.