Не работает axios.post() выдает ошибку POST
127.0.0.1:8000/work/store 500 (Internal Server Error).
Я тестил, почему-то программа не заходит в axios и проходит мимо как только видит axios.post('
127.0.0.1:8000/work/store', category).
Мой js:
import React, { Component } from 'react';
import axios from 'axios';
export default class Add extends Component {
constructor(){
super();
this.onChangeCategoryName = this.onChangeCategoryName.bind(this);
this.onSubmit = this.onSubmit.bind(this);
this.state = {
category_name: ''
}
}
onChangeCategoryName(e){
this.setState({
category_name: e.target.value
});
}
onSubmit(e){
e.preventDefault();
const category = {
category_name : this.state.category_name
}
axios.post('http://127.0.0.1:8000/work/store', category)
.then((response) => {
console.log(response.data);
});
}
render() {
return (
<div>
<form onSubmit={this.onSubmit}>
<div className="form-group">
<label for="exampleInputEmail1">Category Name</label>
<input type="text"
className="form-control"
id="exampleInputEmail1"
value={this.state.category_name}
onChange={this.onChangeCategoryName}
placeholder="Enter catagory" />
</div>
<button type="submit" className="btn btn-primary">Submit</button>
</form>
</div>
);
}
}
Мой controller
public function store(Request $request)
{
$category = new Category();
$category->text = $request->category_name;
$category->save();
}
Мой Route в Web.php
Route::post('work/store', 'Api\TaskController@store');