diff --git a/app/Http/Controllers/API/AccountController.php b/app/Http/Controllers/API/AccountController.php index 15e12de1..6d22634c 100644 --- a/app/Http/Controllers/API/AccountController.php +++ b/app/Http/Controllers/API/AccountController.php @@ -6,10 +6,12 @@ use App\Http\Requests\BankAccountRequest; use App\Http\Requests\ContactsRequest; use App\Http\Resources\AccountResource; +use App\Models\Account; use Illuminate\Http\Request; class AccountController extends Controller { + /** * @OA\GET( * path="/api/account", @@ -28,11 +30,11 @@ class AccountController extends Controller * ) * ) */ - public function account(Request $request) - { - $account = $request->user() - ->account() - ->with('profile'); + public function account(Request $request){ + + $account = Account::with('profile')->find($request->user()->account_id); + + //return $account; if(!empty($account)){ return AccountResource::make($account); diff --git a/app/Http/Controllers/Admin/AccountCrudController.php b/app/Http/Controllers/Admin/AccountCrudController.php index 61a4f15e..945d960b 100644 --- a/app/Http/Controllers/Admin/AccountCrudController.php +++ b/app/Http/Controllers/Admin/AccountCrudController.php @@ -40,27 +40,22 @@ public function setup() */ protected function setupListOperation() { + CRUD::column('type'); CRUD::column('vat'); CRUD::column('country_id'); CRUD::column('legalization_number'); - // dropdown filter - $this->crud->addFilter([ - 'name' => 'status', - 'type' => 'dropdown', - 'label' => 'Account type' - ], [ - 'company' => 'Company', - 'business' => 'Business' - ], function($value) { // if the filter is active - $this->crud->addClause('where', 'type', $value); - }); - /** - * Columns can be defined using the fluent syntax or array syntax: - * - CRUD::column('price')->type('number'); - * - CRUD::addColumn(['name' => 'price', 'type' => 'number']); - */ + // $this->crud->addFilter([ + // 'name' => 'status', + // 'type' => 'dropdown', + // 'label' => 'Account type' + // ], [ + // 'company' => 'Company', + // 'business' => 'Business' + // ], function($value) { // if the filter is active + // $this->crud->addClause('where', 'type', $value); + // }); } /** diff --git a/app/Http/Resources/AccountResource.php b/app/Http/Resources/AccountResource.php index 3e17c6e0..528b7e88 100644 --- a/app/Http/Resources/AccountResource.php +++ b/app/Http/Resources/AccountResource.php @@ -2,7 +2,9 @@ namespace App\Http\Resources; +use App\Models\Business; use Illuminate\Http\Resources\Json\JsonResource; +use Symfony\Component\HttpKernel\Profiler\Profile; class AccountResource extends JsonResource { @@ -18,15 +20,17 @@ public function toArray($request) 'id' => $this->id, 'bank_account' => $this->bank_account, 'contacts' => $this->contacts, - 'account_type' => $this->account_type, + 'account_type' => $this->type, 'profile' => $this->profile() ]; } private function profile() : JsonResource { - $type = config('account.'.$this->account_type.'.resource'); - - return $type::make($this->profile); + if($this->profile){ + $type = config('account.'.$this->type.'.resource'); + return $type::make($this->profile); + } + return new JsonResource([]); } } diff --git a/app/Http/Resources/BusinessProfileResource.php b/app/Http/Resources/BusinessProfileResource.php index 117316bf..71a2c333 100644 --- a/app/Http/Resources/BusinessProfileResource.php +++ b/app/Http/Resources/BusinessProfileResource.php @@ -14,6 +14,10 @@ class BusinessProfileResource extends JsonResource */ public function toArray($request) { - return parent::toArray($request); + return [ + 'personal' => $this->personal, + 'document' => $this->document, + 'job' => $this->job + ]; } } diff --git a/app/Models/Account.php b/app/Models/Account.php index 7561e39f..a5280340 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -20,7 +20,7 @@ class Account extends Model // public $timestamps = false; protected $guarded = ['id']; protected $fillable = [ - 'contacts', 'bank', 'vat', 'country_id', 'legalization_number','type' + 'contacts', 'bank', 'vat', 'country_id', 'legalization_number', 'type', ]; protected $casts = [ 'contacts' => 'array', @@ -57,6 +57,10 @@ public function application(){ return $this->hasOne(Application::class); } + public function clients(){ + return $this->hasMany(Client::class); + } + /* |-------------------------------------------------------------------------- | SCOPES diff --git a/app/Models/Client.php b/app/Models/Client.php index b6031c0e..7bdcfffe 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -25,7 +25,7 @@ class Client extends Authenticatable // public $timestamps = false; protected $guarded = ['id']; protected $fillable = [ - 'firstname', 'lastname', 'email', 'password', 'is_verified','verification_token', 'is_suspended' + 'firstname', 'lastname', 'email', 'password', 'is_verified','verification_token', 'is_suspended', 'account_id' ]; protected $hidden = [ 'password', diff --git a/config/account.php b/config/account.php index e7556c68..9a6aae94 100644 --- a/config/account.php +++ b/config/account.php @@ -8,10 +8,10 @@ return [ 'business' => [ 'class' => App\AccountTypes\BusinessAccount::class, - 'resources' => App\Http\Resources\BusinessProfileResource::class + 'resource' => App\Http\Resources\BusinessProfileResource::class ], 'company' => [ 'class' => App\AccountTypes\CompanyAccount::class, - 'resources' => App\Http\Resources\CompanyProfileResource::class + 'resource' => App\Http\Resources\CompanyProfileResource::class ] ]; diff --git a/resources/views/vendor/backpack/crud/fields/morphic_select.blade.php b/resources/views/vendor/backpack/crud/fields/morphic_select.blade.php deleted file mode 100644 index d1ad209d..00000000 --- a/resources/views/vendor/backpack/crud/fields/morphic_select.blade.php +++ /dev/null @@ -1,49 +0,0 @@ - -@php - $current_value = old_empty_or_null($field['name'], '') ?? $field['value'] ?? $field['default'] ?? ''; - $entity_model = $crud->getRelationModel($field['entity'], - 1); - $field['allows_null'] = $field['allows_null'] ?? $entity_model::isColumnNullable($field['name']); - - //if it's part of a relationship here we have the full related model, we want the key. - if (is_object($current_value) && is_subclass_of(get_class($current_value), 'Illuminate\Database\Eloquent\Model') ) { - $current_value = $current_value->getKey(); - } - - if (!isset($field['options'])) { - $options = $field['model']::all(); - } else { - $options = call_user_func($field['options'], $field['model']::query()); - } -@endphp - -@include('crud::fields.inc.wrapper_start') - - - @include('crud::fields.inc.translatable_icon') - - - - {{-- HINT --}} - @if (isset($field['hint'])) -

{!! $field['hint'] !!}

- @endif - -@include('crud::fields.inc.wrapper_end') diff --git a/resources/views/vendor/backpack/crud/fields/table.blade.php b/resources/views/vendor/backpack/crud/fields/table.blade.php new file mode 100644 index 00000000..36dc3a3b --- /dev/null +++ b/resources/views/vendor/backpack/crud/fields/table.blade.php @@ -0,0 +1,227 @@ + + + 0 ? $field['max'] : -1; + $min = isset($field['min']) && (int) $field['min'] > 0 ? $field['min'] : -1; + $item_name = strtolower(isset($field['entity_singular']) && ! empty($field['entity_singular']) ? $field['entity_singular'] : $field['label']); + + $items = old(square_brackets_to_dots($field['name'])) ?? $field['value'] ?? $field['default'] ?? ''; + + // make sure no matter the attribute casting + // the $items variable contains a properly defined JSON string + if (is_array($items)) { + if (count($items)) { + $items = json_encode($items); + } else { + $items = '[]'; + } + } elseif (is_string($items) && ! is_array(json_decode($items))) { + $items = '[]'; + } + + // make sure columns are defined + if (! isset($field['columns'])) { + $field['columns'] = ['value' => 'Value']; + } + + $field['wrapper'] = $field['wrapper'] ?? $field['wrapperAttributes'] ?? []; + $field['wrapper']['data-field-type'] = 'table'; + $field['wrapper']['data-field-name'] = $field['name']; +?> +@include('crud::fields.inc.wrapper_start') + + + @include('crud::fields.inc.translatable_icon') + + + +
+ + + + + + @foreach( $field['columns'] as $column ) + + @endforeach + + + + + + + + + @foreach( $field['columns'] as $column => $label) + + @endforeach + + + + + + +
+ {{ $column }} + {{-- --}} {{-- --}}
+ +
+ +
+ +
+ + {{-- HINT --}} + @if (isset($field['hint'])) +

{!! $field['hint'] !!}

+ @endif +@include('crud::fields.inc.wrapper_end') + +{{-- ########################################## --}} +{{-- Extra CSS and JS for this particular field --}} +{{-- If a field type is shown multiple times on a form, the CSS and JS will only be loaded once --}} +@if ($crud->fieldTypeNotLoaded($field)) + @php + $crud->markFieldTypeAsLoaded($field); + @endphp + + {{-- FIELD JS - will be loaded in the after_scripts section --}} + @push('crud_fields_scripts') + {{-- YOUR JS HERE --}} + + + + @endpush +@endif +{{-- End of Extra CSS and JS --}} +{{-- ########################################## --}}