php - laravel - Call to a member function request() on string

What I am currently doing is trying to implement the search functionality to my project. And right now, for the pagination, I want it to display the search result and onto the next pages. But I encountered an error that I am not sure what causing it.

Blade

{{ $posts->appends(['search'->request()->query('search')])->links() }}

Controller

public function index()
    {
        $search = request()->query('search');
        
        if ($search){
            $posts = Post::where('title', 'LIKE', "%{$search}%")->simplePaginate(3);
        } else {
            $posts = Post::paginate(3);
        }
        
        $events = Event::latest()->get();

        // Pass Post Collection to view
        return view('posts.index', compact('posts', 'events'));
    }

Answer

Solution:

change code like this

{{ $posts->appends(['search' => request()->query('search')])->links() }}

Source