Reputation: 604
I'm sorry if this is a newbie question.
I am using tntseach a s my laravel-scout driver & serach sytem in my app.
It is currently working well but the only problem is the format in which I recieve the results.
If i search for "video" ie http://localhost:8000/search?q=video
i get ["Video post"] as the result.It is correct but I want the result to be just
Video post` ie omitting the brackets and double quotes.
And if i serach for "posts"
I get:
["My first post","Video post","Posts"]
I want it to be:
My first posts
Video post
posts
I tried json_decode()
but that didn't work,probably beacuse it is not true json.
This is my SearchController.php:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\User;
use App\Post;
use TeamTNT\TNTSearch\TNTSearch;
class SearchController extends Controller
{
/**
* Display the main dashboard page.
*
* @return \Illuminate\Http\Response
*/
public function search(Request $request){
$posts = Post::search($request->input('q'))->get('titlek')->pluck('title');
return view('search.index', compact('posts'));
}
}
This is my search.blade.php:
@extends('layouts.base')
@section('pageTitle', 'Login')
@section('content')
Your search results are:<br><br>
{{ $posts }}
@endsection
Upvotes: 0
Views: 450
Reputation: 4499
Since the result is an array, you need to loop through the array and show each
@section('content')
Your search results are:<br>
@foreach($posts as $post)
{{ $post }}<br>
@endforeach
@endsection
Upvotes: 1