nicolaslopezj / searchable

A php trait to search laravel models
MIT License
2.01k stars 291 forks source link

No search results generated #140

Open ronaklodaya opened 7 years ago

ronaklodaya commented 7 years ago

Hey, I am new to laravel!

I was trying to implement a searchable function using Searchable, a search trait for Laravel by nicolaslopezj, i have used the following code. But it doesn't seem to work if there are only two records in the database it show the records but if more then two records it doesn't search.

Please help me out!

Model: Contact.php `namespace App;

use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use Nicolaslopezj\Searchable\SearchableTrait;

class Contact extends Model { use SearchableTrait;

    protected $searchable = [
    'columns' => [
        'contacts.first_name' => 10,
        'contacts.last_name' => 10,
    ]];

} Controller: SearchController

namespace App\Http\Controllers;

use Illuminate\Http\Request; use Nicolaslopezj\Searchable\SearchableTrait; use View; use App\Contact; use App\Tag; use App\Project; use App\User; //use Illuminate\Support\Facades\Input;

class SearchController extends Controller { public function findAgent(Request $request) { return Contact::search($request->get('cname'))->get(); }

     public function agentPrefetch()
    {
       $all_contacts= Contact::All();
       return \Response::json($all_contacts);
    }

}`

View: show.blade.php

`

` Routes: `Route::get('find_contact', 'SearchController@findContact'); Route::get('find_contact_all', 'SearchController@contactPrefetch');` Waiting for solution!!!
manaseepm commented 6 years ago

Any update on this Ronak? I seem to facing the same issue.

ronaklodaya commented 6 years ago

@manaseepm I had placed the resource links wrong so the plugin did not work properly. But after placing them its works fine. If you facing same problem, Send me your codes. Lets see what's wrong.