hello i am new on livewire, now i am facing some bug. i'm getting 500 internal server error when i am triggering the button.
i don't how to fix this i already re installed fresh laravel with livewire but it still the same error. i will show my code
welcome.blade.php
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="{{ mix('css/app.css') }}">
<livewire:styles />
</head>
<body class="bg-red">
<livewire:scripts />
<div class="container mx-auto px-4 my-5">
<livewire:postcart/>
</div>
<script src="{{ asset('js/app.js') }}"></script>
</body>
</html>
Livewire controller
<?php
namespace App\Http\Livewire;
use Livewire\Component;
class Postcart extends Component
{
public $name;
public function createPost(){
dd($this->name);
}
public function render()
{
return view('livewire.postcart');
}
}
livewire postcart file
<div class="mb-6">
<label for="default-input" class="block mb-2 text-sm font-medium text-gray-900 dark:text-gray-300">Name</label>
<input type="text" id="default-input" wire:model="name" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500">
<button class="my-2 rounded-lg p-2 bg-green-500 hover:bg-green-600" wire:click="createPost">Button</button>
</div>
That is the expected behavior of dd()
. From the source code , you can see that it looks like this,
function dd(...$vars): void
{
if (!in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && !headers_sent()) {
header('HTTP/1.1 500 Internal Server Error');
}
foreach ($vars as $v) {
VarDumper::dump($v);
}
exit(1);
}
Where it will pass a 500 header with it. So the behavior you are seeing is entirely correct. If you were to use dump()
instead, or do any other action, it would have a normal response.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.