get(); return view('customers.index', compact('brands')); } public function show(Customer $customer, Brand $brand) { $CustomerInfo = CustomerInfo::where('customer_id', $customer->id) ->where('brand_id', $brand->id)->firstOrFail(); $customerLogin = CustomerLogin::where('customer_id', $customer->id) ->where('brand_id', $brand->id)->first(); return view('customers.show', compact('CustomerInfo', 'customerLogin')); } public function filter($texte, Brand $brand = null) { if ($brand) { $customers = Customer::join('customer_infos', 'customers.id', '=', 'customer_infos.customer_id') ->join('customer_login', 'customers.id', '=', 'customer_login.customer_id')->select( 'customer_infos.customer_id', 'customer_infos.firstname', 'customer_infos.lastname', 'customer_infos.opt_in', 'customers.email', 'customer_infos.brand_id', 'customer_login.last_connection' )->where([ ['lastname', 'like', '%' . $texte . '%'], ['customer_infos.brand_id', $brand->id], ['customer_login.brand_id', $brand->id] ])->orWhere([ ['email', 'like', '%' . $texte . '%'], ['customer_infos.brand_id', $brand->id], ['customer_login.brand_id', $brand->id] ])->get(); } else { $customers = CustomerInfo::join('customers', 'customers.id', '=', 'customer_infos.customer_id') ->join('customer_login', function ($join) { $join->on('customer_login.customer_id', '=', 'customer_infos.customer_id'); $join->on('customer_login.brand_id', '=', 'customer_infos.brand_id'); })->select( 'customer_infos.customer_id', 'customer_infos.firstname', 'customer_infos.lastname', 'customer_infos.opt_in', 'customers.email', 'customer_infos.brand_id', 'customer_login.last_connection' )->where('lastname', 'like', '%' . $texte . '%') ->orWhere('email', 'like', '%' . $texte . '%')->get(); } return response()->json($customers); } }