Support the ongoing development of Laravel.io →
Routing Laravel Requests

I have this code of my CRM which is working fine, but the drop-down menu is showing the user ID instead of the User name.

Now, I want it to show the username instead:

// LeadController code:

public function massUpdateSalesperson()
{
    $data = request()->all();

    foreach ($data['rows'] as $leadId) {
        $lead = $this->leadRepository->find($leadId);
        $lead->update(['user_id' => Arr::get($data, 'value.value')]);

        Event::dispatch('lead.update.before', $leadId);
    }

    return response()->json([
        'message' => trans('admin::app.response.update-success', ['name' => trans('admin::app.leads.title')])
    ]);
}

and this DataGrid Code:


$this->addMassAction([
    'type'    => 'update',
    'label'   => trans('admin::app.datagrid.update_salesperson'),
    'action'  => route('admin.leads.mass_update_salesperson'),
    'method'  => 'PUT',
    'options' =>$this->getUserDropdownOptions(),
]);

When I do following changes it updates the lead by removing the Salesperson from the column instead of updating with the new one.

LeadDataGrid Code:

public function prepareMassActions()
{
    $stages = [];
    
    foreach ($this->pipeline->stages->toArray() as $stage) {
        $stages[$stage['name']] = $stage['id'];
    }

    $users = User::all();
    $UserName = [];
    
    foreach ($users as $user) {
        $UserName[$user['name']] = $user['id'];
    }
    
    $this->addMassAction([
        'type'   => 'delete',
        'label'  => trans('ui::app.datagrid.delete'),
        'action' => route('admin.leads.mass_delete'),
        'method' => 'PUT',
    ]);
    $this->addMassAction([
        'type'    => 'update',
        'label'   => trans('admin::app.datagrid.update_stage'),
        'action'  => route('admin.leads.mass_update'),
        'method'  => 'PUT',
        'options' => $stages,
    ]);

       //newly added
     $this->addMassAction([
        'type'    => 'update',
        'label'   => trans('admin::app.datagrid.update_salesperson'),
        'action'  => route('admin.leads.mass_update_salesperson'),
        'method'  => 'PUT',
        'options' => $UserName,
    ]);
}

LeadController Code:

public function massUpdateSalesperson()
{
    $data = request()->all();

    foreach ($data['rows'] as $leadId) {
        $lead = $this->leadRepository->find($leadId);
        $lead->update(['leads.users_name' => Arr::get($data, 'value.value')]);
        Event::dispatch('lead.update.before', $leadId);
    }

    return response()->json([
        'message' => trans('admin::app.response.update-success', ['name' => trans('admin::app.leads.title')])
    ]);
}

What is it I am doing wrong?ll

0
moderator

Hello @deenah85

Maybe I did miss it, but what is the code where you show the dropdown?

0

Hello @tvbeek

The drop down menu is the list of mass actions at the datagrid. My issue is not the drop-down itself, but the function of the mass action. it would only update the sales person with the $this->getUserDropdownOptions(), as it shows only numbers, and it will not update with the $UserName where it displays the names.

I am using this open source CRM for reference: https://github.com/krayin/laravel-crm

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Dina S deenah85 Joined 3 Jun 2023

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.