mercredi 4 mars 2020

Laravel query two models which are not related and return fields from both

I have 2 models:

  1. Property (fields: prop_id, a, b, c)
  2. OfferDemandmatch (fields: prop_id d, e, f)

Both models have the prop_id column which can must used to join both models. I have a blade view where I do a foreach for matchs collection and I need to have inside each collection item, the fields from Property and OfferDemandmatch model.

This is the code for Match collection sent to balde view

class OfferdemandsmatchsController extends Controller
{
    public function index ($id) {
        $matchs = OfferDemand::findOrFail($id)->offerdemandsmatchs;
        return view('pages.processes.offerdemand.matchs.index', compact('matchs'));

    }
}

This is the code in blade view

<div class="row">
  @foreach($matchs as $match)
      @component('pages.processes.offerdemand.matchs.matchbox')
      @endcomponent
  @endforeach
</div>

I will need to use Property and Match fields in each foreach iteration in blade view. So, my collection items must contain fields: prop_id, a, b, c, d, e, f

How can I achieve this?

Regards



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire