PHP code example of danielebarbaro / laravel-entity-details

1. Go to this page and download the library: Download danielebarbaro/laravel-entity-details 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/ */

    

danielebarbaro / laravel-entity-details example snippets


return [
    'table_name' => env('ENTITYDETAIL_TABLE_NAME', 'entity_details'),
    'returns_soft_deleted_models' => env('ENTITYDETAIL_SOFTDETED_ENABLE', false),
];

class User extends Authenticatable
{
    [...]
    use EntityDetail, EntityDetailHydrate;
    [...]
}

[...]

class Biker extends Model
{
    [...]
    use EntityDetail, EntityDetailHydrate;
    [...]
}

[...]

class Company extends Model
{
    [...]
    use EntityDetail, EntityDetailHydrate;
    [...]
}

    [...]
    $user = User::create([
        'name' => 'John',
        'email' => 'Doe',
        'password' => Hash::make('password')
    ]);
    
    $user->syncDetail([
        'is_company' => true,
        'status' => 1,
        'code' => 'CODE',
        'name' => 'DUMMY COMPANY',
    ]);
    
    $user->fresh('detail');

    $detail = $user->detail;
    [...]

    [...]
    $company = Company::with('detail')->first();
    
    $company->syncDetail([
        'is_company' => true,
        'status' => 1,
        'code' => 'CODE',
        'name' => 'DUMMY COMPANY',
    ]);

    $detail = $company->detail;
    [...]

    $detail = Detail::with('owner')->get();
    $user = $detail->owner;

    [...]

    $biker = Biker::with('detail')->first();
    $detail = $biker->detail;
    [...]


    $details = Detail::where('status', 1)->isCompany()->get();
    [...]
    
    $user = User::where('email', '[email protected]')->first();
    $detail = Detail::forOwner($user)->first();
    [...]

$rules = [
    'is_company' => '0',
    'code' => 'il' => 'email',
    'sdi' => 'max:7',
    'pec' => 'email',
    'first_name' => 'string|max:60',
    'last_name' => 'string|max:60',
    'phone' => 'string|max:60',
    'mobile' => 'string|max:60',
    'fiscal_code' => 'string|max:16',
    'vat' => 'string|max:13',
    'postal_code' => 'string|max:6',
    'city' => 'string|max:30',
    'country' => 'string|max:2',
    'address' => 'string|max:100',
    'notes' => 'string',
];
bash
php artisan vendor:publish --tag="entity-details-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="entity-details-config"