Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Getting field value from another table returns a json collection in Laravel

I am using Laravel orchid package and in layout file, I have this function:

 protected function columns(): iterable
    {
        $org = '';
        $employeeDetails = '';
        return [
            TD::make('Userid', __('User Id'))
            ->cantHide()
            ->sort()
            ->filter(Input::make()),
            TD::make($employeeDetails, __('Employee Name'))
            ->filter(Input::make())
            ->render(function(DailyAttendance $attendance) {
                $employeeDetails = Employee::where('employeeCode', $attendance->Userid)->first(['employeeName']);
                
                return $employeeDetails;
                
            })
            ->sort(),
           
        ];
    }

The result is not picking employee name but whole with field name like this:

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

There are 2 tables one which is getting attendance logs based on userid and another table which is storing employee records like name and organizaion based on userid.

How can I only get the employee name using first or get.

I tried get(‘fieldname’) but it is also returning the same result.

>Solution :

You can try remove the initialization of $employeeDetails and pass employeeName as the first argument to TD::make() in the second column definition.
Then in the render() method, you can use pluck('employeeName') instead of first(['employeeName']) to get only the employee name:

 TD::make('employeeName', __('Employee Name'))

and

$employeeDetails = Employee::where('employeeCode', $attendance->Userid)->pluck('employeeName')->first();
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading