diff --git a/app/Http/Controllers/Customer/CustomerController.php b/app/Http/Controllers/Customer/CustomerController.php index 998b100..b93cdfb 100644 --- a/app/Http/Controllers/Customer/CustomerController.php +++ b/app/Http/Controllers/Customer/CustomerController.php @@ -20,6 +20,7 @@ use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Http; use App\Models\Setting; use App\Http\Controllers\Admin\TahesabController; +use Illuminate\Support\Facades\Schema; //use App\Models\Price; @@ -30,8 +31,22 @@ class CustomerController extends Controller { public function me() { - $select = ['*',Customer::$SELECT_CAJ,Customer::$SELECT_TYPE_STR]; - $user = Customer::with(['customer_settings.customer',"agent"])->select($select)->findOrFail(auth('customer')->id()); + $select = ['*', Customer::$SELECT_CAJ, Customer::$SELECT_TYPE_STR]; + + $with = []; + if (Schema::hasTable('customers_settings')) { + $with[] = 'customer_settings.customer'; + } + if (Schema::hasColumn((new Customer)->getTable(), 'agent_id')) { + $with[] = 'agent'; + } + + $query = Customer::query(); + if ($with !== []) { + $query->with($with); + } + + $user = $query->select($select)->findOrFail(auth('customer')->id()); $wallet = Wallet::where('owner', $user->id) ->where('owner_type', $user->type)