mercredi 4 mai 2016

Laravel 5.1 & Typeahead.js

js setup in Laravel 5.1 project doesn't work. I can't understand how i can pass my input text so i can compare the texts.

Here is my Controller:

public function getStudentDataTutorschool(){

            if(Auth::check()) {
                $user = Auth::user();
                $user_id = $user->getTutorschoolId(Auth::user()->id);

                $tutorschool = Tutorschool::find($user_id)->first();

                $student_ids = array();

                $students = array();

                $results = array();

                $finals = array();

                $queries = DB::table('student_tutorschool')
                    ->select('student_id')
                    ->where('tutorschool_id', '=', $tutorschool->user_id)
                    ->get();

                //Adds in the student_ids the USER_ID
                foreach ($queries as $query) {
                    $student_ids[] = ['id' => $query->student_id];
                }

                //Αdds in the $students array the id of student
                foreach ($student_ids as $student_id) {

                    $user = User::find($student_id)->first();

                    $studentdatas = $user->students;

                    foreach ($studentdatas as $studentdata) {
                        $students[] = ['id' => $studentdata->id];
                    }
                }
                $get = Input::get('search');

                foreach ($students as $student) {
                    $thestudent = Student::find($student)->first();
                    $results[] = ['name' => $thestudent->name, 'surname' => $thestudent->surname, 'user_id' => $thestudent->user_id];

                }
                return response()->json($results);

            }else{
                return redirect('403');
            }
        }

Here is my Form:

<form method="get">
    <div class="col-md-12">
        <input name="search"  class="scholio-input typeahead" type="text" placeholder="Μαθητές">
    </div>
</form>

Here is my Root:

Route::get('tutorchool/getstudentdatadashboardsearch','SearchController@getStudentDataTutorschool');

Here is my localhost/tutorchool/getstudentdatadashboardsearch link return

enter image description here



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire