声明数组变量在视图中未定义但在laravel 5.7中使用控制器时该怎么办

Here is the code:

    public function chat($id=1){

    Route::view('/chat', 'chat');

    $id = View::make('chat.blade', ['reviewer_id' => Reviewer::findOrFail($id)]);

    $audiences = DB::table('audience')->get();

    $data = [
             'id'=>$id,
             'audiences'=>$audiences,
             'audience_id'=> 2
            ];
    return View::make('chat.blade', ['data'=>$data]);

}

As the code is simple I route to blade view, get data from database, get audience data, initialize data array return data to chat.blade simple code but in view

Undefined variable: data (View: /Users/userinfo/Sites/chat/resources/views/chat.blade.php)

View code:

        <div>
        @foreach($data->audiences as $info->audience)
            {{$info->audience->id}};
        @endforeach
        </div>
        <div>
            <form action="/" method="post">
                <input type="hidden" value={{$reviewer_id}} name="id">
                <input type="hidden" value={{$audience_id}} name="id">
                <input type="text" name="message">
                <input type="submit" value="submit">
            </form>
        </div>



<?php $__currentLoopData = $data->audiences; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $info->audience): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <?php echo e($info->audience->id); ?>;
            <?php endforeach; $__env->popLoop(); $loop = 
$__env->getLastLoop(); 

?>

> undefined variable $data

change $data->audiences to $data['audiences'] in your view. $data is an array not an object

If i do it then i do it like this

public function chat($id = 1){
    Route::view('/chat', 'chat'); // I don't know what that is
    $reviewer_id = Reviewer::findOrFail($id); // or Reviewer::find($id); 
    //I Update this little bit : $audiences = DB::table('audience')->get();
    $audiences = Audience::all();
    $audience_id = 2 ;
    return view('chat.blade', compact(['id','audiences','audience_id','reviewer_id']));
}

Now you can access all the variables passed in compact in your blade file like this

<div>
     // Depends on what is in the $audiences could be with "$key => $value" 
     @foreach($audiences as $key)
            {{$key->id}};
     @endforeach
</div>

<div>
   <form action="/" method="post">
     <input type="hidden" value={{$reviewer_id}} name="id">
     <input type="hidden" value={{$audience_id}} name="id">
     <input type="text" name="message">
     <input type="submit" value="submit">
   </form>
</div>