Ad

How Correctly Store Data With Laravel Vue Axios

- 1 answer

I'm trying to send data to database from a vue component.

The vue component

                ...<form>
                    <div class="form-group">
                        <label for="name">Nom de la tache</label>
                        <textarea name="name" id="name" rows="4" class="form-control" v-model="name"></textarea>
                    </div>
                </form>...


<script>
export default {
    data() {
        return {
            name: ''
        }
    },

    methods: {
        taskStore() {
            axios.post('http://127.0.0.1:8000/taskStore', {
                name: this.name,
            })
                .then(response => console.log(response))
                .catch(error => console.log('une erreur '+error));
        }
    }
}
</script>

the road

Route::post('/taskStore', '[email protected]');

and the controller

public function store(Request $request)
    {
        Task::create($request);
    }

Please someone saw what's i'm doing wrong ? I got this error and i can't found why for moment. thanks by advance

Ad

Answer

To add to AWEMA Agence Web Marketing's answer above (since I can't add comments yet)

You'll also need to ensure the name attribute on your Task model is fillable

class Task extends Model {

   protected $fillable = ['name'];

}
Ad
source: stackoverflow.com
Ad