PHP code example of spykapp / laravel-custom-fields
1. Go to this page and download the library: Download spykapp/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/ */
$post = Post::find(1);
$post->saveCustomFieldResponses([
[
'custom_field_id' => 1,
'value' => 'This is the subtitle',
],
[
'custom_field_id' => 2,
// No value provided, so it will use default_value
]
], validate: false);
use SpykApp\LaravelCustomFields\Traits\HasCustomFields;
use SpykApp\LaravelCustomFields\Traits\LoadCustomFields;
class Post extends Model
{
use HasCustomFields, LoadCustomFields;
// Your model code here...
}
$post = Post::find(1);
echo $post->cf_subtitle; // Outputs the value of the 'subtitle' custom field, or null if not set