Laravel 8 Two Models get Data Example

Hello Dev,

At the moment, i we’ll present you laravel eight two fashions get knowledge instance. This text gives you easy instance of laravel eight two fashions get knowledge instance. you’ll study laravel eight two fashions get knowledge instance.

We have now two examples to gate the fashions knowledge, The primary one is to make use of two foreach loops within the Blade file, and the second is to Merge these fashions within the controller and get knowledge utilizing solely a single variable. this Instance you should use with laravel 6, laravel 7 and laravel eight model as nicely.

So let’s observe few step to create instance of laravel eight two fashions get knowledge instance.

Instance:


<?php

namespace AppHttpControllers;

use IlluminateHttpRequest;
use AppModelsParentuser;
use AppModelsStudent;

class TestController extends Controller
{
    /**
     * Show an inventory of the useful resource.
     *
     * @return IlluminateHttpResponse
     */
    public operate index()
    {
        $mother or father = Parentuser::get();
        $scholar = Pupil::get();
        
        $knowledge = $parent->concat($scholar);
        dd($knowledge);
    }

}

Output:


IlluminateDatabaseEloquentCollection {#281 ?

  #gadgets: array:4 [?

    0 => AppModelsParentuser {#297 ?}

    1 => AppModelsParentuser {#298 ?}

    2 => AppModelsStudent {#1015 ?}

    3 => AppModelsStudent {#1014 ?}

  ]

}

Komentar

Postingan populer dari blog ini

PHP 8 Multiple Select Dropdown Example

Laravel 8 Get HTTP Hostname

JQuery Drag And Drop Menu Example