dimanche 3 septembre 2023

Laravel SearchDropdown - to implement SearchDropdown in my laravel project

i want to implement SearchDropdown in my laravel project so i have in issue that i do not have search results this is my SearchDropdown.php file `<?php namespace App\Livewire;

use Livewire\Component; use Illuminate\Support\Facades\Http;

class SearchDropdown extends Component { public $search = '';

public function render()
{
     $searchResults = [];

    if (strlen($this->search) >= 2 )
    // if (!empty($this->search))
    {
        $response = Http::withToken(config('services.tmdb.token'))
            ->get('https://api.themoviedb.org/3/search/movie', [
                'query' => $this->search,
            ]);

        if ($response->ok()) {
            $searchResults = $response->json()['results'];
        }
    }

    return view('livewire.search-dropdown', [
        'searchResults' => collect($searchResults)->take(7),
    ]);
}

}`

and this is my component `

<div wire:loading class="spinner top-0 right-0 mr-4 mt-3"></div>

@if (strlen($search) >= 2)
    <div class="absolute bg-gray-800 text-sm rounded w-64 mt-4">
        @if ($searchResults->count() > 0)
            <ul>
                @foreach ($searchResults as $result)
                    <li class="border-b border-gray-700">
                        <a href="" class="block hover:bg-gray-700 px-3 py-3 items-center transition ease-in-out duration-150">
                            @if ($result['poster_path'])
                            <img src="https://image.tmdb.org/t/p/w92/" alt="poster" class="w-8">
                        @else
                            <img src="https://via.placeholder.com/50x75" alt="poster" class="w-8">
                        @endif
                        <span class="ml-4"></span>
                    </a>
                    </li>
                @endforeach

            </ul>
        @else
            <div class="px-3 py-3">No results for ""</div>
        @endif
    </div>
@endif
`

i try to implement SearchDropdown in my laravel project to wite a movie name in the SearchDropdown but i have no resualts



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire