我总是得到“找不到具有给定标识符的资源”

问题描述 投票:0回答:1

我正在实现一个简单的后查询,并且我之前已经实现了类似的查询,一切都很好,但在这里我得到了这个错误。它发生在控制台深处的某个地方,即使我也没有立即看到它

控制器

`class OperatorController extends Controller
{
    public function index()
    {
        $ldap_users = LdapUser::all();
        return view('pages.home')->with('ldap_users', $ldap_users);
    }

    public function storeUser(LdapUserStoreRequest $request)
    {
try {
            $validatedData = $request->validated();
            Log::error("тут "`your text` .$validatedData );

            $validatedData['full_name'] = $this->generateLogin($validatedData['full_name']);

            LdapUser::create($validatedData);
        } catch (Exception $e) {
            Log::error("Ошибка при создании пользователя: " . $e->getMessage());
            return response("Ошибка при создании пользователя", 202);
        }
        return response('success', 201);
    }}`

web.php

Route::middleware("auth:web")->group(function () {
    Route::get('/', [OperatorController::class, 'index'])->name('home');
    Route::get('/logout', [AuthController::class, 'logout'])->name('logout');
    Route::post('/createUser', [OperatorController::class, 'storeUser'])->name('createUser');
});

js脚本

    <script>


        function createUser2() {
            var userPanel = document.getElementById("userPanel");
            var formData = new FormData(userPanel);
            var xhr = new XMLHttpRequest();
            var csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
            xhr.open('POST', '{{ route("createUser") }}');
            xhr.setRequestHeader('X-CSRF-TOKEN', csrfToken);

            xhr.onload = function () {
                if (xhr.status === 201) {
                    alert('Пользователь успешно создан!');
                    document.getElementById("createUserError").textContent = "";
                } else if (xhr.status === 202) {
                    document.getElementById("createUserError").textContent =
 "Ошибка: "  +xhr.responseText;
                } else if (xhr.status === 200) {
                    document.getElementById("createUserError").textContent = "Ошибка введённых данных";
                }
            };
            xhr.send(formData);
            console.error(xhr.statusText);

        }
    </script>

刀片.php

<div id="createUserModal" class="modal">
    <div class="create-modal-content">
        <h2>Создание нового пользователя
            <button class="btn btn-danger close-button " onclick="closeCreateUserPanel()">Закрыть</button>
        </h2>
        <form id="userPanel">
            <div id="createUserError"></div>
            <table>
                <tr>
                    <th>Full Name</th>
                    <th>Mobile phone</th>
                    <th>Internal phone</th>
                    <th>Department</th>
                </tr>
                <tr>
                    <td><input type='text' name='full_name' id="createUserFullName" placeholder='Full Name'></td>
                    <td><input type='text' name='m_phone' id="createUserMPhone" placeholder='Mobile phone'></td>
                    <td><input type='text' name='i_phone' id="createUserIPhone" placeholder='Internal phone'></td>
                    <td><input type='text' name='department' id="createUserDepartment" placeholder='Department'></td>
                    <td>
                        <button class='btn btn-primary  create-btn' type='button' onclick="createUser2()">Создать</button>
                    </td>
                </tr>
            </table>
        </form>
    </div>
</div>

总是收到代码 200 和“未找到具有给定标识符的资源”

我尝试过重新路由 并更改控制器并尝试以不同的方式发送数据,但我看到的只是这个。

javascript php laravel post
1个回答
0
投票

我很愚蠢,只是以不同的方式命名参数。在请求规则中,我命名为 mobile_phone,但在 html m_phone 中,没有看到 ide 的错误

© www.soinside.com 2019 - 2024. All rights reserved.