laravel 5.2 - Trying to get property of non-object, exactly i don't this error -
this controller questions , it's category, should displayed users category, category user select must displayed , count questions users answered ,but when want apply section mentioned error displaying don't error
contrller
public function start() { $category = db::table('question_type')->get(); return view('frontend.start',compact('category')); } public function questionscategory(request $request) { $ctid = $request->input('selected-category'); $langid = $request->input('language'); $time = db::table('question_type')->select('time')->where('type_id', $ctid)->first(); $hours = 0; $minutes = 0; $scs = 0; if ($ctid == 1) { if ($time->time > 60) { $hours = 1; $minutes = $time->time- 60; } else { $hours = 0; $minutes = $time->time; } } elseif ($ctid == 2) { if ($time->time > 60) { $hours = 1; $minutes = $time->time- 60; } else { $hours = 0; $minutes = $time->time; } } elseif ($ctid == 3) { if ($time->time > 60) { $hours = 1; $minutes = $time->time- 60; } else { $hours = 0; $minutes = $time->time; } } elseif($ctid == 4) { if ($time->time > 60) { $hours = 1; $minutes = $time->time- 60; } else { $hours = 0; $minutes = $time->time; } } $category = db::table('question_type')->select('type_name')->where('type_id',$ctid)->first(); $questions = db::table('questions')->join('question_type','question_type.type_id','=','questions.type_id') ->select('questions.*','question_type.*') ->where('questions.lang_id',$langid)->where('questions.type_id',$ctid)->limit(43)->get(); $cat_done = db::table('student_answers') ->select('student_answers.*')->first(); if ($cat_done->student_id == auth()->user()->id && $cat_done->question_id >=42) { dd("you have done category"); } //->inrandomorder() return view('frontend.category-questions',compact('category','questions','hours','minutes','ctid','langid')); } public function categoryover() { return view('frontend.time-over')->render(); } public function darianswers(request $request) { $catid = $request->input('category'); $lang = $request->input('language'); //dd($request->all()); $questions = db::table('questions')->join('question_type','question_type.type_id','=','questions.type_id') ->select('questions.*','question_type.*') ->where('questions.lang_id',$lang) ->where('questions.type_id',$catid)->limit(43)->get(); ($i=1; $i<=count($questions); $i++) { $qid = $request->input('qid'.$i); $answer = $request->input('answer'.$i); $status = db::table('student_answers')->insert([ 'student_id' => auth()->user()->id, 'question_id' => $qid, 'st_answer' => $answer ]); } if ($status != 0) { if ($catid == 4) { return redirect('/student/choices'); } else { return redirect('/start')->with('success','این بخش موفقانه تمام شد!'); } } else { return back()->with('error','خطا رخ داده، دوباره سعی نمایید.'); } } public function studentchoices() { $provinces = db::table('provinces')->select('*')->get(); $unvs = db::table('university')->select('*')->get(); $faculty = db::table('faculty')->select('*')->get(); $depart = db::table('department')->select('*')->get(); return view('student.choices',compact('provinces','unvs','faculty','depart')); } } routes: oute::get('/', 'pagescontroller@index');`enter code here` route::get('start','pagescontroller@start');`enter code here` //end of student routes // user routes route::get('student/register', 'studentcontroller@getregister'); route::post('student/store', 'studentcontroller@postregister'); route::post('filter/districts','studentcontroller@filterdistricts'); //end of user route route::post('question/category','studentcontroller@questionscategory'); route::get('question/category','studentcontroller@categoryover'); route::post('question/answer','studentcontroller@darianswers'); route::get('student/choices','studentcontroller@studentchoices');
Comments
Post a Comment