Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to pass a Static value with search results in a Laravel Controller

I have the following method defined in my controller. I want to pass the value of $title along with the search results so that it can be displayed at the top of the blade page, but I am unsure how to do it.

    public function index_sog(Request $request)
    {
        $title = 'Standard Operating Guideline';

            return view('knowledgebase.index', [
                'kbase' => Knowledgebase::orderBy('category', 'asc')
                ->filter(request(['tags', 'search']))
                ->where('type','SOG')
                ->paginate(20),
                'search' => $request->input('search')
            ]);
    }

My output…

<h4>{{//TITLE SHOULD GO HERE//}}</h4>
        <div class="panel-container show">
            <div class="panel-content">
                
                @foreach ($kbase->groupBy('category') as $category => $group)
                <table class="table">
                        <tr>
                            <th colspan="3" class="text-center bg-fusion-50"><strong>{{ $category }} <strong></th>
                        </tr>
                        @foreach ($group as $kb)
                            <tr>
                                <td>{{ $kb->title }}</td>
                                <td></td>
                                <td></td>
                            </tr>
                        @endforeach
                </table>
                @endforeach
            </div>
        </div>

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

ADD on return variables. And you can use on blade like {{ $title }}

> return view('knowledgebase.index', [
>                 'kbase' => Knowledgebase::orderBy('category', 'asc')
>                 ->filter(request(['tags', 'search']))
>                 ->where('type','SOG')
>                 ->paginate(20),
>                 'search' => $request->input('search'),
>                 'title' => $title
>             ]);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading