-2

any one guide me how to do this

this is input view, enter image description here

output come in view like this with student data enter image description here

my model Student.php

<?php

namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Database\Eloquent\Model;

class Student extends Model
{
    protected $table = 'student_lists';
    // protected $dates = ['certificate_issue_date','date_of_join','date_of_completion','dob'];

    protected $fillable = ['student_name', 'student_registration_id', 'date_of_join', 'student_phone_no', 'student_photo' ];

}

my route

Route::any ( '/search', function () {
    $q = Input::get ( 'q' );
    $user = Student::where ( 'student_registration_id', 'LIKE', '%' . $q . '%' )->orWhere ( 'email', 'LIKE', '%' . $q . '%' )->get ();
    if (count ( $user ) > 0)
        return view ( 'my-search' )->withDetails ( $user )->withQuery ( $q );
       else
         return view ( 'my-search' )->withMessage ( 'No Details found.  Try to search again !' );
} );

my view

{{ csrf_field() }} @if(isset($details))

The Search results for your query are :

Sample User details

Name Email Photo @foreach($details as $user) {{$user->name}} {{$user->email}} student_photo }}" class="img-circle" width="90" /> @endforeach @elseif(isset($message))

{{$message}}

@endif
user12380208
  • 519
  • 7
  • 26

1 Answers1

0

Put this is your model Students.php

public static function search(string $search) {
    $columns = ["student_registration_id", "date_of_join"];

    // If the search is empty, return everything
    if (empty(trim($search))) {
      return static::select($columns)->get();
    }
    // If the search contains something, we perform the fuzzy search 
    else {
      $fuzzySearch = implode("%", str_split($search)); // e.g. test -> t%e%s%t
      $fuzzySearch = "%$fuzzySearch%"; // test -> %t%e%s%t%s%

      return static::select($columns)->where("name", "like", $fuzzySearch)->get();
    }
}

Create one controller and paste this code there:

class SearchController extends Controller {
    public function type(Request $request, $search = "") {
      $search = Input::get('q');
      $user =  Student::search($search);

      return view ('my-search',compact($user));
    }
  }

And your route for this should be:

Route::get( '/search', 'SearchController@type');

Hopefully it'll help you

Khalid Khan
  • 3,017
  • 1
  • 11
  • 27