jeudi 10 mars 2016

BadMethodCallException in Macroable.php line 81:

I an developing a page to create, update, delete and view an event in which there is error while updating the event. There is a event table and a event_collection table. In that event_collection table there is event_id which is id of an event and a collection_id which is from other table collection.

When i create an event, all the data gets stored in event table except the collection one. in the collection table data gets stored in one by one manner like if I check 2 items in collection, it will generate 2 ids with same event_id and 2 collection_ids.

There is problem in update, when i try to update the code, it gives me error as

BadMethodCallException in Macroable.php line 81: Method update does not exist.

Update method is:

        public function update(EventRequest $request, $id)
    {
        $event = Event::findOrFail($id);
        $input = $request->all();
        $input['days_of_week'] = serialize(Input::get('days_of_week'));
        $query = $event->update($input);
        $checkbox_selection = Input::get('agree');
        $choosen_checkbox = $id;
        $collection_event = EventCollection::where('event_id',$choosen_checkbox)->get();
//        return $collection_event;
        if (!is_null($checkbox_selection)) {
            foreach ($checkbox_selection as $collection) {
//                $collection_id =  $id;
                foreach($collection_event as $k){
//                    return $k;
                    if($k->event_id == $choosen_checkbox){
                        $data = $request->all();
                        $data['event_id']= $choosen_checkbox;
                        $data['collection_id'] = $collection;
                        $collection_event->update($data);
                    }
                }

            }
        }

My store method is:

    public function store(Request $request)
    {

        $checkbox = Input::get('days_of_week');
        $checkbox_selection = Input::get('agree');
//        return $checkbox_collection;
        $input = $request->all();
        $input['days_of_week'] = serialize($checkbox);
        $query =  Event::create($input);
        $event_id = $query->id;
        $pro_id = $query->provider_org_id;
        /*For the checkbox selection, if they are multiple store each separately*/
        if (!is_null($checkbox_selection)) {
            foreach ($checkbox_selection as $collection) {
                $collection_id =  $query->id;
                if($collection_id){
                    $data = $request->all();
                    $data['event_id']= $collection_id;
                    $data['collection_id'] = $collection;
                    $create_collection = EventCollection::create($data);
                }
            }
        }
        return view('event.pic_upload',compact('event_id','pro_id'));
    }

Store method works properly! Can someone tell where i am doing wrong in update method?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire