H
H
HeartOfProgrammer2016-06-05 17:18:24
Laravel
HeartOfProgrammer, 2016-06-05 17:18:24

Why is the request to edit the news not sent?

The third hour I can not solve the problem, there are news on the site, and each news has the "Delete" and "Edit" buttons. So, when you go to the localhost:8000/news/1/edit page , everything is fine, but the request to change the news is not sent.
news is the route/1 is the id of the news/edit is the edit page.
I thought the problem was in POST-GET, but no.
The "Editing" page of the news itself:

<div class="edit-news">
        <h2 class="text-center">Редактирование: <b>{{ $news->title }}</b></h2>
        <form method="PUT" action="{{ route('news.update', $news->id) }}">

        <div class="form-group">
            <label for="title">Название:</label>
            <input class="form-control" placeholder="Введите названия" name="title" type="text" required autofocus
            >
        </div>

        <div class="form-group">
            <label for="description">Описание новости:</label>
            <p><textarea name="description" id="description" cols="30" rows="10" required></textarea></p>
        </div>

        <br>

        <div class="form-group">
            <label for="full_description">Полное описание новости:</label>
            <p><textarea name="full_description" id="full_description" cols="30" rows="10" required></textarea></p>
        </div>

        <br>

        <div class="form-group">
            <label for="author">Автор:</label>
            <input class="form-control" placeholder="Введите автора" name="author" type="text" required>
        </div>

        <div class="form-group">
            <input type="submit" class="btn btn-success" value="Сохранить">
        </div>

        </form>
    </div>

update method in NewsController
public function update($id, PublishNewsRequest $requestData)
    {
        $news = News::find($id);

        $news->title = $requestData['title'];
        $news->description = $requestData['description'];
        $news->full_description = $requestData['full_description'];
        $news->author = $requestData['author'];

        $news->save();

        return redirect()->route('news.index');
    }

When you try to change the news
, it gives you the following link:
1faf5b074c094eaf8b75936934b514e7.png
All routes
7548d0e4c55f48238abed9c9e19d38f5.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2016-06-05
@HeartOfProgrammer

HTML forms do not support PUT, PATCH or DELETE actions. So, when defining PUT, PATCH or DELETE routes that are called from an HTML form, you will need to add a hidden _method field to the form.

https://laravel.com/docs/5.2/routing#form-method-s...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question