我一直在研究 Laravel 和 VueJs,我正在使用 AXIOS 将数据保存到 MySQL,但是在使用 Post 时我有 403 被禁止
我使用的是 Windows 10 64 位和 Laragon
<script>import axios from 'axios';
export default{
data() {
return{
form:{
job_name: null,
job_description: null,
vacants: 0
}
}
},
methods:{
submit() {
axios.post('/job_postings', this.form)
.then(function (response) {
alert('success')
})
.catch(function (error) {
alert('something went wrong')
});
}
}
}
Route::resource('/job_postings',JobPostingController::class);
<?php
namespace App\Http\Controllers;
use App\Http\Requests\JobPostingRequest;
use App\Models\JobPosting;
use Exception;
use Illuminate\Http\Request;
class JobPostingController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return view('job_posting.index');
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(JobPostingRequest $jobPostingRequest, JobPosting $jobPosting)
{
$posting = $jobPosting::create($jobPostingRequest->all());
return response()->json(['message' => 'Job Posting has been sucessfully saved', 'data' => $posting]);
}
/**
* Display the specified resource.
*
* @param \App\Models\JobPosting $jobPosting
* @return \Illuminate\Http\Response
*/
public function show(JobPosting $jobPosting)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Models\JobPosting $jobPosting
* @return \Illuminate\Http\Response
*/
public function edit(JobPosting $jobPosting)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Models\JobPosting $jobPosting
* @return \Illuminate\Http\Response
*/
public function update(Request $request, JobPosting $jobPosting)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param \App\Models\JobPosting $jobPosting
* @return \Illuminate\Http\Response
*/
public function destroy(JobPosting $jobPosting)
{
//
}
}
开发控制台出错
{data: {…}, status: 403, statusText: "Forbidden", headers: {…}, config: {…}, …}
config: {url: "/job_postings", method: "post", data: "{"job_name":"test","job_description":"","vacants":0}", headers: {…}, transformRequest: Array(1), …}
data: {message: "This action is unauthorized.", exception: "Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException", file: "C:\laragon\www\lara-vue\vendor\laravel\framework\src\Illuminate\Foundation\Exceptions\Handler.php", line: 367, trace: Array(40)}
headers: {cache-control: "no-cache, private", connection: "close", content-type: "application/json", date: "Thu, 11 Feb 2021 14:33:57 GMT, Thu, 11 Feb 2021 14:33:57 GMT", host: "127.0.0.1:8000", …}
request: XMLHttpRequest {readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, onreadystatechange: ƒ, …}
status: 403
statusText: "Forbidden"
__proto__: Object
我一直在研究 Laravel 和 VueJs,我正在使用 AXIOS 将数据保存到 MySQL,但是在使用 Post 时我有 403 被禁止
我使用的是 Windows 10 64 位和 Laragon