Support the ongoing development of Laravel.io →
Eloquent Blade Forms

Hi. I have the following relations in the app I am working on. I have a Bank model or Component as well as Bank Accounts and Currencies. The relation is very simple here. We can have several banks and each bank has multiple bank accounts. Each account has one currency type. Currencies are created with just the name, code and enabled fields (and the classic id and timestamp field). My question is related to the currency type. For a bank account this is not like an ownership type of relationship but more like a configuration parameter. Still, a bank account will have one currency type (belongs to) and a currency could have many bank accounts associated to it. So, even that for me this is a configuration parameter rather than a relationship, I have created the eloquent relationship. Is this the right way to go here?

Also, when I create a new bank account, I need to get all the currency types in order to populate the select component in the blade file. For this, even that the relationship between bankaccount and currency exist (on thinker I can get App\Model\backend\bankaccount::find(1)->currency and App\Model\backend\currency::find(2)->bankaccounts) there is no way to get all the currency types configured (populated in the DB). So in the bankaccount controller in the create method, I do the following: ... $currencies = \App\Model\backend\currency::all(); return view('backend.bankaccount.create',compact('currencies'));

Then on the create.blade.php I simply do:

<select class="form-control" id="currency_code" name="currency_code" placeholder="Moneda" type="text"> @foreach ($currencies as $currency) <option>{{ $currency->code }}</option> @endforeach </select>

Is this the way to do so because even that I have the relationship, when creating a new bank account, trough that relationship I can not get all the available currencies configured from the bankaccount model right?

Regards,

Omar

Last updated 3 years ago.
0

i think you should summary

0

hi Junie, could you please explain what do you mean by summary?

Regards, Omar

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Omar Pulido opulido Joined 10 Sep 2018

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.