Thursday, March 30, 2017

how to receive json object from laravel

i'm sending a json object from laravel function:-

public function store(Request $request)
{
    $this->validate($request,[
        'name'=>'required',

    ]);

    $group = Group::create($request->all());
    return response()->json(['success'=>true , 'group'=>$group]);
}

and i want to receive it using javascript but nothing is working, i want to access the name of this:-

enter image description here

i'm trying to access it using this function but it can output to the console fine but cant get to the name there, thanks

<script>
  // _token: $("input[name=_token]").val()
    var app = new Vue({
      el: '#app',
      data: {
        startingGroup: '',
        GroupName:''
      },
      methods: {
        AddNewGroup: function() {
          // console.log(this.startingGroup);
          var app = this
                axios.post('/groups/store', {
                name: this.startingGroup
                 })
                .then(function (response) {
                 console.log(response);
                 })
                .catch(function (error) {
                  app.GroupName = "Invalid Name"
                })
        }
      }
    })
  </script>



via Mohamed Gabr

Advertisement