Load Relationships table
cherif-bayo opened this issue · 3 comments
Hey there ,
I'm using laravel voyager as admin package and spatie/laravel-searchable as search engine.
i'm building app with 5 languages so i need to make search title for these languages.
In my Tutorial Model
public function getSearchResult(): SearchResult
{
$url = route('tutorial', $this->slug);
return new \Spatie\Searchable\SearchResult(
$this,
$this->title,
$url
);
}
In My Search Controller :
public function search(Request $request)
{
$searchterm = $request->input('query');
$searchResults = (new Search())
->registerModel(Tutorial::class, 'title')
->perform($searchterm);
return view('search.show', compact('searchResults', 'searchterm'));
}
My View:
@foreach($searchResults->groupByType() as $type => $modelSearchResults)
<h2>{{ ucfirst($type) }}</h2>
@foreach($modelSearchResults as $searchResult)
<ul>
<li><a href="{{ $searchResult->url }}">{{ $searchResult->title }}</a></li>
</ul>
@endforeach
@endforeach
And my form input :
<form action="{{ route('search') }}" method="GET">
@csrf
<input class="form-control searchBar" type="text" placeholder="
{{__('home.search_placeholder')}}"
aria-label="Search" name="query" value="{{ request($query ?? '') }}" />
</form>
spatie laravel-searchable only find English(default language) title and nothing for the other languages.
I'm maybe missing something .
Thank you for your help
I don't know how your models are set up to handle different languages. Is it one model per language or is the title
field a json field with multiple languages?
Hey @AlexVanderbist ,
Thanks for your unswer .
I only have one translation table
public function up()
{
Schema::create('translations', function (Blueprint $table) {
$table->increments('id');
$table->string('table_name');
$table->string('column_name');
$table->integer('foreign_key')->unsigned();
$table->string('locale');
$table->text('value');
$table->unique(['table_name', 'column_name', 'foreign_key', 'locale']);
$table->timestamps();
});
}
Do you have an idea of how to search with spatie ?
thank you
Dear contributor,
because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it.