I have a search component and when the user is not on the homepage I’d like to redirect to the homepage. But this redirect doesn’t work. How can I fix that ?
class Search extends Component
{
public $q = '';
public $currentRouteName = '';
protected $updatesQueryString = ['q'];
public function updatedQ ()
{
if ($this->currentRouteName !== 'home') {
return redirect()->route('home', ['q' => $this->q]);
}
$this->emit('search', $this->q);
}
public function mount ()
{
$this->q = request('q', '');
$this->currentRouteName = Route::currentRouteName();
}
public function render()
{
return view('livewire.layout.search');
}
}