Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save joergpatz/11405849 to your computer and use it in GitHub Desktop.
Save joergpatz/11405849 to your computer and use it in GitHub Desktop.
Laravel DB::Raw snippets
        $ids = DB::table('service')
                ->select(DB::raw('DISTINCT label_id AS cat_label_id'))
                ->whereNull('deleted_date')
                ->lists('cat_label_id');

$ids will be an array.

    $sSelect   = '
        SELECT DISTINCT label_id
        FROM service
        WHERE flag_deleted = 0
    ';

    try {
        $ids = DB::select(DB::raw($sSelect));

    } catch (Exception $e) {
        \Log::error(__METHOD__ ." Error: ".$e->getMessage());
        throw new HttpException(500, 'detected an internal error in: '.__METHOD__ );
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment