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

Providing multiple variables in return view

I have an overview site with a filter canton on top. The user can filer for location and department.

The code of the controller looks like this:

public function index(Request $request)
    {


        $posts = Post::orderBy('titel')
            ->get();

        $standorts = Standort::get();

        $abteilungs = Abteilung::get();

        if ($request->filled('s')) {
            $query = strtolower($request->get('s'));
            $posts = $posts->filter(function ($post) use ($query) {
                if (Str::contains(strtolower($post->Titel), $query)) {
                    return true;
                }
                return false;
            });

        }
        return view('posts.overview', ['posts' => $posts], ['standorts' => $standorts]);
    }

I need to provide the $abteilungs = Abteilung::get(); aswell, but when I return it like this:

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

return view('posts.overview', ['posts' => $posts], ['standorts' => $standorts], ['abteilungs' => $abteilungs]);

The last part in the brackets is greyed out and I can’t access it.

In the blade file I access them like this:

<div class="text-left mb-4 h-12">
                    <select name="standort" id="standort" class="h-full w-full flex justify-center bg-white bg-opacity-95 rounded focus:ring-2 border border-gray-300 focus:border-indigo-500 text-base
                                outline-none text-gray-700 text-lg text-center leading-8">

                        <option selected="true" disabled="disabled">Standort</option>
                        @foreach($standorts as $standort)
                            <option value="{{ $standort->standort_name }}">{{ $standort->standort_name }}</option>
                        @endforeach
                    </select>
                </div>


                <button class="col-start-4 col-end-4 w-11/12 text-white text-2xl px-4 py-3 rounded text-base font-medium
                                bg-gradient-to-r from-green-400 to-blue-500 float-right shadow transition duration-500 ease-in-out transform hover:-translate-y-1 hover:scale-100">
                    Suchen
                </button>
            </form>


            @foreach($posts as $post)
                <div
                    class="p-10 grid-cols-3 grid-rows-3 gap-4 shadow-2xl mb-10 bg-gradient-to-r from-green-400 to-blue-500 border-solid border-2 border-black rounded-lg">


                    <!--Card 1-->
                    <a href="{{ route('select', $post->Stellenanzeigen_ID) }}">
                        <div
                            class="overflow-hidden row-span-3 bg-gray-100 shadow-2xl border-solid border-2 border-gray-500 rounded-lg">
                            <div class="pt-2 pl-6 mt-3"> {{ $post->Titel }}</div>
                            <div class="px-6 py-4 mt-2 ring-4 ring-opacity-90">
                                <button type="submit" class="text-white px-4 py-3 rounded text-base font-medium
                                bg-gradient-to-r from-green-400 to-blue-500 float-right shadow transition
                                duration-500 ease-in-out transform hover:-translate-y-1 hover:scale-100">Direkt
                                    bewerben!
                                </button>


                                <div class="pt-2 pl-4 font-medium text-base font-bold font-serif">
                                    Standort: {{ $post->Standort }}</div>

                                <div class="pt-2 pl-4 font-medium text-base font-bold font-serif">
                                    Kontakt: {{ $post->Kontakt }}</div>
                                <button type="submit" class="text-white px-4 py-3 rounded text-base font-medium
                                bg-gradient-to-r from-green-400 to-blue-500 float-right shadow transition duration-500 ease-in-out transform hover:-translate-y-1 hover:scale-100">
                                    Details!
                                </button>
                                <div class="pt-2 pl-4 font-medium text-base font-bold font-serif">
                                    Startdatum: {{ $post->startdate }}</div>
                                <div class="pt-2 pl-4 font-medium text-base font-bold font-serif">
                                    Enddatum: {{ $post->enddate }}</div>

                                <div class="px-6 pt-4 pb-2"></div>
                            </div>
                        </div>
                    </a>
                </div>
            @endforeach

For the third part in the return statement I have this code:

<div class="text-left mb-4 h-12">
                    <select name="abteilung" id="abteilung" class="h-full w-full flex justify-center bg-white bg-opacity-95 rounded focus:ring-2 border border-gray-300 focus:border-indigo-500 text-base
                                outline-none text-gray-700 text-lg text-center leading-8">

                        <option selected="true" disabled="disabled">Abteilung</option>
                        @foreach($abteilungs as $abteilung)
                            <option value="{{ $abteilung->abteilung_name }}">{{ $abteilung->abteilung_name }}</option>
                        @endforeach
                    </select>
                </div>

Is there a way to make this work or is the return view limited to two parameters?

>Solution :

You can also try in this way

    $data = [
            'posts' => $posts, 
            'standorts' => $standorts, 
            'abteilungs' => $abteilungs,
        ];
return view('posts.overview')->with($data);

Or,

return view('post.overview',compact('posts','standorts','abteilungs'));
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