Создание поиска постов Laravel [закрыто]Php

Кемеровские программисты php общаются здесь
Anonymous
Создание поиска постов Laravel [закрыто]

Сообщение Anonymous »

Я создаю простую форму поиска своих постов. Он возвращает посты, но игнорирует термин поиска, и он просто отображает все сообщения. Я вижу правильный термин в URL. Вот функция в postcontroller
public function search(Request $request) {
// Get the search value from the request
$search = $request->input('search');

// Search in the title and body columns from the posts table
$posts = Post::query()
->where('title', 'LIKE', "%{$search}%")
->orWhere('body', 'LIKE', "%{$search}%")
->take(3)
->get();

// Return the search view with the resluts compacted
return view('search-results', compact('posts'));
}
< /code>
Вот результаты поиска < /p>
if($posts->isNotEmpty())
@foreach ($posts as $post)

{{ $post->title }}
Изображение
image }}">

@endforeach
@else

No posts found

@endif
< /code>
Это форма < /p>


Search

< /code>
Редактировать изменилось на: < /p>
public function search(Request $request) {
// Get the search value from the request
$search = $request->input('query')

// Search in the title and body columns from the posts table
$posts = Post::query()
->where('title', 'LIKE', "%{$search}%")
->orWhere('body', 'LIKE', "%{$search}%")
->take(3)
->get();

// Return the search view with the resluts compacted
return view('search-results', compact('posts'));
}
Changed to $request->input('query')


Подробнее здесь: https://stackoverflow.com/questions/795 ... h-of-posts

Вернуться в «Php»