Vue js Laravel axios POST 500内部服务器错误
我刚刚使用Axios for call API创建了laravel Vuejs项目。 GetAPI运行良好,但当我要发布数据时,获取内部服务器错误。 我正在使用Resources作为控制器。 我只是创建Api并通过以下方式获取数据:Vue js Laravel axios POST 500内部服务器错误,laravel,vue.js,laravel-6,http-status-code-500,Laravel,Vue.js,Laravel 6,Http Status Code 500,我刚刚使用Axios for call API创建了laravel Vuejs项目。 GetAPI运行良好,但当我要发布数据时,获取内部服务器错误。 我正在使用Resources作为控制器。 我只是创建Api并通过以下方式获取数据: VueLavel是我的项目名称。 它工作得很好。但当我试图将数据发布到数据库中时,它显示了500个内部错误 Here is my controller: <?php namespace App\Http\Controllers; use App\Tod
VueLavel是我的项目名称。 它工作得很好。但当我试图将数据发布到数据库中时,它显示了500个内部错误
Here is my controller:
<?php
namespace App\Http\Controllers;
use App\Todo;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
class TodoController extends Controller
{
public function index()
{
$tasks=Todo::orderBy('id', 'desc')->paginate(2);
return request()->json(200,$tasks);
}
public function create()
{
//
}
public function store(Request $request)
{
$todo=Todo::create($request->all());
if($todo){
$tasks=Todo::orderBy('id', 'desc')->paginate(2);
return request()->json(200,$tasks);
}
}
public function show(Todo $todo)
{
//
}
public function edit(Todo $todo)
{
//
}
public function update(Request $request, Todo $todo)
{
//
}
public function destroy(Todo $todo)
{
//
}
}
我正在Welcome.blade.php中使用我的csrf
<meta name="csrf-token" content="{{csrf_token()}}">
试试这个
响应($tasks)
方法
$tasks=Todo::orderBy('id','desc')->分页(2);
返回响应($任务);
由于您在模型中使用的是“创建”方法,请将此代码置于上方,以确保已在模型中指定了质量
protected $guarded = [];
请阅读此文档检查您的网络选项卡并查看错误您确定axios中的url正确吗?您可以在“catch()”console.log(error.response)中执行此操作以显示更多详细信息。是get和post的用户。Get正在工作,但post不工作。您是否已经为todo模型分配了大量任务?在我的todo模型中,我没有分配任何任务。创建一个模型。谢谢兄弟,你很棒。这就是问题解决者之间的区别。
app.js:285 POST http://localhost:8080/vuelaravel/tasks 500 (Internal Server Error)
at createError (app.js:699)
at settle (app.js:960)
at XMLHttpRequest.handleLoad (app.js:168)
<meta name="csrf-token" content="{{csrf_token()}}">
created(){
axios.get("http://localhost:8080/vuelaravel/tasks")
.then(response =>{this.tasks = response.data})
.catch(error => console.log(error.response));
}
protected $guarded = [];