Friday, March 10, 2017

FatalThrowableError in Grammar.php line 135: Laravel 5.4

what i am doing wrong?? Type error: Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array, integer given, called in C:\xampp\htdocs\wanderfoo\vendor\laravel\framework\src\Illuminate\Database\Query\Grammars\Grammar.php on line 681

public function createEvent(Request $request){

    $userid=Auth::user()->id;
    $arr=collect($request->input('sch-title'));


    $data = User::findOrFail(Auth::user()->id);
    if (!empty($data)) {

        //$arr=$request->input('sch-title');
        //dd($arr);
        $days=$request->input('days');
        $this->validate($request , [
            'title'           => 'required',
            'description'     => 'required',
            'firstDate'       => 'required',
            'secondDate'      => 'required',
            'days'            => 'required',
            'location'        => 'required',
            'event-img'       => 'image|mimes:jpeg,png,jpg,gif',
            'sch-title'       =>'required',
            'sch-desc'       =>'required',
            'sch-e'       =>'required',
            'sch-s'       =>'required',
        ]);

        if ($request->hasFile('event-img')) {
            $image = $request->file('event-img');
            $extension = $image->getClientOriginalExtension();
            $filename = md5(str_shuffle(time())) . md5(time()) . '.' . $extension;
            $path = public_path('images/event');
            $image->move($path, $filename);
            $request->request->add([
                'event_img' => $filename,

            ]);

        }
        $request->request->add(['user_id'=>$userid]);
        $eventData = Event::create($request->except(['_token', 'submit', 'tags','sch-e','sch-s','sch-title','sch-desc','event-img']));
        $eventId=$eventData->id;
        //dd($asd);


        if(isset($eventId)){
            for($i=0; $i<$days;$i++){
                $request->request->add(['user_id'=>$userid]);
                $request->request->add(['event_id'=>$eventId]);
                $dayPostData = Day::create($request->except(['_token', 'submit', 'title','description','firstDate','secondDate', 'days','location','tags','event-img','event_img','sch-e','sch-s','sch-title','sch-desc']));
                $dayId=$dayPostData->id;
                //dd($dayId);
                $countSchedules=count($arr[$i]);
                for ($j=0;  $j < $countSchedules; $j++){

                    $request->request->add(['user_id'=>$userid]);
                    $request->request->add(['event_id'=>$eventId]);
                    $request->request->add(['day_id'=>$dayId]);
                    $scheduleData = DaySchedule::create($request->except(['_token', 'submit', 'title','description','firstDate','secondDate' ,'days','location','tags','event-img','event_img']));

                }

            }

        }


        return back()->with('msg', ' Event Create Successfully..!');

    }

}

Route:

   Route::post('create_event','PostController@createEvent');

Error occurred when include the following part:

$countSchedules=count($arr[$i]);
                for ($j=0;  $j < $countSchedules; $j++){

                    $request->request->add(['user_id'=>$userid]);
                    $request->request->add(['event_id'=>$eventId]);
                    $request->request->add(['day_id'=>$dayId]);
                    $scheduleData = DaySchedule::create($request->except(['_token', 'submit', 'title','description','firstDate','secondDate' ,'days','location','tags','event-img','event_img']));

                }



via Jamal Ahmad

Advertisement