mercredi 20 mars 2019

Laravel Backpack how to get selected the drop down option from database

I'm developing a backend admin panel through Laravel 5 BackPack. Here, in agent crud, I want to show the option in the drop down box which will come from the database. The value which will come from the db table (table name: agent_availability) is in a relational file of agent (table name: users) db table. There is a relationship between the users table and agent_availability and the field responsible for this is agent_id. agent_id is the foreign key in agent_availability table.

To get the option selected of the drop down, I did the follows:

  1. Created a repository and a model named "AgentAvailabilityRepository.php" and "AgentAvailability.php" respectively.
  2. In the AgentCrudController, I use the repository as like: use App\Repositories\AgentAvailabilityRepository;
  3. Declared the same in the constructor like

public function __construct(AgentAvailabilityRepository $agentavailabilityRepository)

In the add fields I did the follows:

$this->crud->addFields([
['name'  => 'sunday',
'label' => trans('Sunday'),                
'type'  => 'select_from_array',
'options' => [0 => 'Open', 1 => 'Closed'],
],
....
....
]);

Now, I don't have any idea how can I call a function from which repository and how to get the option selected for the drop down.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire