PHP code example of signifly / laravel-builder-macros

1. Go to this page and download the library: Download signifly/laravel-builder-macros library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

signifly / laravel-builder-macros example snippets


// Params: $column, $query
$query->addSubSelect('primary_address_id', 
    Address::select('id')
        ->where('user_id', $user->id)
        ->primary()
);

// It adds primary_address_id to the result set

$query->defaultSelectAll()
    ->join('contacts', 'users.id', '=', 'contacts.user_id')
    ->addSelect('contacts.name as contact_name');

// Params: $relationName, $operator
$query->joinRelation('contact');

// Params: $relationName, $operator
$query->leftJoinRelation('contact');

$userIds = $query->where('user_id', 10)->map(function ($user) {
    return $user->id;
});

// Returns a collection

$query->whereLike('title', 'john')->get();

// Returns all results where title  

$query->whereLike(['title', 'contact.name'], 'john')->get();

// Returns all results where title or contact.name