Argument #1 ($values) must be of type array, string given
Pardon, I don't understand what the error is? I'm trying create comment for topic. I got these error.
Thank you.
Thank you.
Argument #1 ($values) must be of type array, string given//
public ?array $data = [];
//
$record = Comment::create([
array_merge($data, [
'user_id' => auth()->id(),
'topic_id' => $this->topic->id,
]),
]);Typed property App\Http\Livewire\Forum\AddComment::$feeling must not be accessed before initializationQLSTATE[23502]: Not null violation: 7 ERROR: null value in column "feeling_id" of relation "comments" violates not-null constraint DETAIL: Failing row contains (505, 1, null, fasd asdfa sdfae, 2023-03-21 17:29:52, 2023-03-21 17:29:52). (Connection: pgsql, SQL: insert into "comments" ("content", "user_id", "feeling_id", "updated_at", "created_at") values (fasd asdfa sdfae, 1, ?, 2023-03-21 17:29:52, 2023-03-21 17:29:52) returning "id")public Feeling $feeling;protected function getFormSchema(): array
{
return [Forms\Components\Textarea::make('content')->required()];
}
public function replyFeeling()
{
abort_if(auth()->guest(), Response::HTTP_FORBIDDEN);
$data = $this->form->getState();
$record = Comment::create(
array_merge($data, [
'user_id' => auth()->id(),
'feeling_id' => $this->feeling->id,
]
)
);
//////<?php
namespace App\Http\Livewire\Forum;
use Filament\Forms;
use App\Models\Comment;
use App\Models\Feeling;
use Livewire\Component;
use Illuminate\Http\Response;
use Filament\Notifications\Notification;
class AddComment extends Component implements Forms\Contracts\HasForms
{
use Forms\Concerns\InteractsWithForms;
public Feeling $feeling;
public ?array $data = [];
public bool $showReplyModal = false;
public function mount(): void
{
$this->form->fill();
}
public function confirmFeelingReply(): void
{
$this->showReplyModal = true;
}
protected function getFormSchema(): array
{
return [Forms\Components\Textarea::make('content')->required()];
}
public function replyFeeling()
{
abort_if(auth()->guest(), Response::HTTP_FORBIDDEN);
$data = $this->form->getState();
$record = Comment::create(
array_merge($data, [
'user_id' => auth()->id(),
'feeling_id' => $this->feeling->id,
]
)
);
$this->form->model($record)->saveRelationships();
Notification::make()
->title('Commented successfully')
->success()
->send();
$this->reset('data');
$this->showReplyModal = false;
$this->emit('commentWasAdded');
return redirect()->back();
}
protected function getFormModel(): string
{
return Comment::class;
}
protected function getFormStatePath(): string
{
return 'data';
}
public function render()
{
return view('livewire.forum.add-comment');
}
}<livewire:forum.add-comment :feeling="$feeling" />