jeudi 13 décembre 2018

how to insert data to database with vue and laravel

i trying to create a crud system using vue js and laravel.

i already create api route and more...

but when i click submit i got message 405 (Method Not Allowed)

here my AddArtist.vue file

<form @submit.prevent="add">
<input type="text" class="form-control" v-model="artist.name"  placeholder="Artist Name">
<button class="btn btn-success" type="submit">Save</button>
</form>

<script>
    export default {
        data: function () {
        return {
            errors: [],
            image: '',
            artist: {
                    name: '',
                }
        }
        },
        methods: {
            add() {
                axios.post('/api/artist/store-artist', this.$data.artist)
                    .then((response) => {
                        alert('Success add Artist')
                        console.log(response)
                    })
            },
        },
            mounted() {
                console.log('Add Artist Mounted.')
            }
    }
</script>

and my api.php route

Route::group(['middleware' => 'cors'], function(){
    Route::post('addartist/store-artist', 'ArtistController@store');
});

and here my controller ArtistController.php

public function store(Request $request)
    {
        $input = $request->all();
        dd($input);
    }

and the last is my model Artist.php

class Artist extends Model
{
    protected $table = 'artist';
    protected $fillable = ['artist_name', 'date_birth', 'cover', 'gender'];
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire