'The page shows data before i click the search button Laravel

Im new on laravel im working on a project. the problem is when i enter the page all the data is there and i only want them to be shown when i search. when i click search it's working i can only see one

so the problem is how can i block the data to be shown before i search.

thank you. here's my code

public function Newtask(Request $request){
    // $clients = Client::all();
    // return view('receptions.newtask',compact('clients'));
    $recherche = $request->get('ClientSearchbylastname');
    $clients =  Client::where([['ClientLastName','LIKE','%'.$recherche.'%']])->get();

    return view('receptions.newtask',compact('clients'));

}


Solution 1:[1]

If not $recherche set $clients as an empty array.

$clients = $recherche ? Cliente::where([['ClientLastName', 'LIKE', '%'.$recherche.'%']])->get() : [];

PD: Next time, paste code instead of image.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Pnia