PHP code example of givebutter / laravel-custom-fields
1. Go to this page and download the library: Download givebutter/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/ */
givebutter / 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'
]);
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.