samedi 18 juillet 2020

Laravel issue with form select [SOLVED]

Originally I had

and to get the data I use

Quote::get()->pluck('name', 'id');

Which works but I wanted to remove the name field to opt for a dynamic field.

I need the form select in my view to provide a name/text that is not part of the model.

Model

-id
-name
-date
-status
...

I removed the name field as it is no longer required, and now have the below model

-id
-date
-status
...

So the select form now wont work, what I want to display is the DATE + status in the form::select.

eg: $this->date . ' ' . $this->status;

Something like this would be useful

Quote::get()->pluck('dynamicName()', 'id');

Then I could add the dynamicName() function in the model. so the model should look like

Model

-id
-date
-status
- function dynamicName()
{
   return $this->date . ' ' . $this->status;
}
...

is this possible ?

I tried

Quote::get()->pluck('dynamicName()', 'id');

However it yeilded a blank entry

UPDATE

I solved this by using a map function :

$quotes = Quote::get();
$quotes = $quotes->map(function ($quote) {
  return $quote->dynamicName() . $quote->status;
});


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3fG0gjx
via IFTTT

Aucun commentaire:

Enregistrer un commentaire