当我在laravel的视图页面上调用它时,foreach循环不显示数据

I am having this code in my controller. When i print the variable in view it gives only last row of database table column. How i print all the value as a string on view. Can anyone help please

public function welcome(){
    $company_name = DB::table('companies')
            ->select('company_name')
            ->get(); 
    return view('welcome',['company_name' => $company_name]);
}

I am trying to access the value in this jquery code

 @foreach ($company_name as $company_names)


  <script>
  $(document).ready(function() {
  $("#tags").autocomplete({
    source: [
         { value: "{{$company_names->company_name}}", url:        "http://localhost:8000/company_profile" }, 

    ],
    select: function (event, ui) {
        window.location = ui.item.url;
    }
  });
  });
  </script>

@endforeach

Make Sure you add use Illuminate\Support\Facades\DB; in your controller.

It looks like you only sending a value of the last row to your View. Doing this might help:

//controller
public function welcome(){
     $company_names = DB::table('companies')
        ->select('company_name')
        ->get();
return view('welcome',compact('company_names'));
}

Add this code to your View: welcome.blade.php

//Printing a list of companies in a View
<ul>
@foreach ($company_names as $company_name)
           <li>{{ $company_name->company_name }}</li>
@endforeach
</ul>