PHP code example of lumenpress / acf

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

    

lumenpress / acf example snippets


$app->configure('acf'); 
$app->register(LumenPress\ACF\ServiceProvider::class);

use LumenPress\ACF\Schema;
use LumenPress\ACF\Models\FieldGroup;

Schema::create($groupKey, function (FieldGroup $group) {
    $group->title('Title'); // 

Schema::create('group_599d8daf5e131', function (FieldGroup $group) {
    $group->title('Title'); // 

Schema::create('home_page', function (FieldGroup $group) {
    $group->title('Home'); // ubstr(hash('md5', 'home_page'), 8, 16);
// group_3f239af6fe3db5c0

$group->location($param, $value); // operator is '==';
$group->location($param, $operator, $value);

$group->location(
    [$param, $operator, $value], // A
    [$param, $operator, $value]  // B
);

// another
$group->location($param, $operator, $value)  // A
    ->location($param, $operator, $value);   // B

$group->location($param, $operator, $value)   // A
    ->orLocation($param, $operator, $value);  // B

$group->location(
        [$param, $operator, $value],  // A
        [$param, $operator, $value]   // B
    )->orLocation(
        [$param, $operator, $value],  // C
        [$param, $operator, $value]   // D
    );

// another
$group->location($param, $operator, $value)  // A
    ->location($param, $operator, $value);   // B
    ->orLocation($param, $operator, $value)  // C
    ->location($param, $operator, $value);   // D

Schema::rename($oldKey, $newKey);

Schema::drop($groupKey);

Schema::create($groupKey, function (FieldGroup $group) {
    $group->title('Demo'); // eld) {
        $field->text('uniqid_name')->label('Label');
    });
});

// Basic
$field->text('text')->label('Text');
$field->textarea('textarea')->label('Textarea');
$field->number('number')->label('Number');
$field->email('email')->label('Email');
$field->url('url')->label('URL');
$field->password('password')->label('Password');

// Content
$field->wysiwyg('wysiwyg');
$field->oembed('oembed');
$field->image('image');
$field->file('file');
$field->gallery('gallery');

// Choice
$field->true_false('true_false');
$field->checkbox('checkbox')->choices(['value1', 'value2']);
$field->radio('radio')->choices(['value1', 'value2']);;
$field->select('select')->choices(['value1', 'value2']);;

// Relational
$field->link('link');
$field->page_link('page_link');
$field->post_object('post_object');
$field->relationship('relationship');
$field->taxonomy('taxonomy');
$field->user('user');

// JQuery
$field->google_map('google_map');
$field->date_picker('date_picker');
$field->date_time_picker('date_time_picker');
$field->time_picker('time_picker');
$field->color_picker('color_picker');

// Layout

$field->tab('tab');
$field->message('Message')->content('Content');

$field->group('group')->fields(function($field) {
    $field->text('text');
    $field->image('image');
});

$field->repeater('repeater')->fields(function($field) {
    $field->text('text')->label('Text');
    $field->image('image');
});

$field->flexible('flexible')->layouts(function($flexible) {
    $flexible->layout('layout1')->label('Layout 1')->fields(function($field) {
        $field->textarea('textarea')->label('Textarea');
    });
    $flexible->layout('layout2')->label('Layout 2')->fields(function($field) {
        $field->text('text')->label('Text');
    });
});

// friendly
$field->clone('clone')->fields('group');
$field->clone('clone')->fields('group.text');
$field->clone('clone')->fields('group.text', 'group.textarea');

// strict
$field->clone('clone')->fields('group_1b8797f52e1e7731');
$field->clone('clone')->fields('field_599ec2068e143');
$field->clone('clone')->fields('field_599ec2068e143', 'field_599ec6186b36b');

Schema::group($groupKey, function (FieldGroup $group) {
    $group->fields(function($field) {
        $field->text('text')->label('Text2');
    });
});

Schema::group($groupKey, function (FieldGroup $group) {
    $group->fields(function($field) {
        $field->rename('oldname', 'newname');
    });
});

Schema::group($groupKey, function (FieldGroup $group) {
    $group->fields(function($field) {
        // single field
        $field->drop('text');
        // multiple fields
        $field->drop('text', 'textarea');
        // all
        $field->dropAll();
    });
});

use LumenPress\ACF\Concerns\HasFields;

class Post extends \LumenPress\Nimble\Models\Post
{
    use HasFields;
}

$post = new Post;

$post->title = 'Title1';
$post->type = 'post';

$post->acf->schema('home_fields');

$post->acf->text = 'Text';
$post->acf->textarea = 'Textarea';

$post->save();

$post = Post::find(2);

$post->acf->text = 'Text2';
$post->acf->textarea = 'Textarea2';

$post->save();

$post = Post::find(2);

unset($post->acf->text);
unset($post->acf->textarea);

$post->save();

$post = Post::find(2);
$builder = $post->acf();

$post->acf('abc')->value();
$post->acf()->text('abc')->value();

$post->acf()->text('abc')->insertValue('Value 1');

$post->acf()->text('abc')->updateValue('Value 2');

$post->acf('abc')->delete();
$post->acf()->text('abc')->delete();