dimanche 27 janvier 2019

Too few arguments to function laravel 5.7

I want to query to db using two parameter which will be optional, so I defined a route as:

web.php

Route::get('question/{subject?}/{sbj_type?}', 'QuestionController@index')->name('question.index');

After that I made a function in QuestionController.php as:

public function index($subject = null, $sbj_type = null)
{
    $questions;
    if (!$subject) {
        dd($subject);
        if (!$sbj_type) {
            $questions = Question::where(['subject_id' => $subject, 'sbj_type_id' => $sbj_type])->get();
        }
        else {
            $questions = Question::where(['subject_id' => $subject])->get();
        }
    }
}

After that I inserted this URL as http://localhost/digitalinvigilator/question?subject=1 but I am getting null every time.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire