0

我正在为Laravel Inertia. 我正在使用 Laravel v8.24.0 (PHP v7.3.26)。我尝试在互联网上搜索,但其中一些遇到它更新/编辑数据。

铅.vue

<script>
import Layout from "../../Shared/Layout";
export default {
components: {
   Layout,
},
data() {
return {
  lead: {
    name: "",
    email: "",
    phone: "",
    dob: "",
    package: "",
  },
};
},
methods: {
async handleSubmit() {
  let res = await this.$inertia.post("/leads/save", this.lead);
},
},
};

网页.php

Route::get('/', [WelcomeController::class, 'index']);
  Route::group(['middleware' => 'auth'], function () {
  Route::get('/dashboard', [DashboardController::class, 'index'])->name('dash');
  Route::get('/leads/add', [LeadController::class, 'create']);
  Route::get('/leads/save', [LeadController::class, 'store']);
});

领导控制器

public function store(Request $request)
{
    $postData = $this->validate($request, [
        'name' => 'required',
        'email' => "required|email",
        'phone' => "required|phone",
        'dob' => "required|date"
    ]);
    $package = "";
    if ($request->has('package')) {
        $package = $request->input('package');
    }
    Lead::create([
        'name' => $postData['name'],
        'email' => $postData['email'],
        'phone' => $postData['phone'],
        'dob' => $postData['dob'],
        'branch_id' => 1,
        'age' => 1,
        'added_by' => Auth::user()->id,
        'interested_package' => $package
    ]);

    return redirect()->route('dash');
}

但是在保存时我得到了一个错误在此处输入图像描述

4

1 回答 1

1

Route::post('/leads/save', [LeadController::class, 'store']);

在这里get解决post这个问题

于 2021-01-26T08:43:50.247 回答