mercredi 11 mai 2016

Cannot access id being passed in vue.js and laravel

I am having hard time inserting the values which is the id that is being passed from the form into the controller of my enrollment system. To achieve this I make use of vue.js and vue-resource library. In my all.js file I am gettting the correct id value when I console.log the id being passed. However, when passing it to the route address of my application I am getting 500 error. Also, upon debugging I' m getting this error SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'section_subject_id' cannot be null (SQL: insert into reservations. How can I solve this?

ReservationController.php

class ReservationController extends Controller
{

    public function create($id)
    {

        $subjects = Subject::with('sections')->get();

        return view('reservation.form',compact('subjects'));
    }

    public function store(Request $request)
    {

        $subject = new Reservation();

        $subject->section_subject_id = $request->input('id');

        $subject->student_id = 1;

        $subject->save();

    }
}

all.js

Vue.http.headers.common['X-CSRF-TOKEN'] = document.querySelector('#token').getAttribute('value');

new Vue({
    el: '#app-layout',

    data: {
        subject: {
            id : ''
        },
        subjects: []

    },
    ready: function(){

    },
    methods:{
        addSubject: function(id){

            this.subject = id;

            this.$http({url: 'http://localhost:8000/reservation', id, method: 'POST'}).then(function(response){

            }, function (response){
                console.log('error');
            });
        }
    }
});

form.blade.php

<body>
  @foreach($subjects as $subject)
  @foreach($subject->sections as $section)
  <tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td>
      <button 
         v-on:click="addSubject(  )" 
         class="btn btn-xs btn-primary">Add
         </button>

       <button class="btn btn-xs btn-info">Edit</button>
     </td>
    </tr>
   @endforeach
  @endforeach
 </body>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire