hasen39
285
10
Laravel

laravel scout returns empty

Posted 2 months ago by hasen39

my model

<?php

namespace App\Organization;

use Illuminate\Database\Eloquent\Model;
use Laravel\Scout\Searchable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use App\ExamTaker\Answer;

class ExamTaker extends Authenticatable
{   use Searchable;
    protected $guards = "exam_taker";

    protected $table="exam_taker";
    protected $primaryKey="username";
    protected $keyType="string";
    public $incrementing=false;

    protected $hidden=[
      'password',
      'username',
      'exam_code',
  
    ];
  
    public function Answer(){
       return $this->hasMany(Answer::class,'username','username')->whereColumn('answer','correct');
    }

    public function getScoutKey()
    {
        return $this->username;
    }
  


    
}


and my controller

<?php

namespace App\Http\Controllers\Organization;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Organization\ExamTaker;

class SerachingController extends Controller
{
    public function search_exam_taker(Request $request){
       $request->validate([
        'search' => 'string|required',
       ]);

       

       $error = ['errors'=>'result not found'];
        // dd($request->get('search'));
       $result = ExamTaker::search($request->get('search'))->get();
        return $result;
       if ($result->count()>0) {
          return $result;
       }

       return $error;
    }
}



i asked it before but no one solve please any one

Please sign in or create an account to participate in this conversation.