server error? Look in Laravel log file
Oct 16, 2021
11
Level 12
Livewire can't insert something, deployed code
I can't make a new Idea when I try to do so on the deployed website, https://playazchoice.herokuapp.com I can locally but not there, why? It gives a 500 Server Error message
CreateIdea.php
<?php
namespace App\Http\Livewire;
use App\Models\Idea;
use Livewire\Component;
use App\Models\Category;
use Illuminate\Http\Response;
class CreateIdea extends Component
{
public $title;
public $category = 1;
public $description;
protected $rules = [
'title' => 'required|min:4',
'category' => 'required|integer',
'description' => 'required|min:4',
];
public function createIdea()
{
if (auth()->check()) {
$this->validate();
Idea::create([
'user_id' => auth()->id(),
'category_id' => $this->category,
'status_id' => 2,
'title' => $this->title,
'description' => $this->description,
]);
session()->flash('success_message', 'Idea was added successfully');
$this->reset();
return redirect()->route('idea.index');
}
abort(Response::HTTP_FORBIDDEN);
}
public function render()
{
return view('livewire.create-idea', [
'categories' => Category::all(),
]);
}
}
If it works locally... and I receive no errors or warnings...all the settings ever needed to run a database are there, I been migrating and running my seeds now with no problem but I can't make use of a form sadly.
<form wire:submit.prevent="createIdea" action="#" method="POST" class="space-y-4 px-4 py-6">
<div>
<input
wire:model.defer="title"
type="text"
class="w-full border-none bg-gray-100 text-sm rounded-xl text-gray-900 placeholder-gray-500 px-4 py-2"
placeholder="Your idea"
required
>
@error('title')
<p class="text-red text-xs mt-1">{{ $message }}</p>
@enderror
</div>
<div>
<select
wire:model.defer="category"
name="category_add"
id="category_add"
class="w-full bg-gray-100 rounded-xl px-4 py-2 border-none text-gray-900 text-sm"
required
>
@foreach ($categories as $category)
<option value="{{ $category->id }}">{{ $category->name }}</option>
@endforeach
</select>
</div>
@error('category')
<p class="text-red text-xs mt-1">{{ $message }}</p>
@enderror
<div>
<textarea
wire:model.defer="description"
name="idea"
id="idea"
cols="30"
rows="4"
class="w-full bg-gray-100 rounded-xl placeholder-gray-500 text-sm px-4 py-2 border-none text-gray-900"
placeholder="Describe the idea"
required></textarea>
@error('description')
<p class="text-red text-xs mt-1">{{ $message }}</p>
@enderror
</div>
<div class="flex items-center justify-between space-x-3">
<button
type="button"
class="flex items-center justify-center w-1/2 h-11 text-xs bg-gray-200
font-semibold rounded-xl border border-gray-200 px-6 py-3 text-black
hover:border-gray-400 transition duration-150 ease-in"
>
<svg class="text-gray-500 w-4 transform -rotate-45" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13" />
</svg>
<span class="ml-1">Attach</span>
</button>
<button
type="submit"
class="flex items-center justify-center w-1/2 h-11 text-xs bg-blue
font-semibold rounded-xl border border-blue px-6 py-3
hover:bg-blue-hover transition duration-150 ease-in"
>
<span class="ml-1">Submit</span>
</button>
</div>
<div>
@if (session('success_message'))
<div
x-data="{ isVisible: true }"
x-init="
setTimeout(() => {
isVisible = false
}, 5000)
"
x-show.transition.duration.1000ms="isVisible"
class="text-gray-900 p-2 text-center mt-4">
{{ session('success_message') }}
</div>
@endif
</div>
</form>
Please or to participate in this conversation.