LAravel 5.4: Response from controller to blade by Ajax (laravel, json_encode() expects parameter 2 to be integer, object given)

LAravel 5.4: Response from controller to blade by Ajax (laravel, json_encode() expects parameter 2 to be integer, object given)

I want to response the data from controller to AJAX as array, but it keep showing this error:

I want to response the data from controller to AJAX as array, but it keep showing this error:

json_encode() expects parameter 2 to be integer, object given

the following is my code:

 function get_show(Request $request)
    {
        $id = $request->input('id');
        $leads = Lead::find($id);

    $leads_attendances = DB::table('event_attendances')
        ->leftJoin('leads', 'leads.id', '=', 'event_attendances.lead_id')
        ->leftJoin('groups', 'groups.id', '=', 'event_attendances.group_id')
        ->select('groups.name as event_name', 'leads.name as name', 'leads.company_name', 'event_attendances.attend as attend_status')
        ->where('event_attendances.lead_id', '=', $id)
        ->get()->toArray();

    $output = array(
        'id' => $id,
        'country' => $leads->country,
        'company_name' => $leads->company_name,
        'lead_stage' => $leads->lead_stage
    );

    echo json_encode($output,$leads_attendances);
}

The first array ($output) passed and working well with Ajax, but the second collection showing that error. I still need to pass more than these collection, any help how to pass it and make it work with Ajax?

Thank you

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

jQuery ajax get request method example

### jQuery Ajax Get Request Method Example This article is originally published at [https://www.tutsmake.com/jquery-api-ajax-get-method-example/](https://www.tutsmake.com/jquery-api-ajax-get-method-example/...

Laravel 6 Ajax Request Tutorial

In this post, you'll learn how to write jquery ajax form submit in Laravel 6. We will write Jquery Ajax post request Laravel 6. We will protect csrf token with Ajax request in Laravel 6. I will give you very simple example of Laravel 6 Ajax post request tutorial.

How to use Ajax form validation in Laravel 6

In this tutorial, I would like to guide how to use Aajax form validation in Laravel 6. We will use Laravel 6 validation with ajax post request. We will gives errors response and display it on front side using Ajax Laravel 6