Laravel - Query Builder - Retrieving A List Of Column Values

If you would like to retrieve an Illuminate\Support\Collection instance containing the values of a single column, you may use the pluck method. In this example, we'll retrieve a collection of user titles:

    
    use Illuminate\Support\Facades\DB;
    
    $titles = DB::table('users')->pluck('title');
    
    foreach ($titles as $title) {
        echo $title;
    }
	

You may specify the column that the resulting collection should use as its keys by providing a second argument to the pluck method:

    
    $titles = DB::table('users')->pluck('title', 'name');
    
    foreach ($titles as $name => $title) {
        echo $title;
    }