PHP code example of ipop / laravel-custom-fields

1. Go to this page and download the library: Download ipop/laravel-custom-fields 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/ */

    

ipop / laravel-custom-fields example snippets


use Illuminate\Database\Eloquent\Model;
use Givebutter\LaravelCustomFields\Traits\HasCustomFields;

class Survey extends Model
{
    use HasCustomFields;

    // ...
}

use Illuminate\Database\Eloquent\Model;
use Givebutter\LaravelCustomFields\Traits\HasCustomFieldResponses;

class SurveyResponse extends Model
{
    use HasCustomFieldResponses;

    // ...
}

$survey->customFields()->create([
    'title' => 'What is your name?',
    'type' => 'text'
]);

$field->responses()->create([
    'value' => 'John Doe'
]);

$survey->customFields()->get();

$field->responses()->get();

 $survey->customFields()->create([
    'title' => 'What is your favorite color?',
    'type' => 'select',
    'answers' => ['Red', 'Green', 'Blue', 'Yellow'], 
]);


$responses = [
    '1' => "John Doe",
    '2' => "Blue"
];
$survey->validateCustomFields($responses);

use Request;

class FooController extends Controller {

    public function index(Request $request) 
    {
        $validation = $survey->validateCustomFields($request);

        // ...
    }

}

$survey->customFields()->create([
    'title' => 'Do you love Laravel?',
    'type' => 'radio',
    'answers' => ['Yes', 'YES'],
    '

$survey->customFields()->create([
    'title' => 'Pick a number 1-10',
    'type' => 'text',
    'validation_rules' => 'integer|min:1|max:10'
]);

$surveyResponse->saveCustomFields(['
   
']);

Use App\...
$surveyResponse->saveCustomFields($request->input);

Use App\Models\SurveyResponse;
Use App\Models\SurveyResponse;

$field = 

SurveyResponse::WhereCustomField($field, 'large')->get();

$survey->orderCustomFields([2, 4, 5]); // Field with id 2 will be ordered first.

$field->order = 3; 
$field->save();

$survey->customFields()->get(); // Returned in ascending order.
bash
php artisan vendor:publish --provider="Givebutter\LaravelCustomFields\LaravelCustomFieldsServiceProvider" --tag="migrations"
bash
php artisan migrate
bash
php artisan vendor:publish --provider="Givebutter\LaravelCustomFields\LaravelCustomFieldsServiceProvider" --tag="config"