lundi 8 novembre 2021

How can I fix this error related to to controller?

I have a problem, thank you for your help. I want this to be done in the Store method when a person submits a question But it gives me an error that says: thread_id required ???!

  Subscribe::query()->create([
        'thread_id'=>$thread->id,
        'user_id' => auth()->user()->id
    ]);

This is the code for my Store method, which includes the subscribe model:

 public function store(Request $request,Thread $thread)
{
    $request->validate([
        'title' => ['required', 'min:3'],
        'description' => ['required'],
        'channel_id' => ['required'],
        'thread_id' => ['required']
    ]);

    Thread::create([
        'title' => $request->title,
        'description' => $request->description,
        'user_id' => auth()->user()->id,
        'channel_id' => $request->channel_id,
    ]);

    Subscribe::query()->create([
        'thread_id' => $thread->id,
        'user_id' => auth()->user()->id
    ]);
    return redirect('/');
}

This is also the code related to View

<form action="" method="post">
@csrf
<input type="hidden" name="thread_id" value="">

<div class=" container-fluid w-75 border border-secondary rounded shadow">
    <div style="font-weight: bolder; font-size: large;" class=" my-3">فرم ارسال پرسش</div>
    <div class="input-group mb-3">
        <div class="input-group-prepend">

        </div>
        <input type="text" name="title" class="form-control" placeholder="موضوع" aria-label="Username" value=""
               aria-describedby="basic-addon1">
    </div>
    
    <div class="input-group">
        <textarea name="description" class="form-control" aria-label="With textarea" placeholder="متن پرسش"
                  style="height: 200px;"></textarea>
    </div>


    <div class="input-group mt-3 " style="direction: ltr;">
        <select name="channel_id" class="custom-select" id="channel_id" >
            <option selected disabled value="">انتخاب عنوان</option>
            @foreach(\App\Models\Channel::all() as $channel)
                <option value=""></option>
            @endforeach
        </select>

    </div>

    <div class="my-3" style="width: 100px;">
        <button class="btn btn-success" type="submit">ارسال</button>
    </div>


</div>

the problem about this code on view

<input type="hidden" name="thread_id" value="">

also i sent the Thread model on view

 public function create(Thread $thread)
{
    return view('answer-question.thread.thread-create',compact('thread'));
}

this is subcribe database enter image description here



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire