PHP code example of hongxunpan / eloquent-projection

1. Go to this page and download the library: Download hongxunpan/eloquent-projection 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/ */

    

hongxunpan / eloquent-projection example snippets


$projectionModel = clone $submitRecord;
$projectionModel->append(['mobile_phone_masked']);
$projectionModel->makeHidden(['mobile_phone']);

$result = $projectionModel->toArray();

if ($canViewMobileFull) {
    $result['mobile_phone_masked'] = $projectionModel->getAttribute('mobile_phone');
}

return $result;

use HongXunPan\EloquentProjection\FieldOverrideRule;
use HongXunPan\EloquentProjection\ProjectionApplier;
use HongXunPan\EloquentProjection\ProjectionProfile;

$profile = new ProjectionProfile(
    overrides: [
        new FieldOverrideRule(
            'mobile_phone_masked',
            'mobile_phone',
            $canViewMobileFull,
            true,
            true
        ),
    ],
);

return ProjectionApplier::projectModel($submitRecord, $profile);

new FieldOverrideRule(
    'mobile_phone_masked',
    'mobile_phone',
    $canViewMobileFull,
    true,
    true
)

use HongXunPan\EloquentProjection\FieldOverrideRule;
use HongXunPan\EloquentProjection\ProjectionApplier;
use HongXunPan\EloquentProjection\ProjectionProfile;

$profile = new ProjectionProfile(
    overrides: [
        new FieldOverrideRule(
            'mobile_phone_masked',
            'mobile_phone',
            $canViewMobileFull,
            true,
            true
        ),
    ],
);

ProjectionApplier::applyRelation($records, 'alumniCard', $profile);

$profile = new ProjectionProfile(
    overrides: [
        new FieldOverrideRule(
            'phone_masked',
            'phone',
            $canViewPhoneFull,
            true,
            true
        ),
    ],
);

return ProjectionApplier::projectModel($user, $profile);

return ProjectionApplier::projectList($candidates, $profile);
text
app/Projections/AlumniCard/AlumniCardProjectionProfiles.php
app/Projections/Activity/ActivityProjectionProfiles.php