S
S
supercoder6662021-03-29 15:31:56
Laravel
supercoder666, 2021-03-29 15:31:56

Why doesn't the code in laravel controller work?

The code in the controller does not work. The form is being processed, when the button is pressed, the controller should be triggered, which writes the data to the database. The code inside the controller doesn't work. When you click on the button, the page simply reloads (at least it looks like this), it does not give any errors.

web.php:

Route::post('/post/{id}/submit', [\App\Http\Controllers\PostController::class, 'postCommentSubmit'])->name('postCommentSubmit');

PostController:
public function postCommentSubmit($id, PostRequest $data) {
  //здесь код, который не выполняется, не происходит даже редирект
return redirect()->route('home');
}

comments.blade.php:
<form action="{{ route('postCommentSubmit', $post[0]->id) }}" method="post" enctype="multipart/form-data">
        @csrf
        <textarea name="comment" id="" cols="30" rows="10" placeholder="Your answer"></textarea>
</div>
<button type="submit" class="btn btn-outline-primary">Submit</button>
</form>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question