Illuminate\View\ViewException {#1322 #severity: E_ERROR }
throw new UniqueConstraintViolationException( $this->getName(), $query, $this->prepareBindings($bindings), $e ); } throw new QueryException( $this->getName(), $query, $this->prepareBindings($bindings), $e ); } } \Illuminate\View\Engines\PhpEngine::handleViewException($e, $obLevel); return; } parent::handleViewException($e, $obLevel); } public function shouldBypassExceptionForLivewire(\Throwable $e, $obLevel) { $uses = array_flip(class_uses_recursive($e)); \Closure::bind(function () use ($__path, $__data) { extract($__data, EXTR_SKIP); include $__path; }, $component, $component)(); } catch (\Exception|\Throwable $e) { $this->handleViewException($e, $obLevel); } return ltrim(ob_get_clean()); } // Once we have the path to the compiled file, we will evaluate the paths with // typical PHP just like any other templates. We also keep a stack of views // which have been rendered for right exception messages to be generated. try { $results = $this->evaluatePath($this->compiler->getCompiledPath($path), $data); } catch (ViewException $e) { if (! Str::of($e->getMessage())->contains(['No such file or directory', 'File does not exist at path'])) { throw $e; } $currentComponent = ExtendBlade::currentRendering(); trigger('view:compile', $currentComponent, $path); return parent::get($path, $data); } protected function evaluatePath($__path, $__data) { if (! ExtendBlade::isRenderingLivewireComponent()) { * * @return string */ protected function getContents() { return $this->engine->get($this->path, $this->gatherData()); } /** * Get the data bound to the view instance. * // clear out the sections for any separate views that may be rendered. $this->factory->incrementRender(); $this->factory->callComposer($this); $contents = $this->getContents(); // Once we've finished rendering the view, we'll decrement the render count // so that each section gets flushed out next time a view is created and // no old sections are staying around in the memory of an environment. $this->factory->decrementRender(); * @throws \Throwable */ public function render(?callable $callback = null) { try { $contents = $this->renderContents(); $response = isset($callback) ? $callback($this, $contents) : null; // Once we have the contents of the view, we will flush the sections if we are // done rendering all views so that there is nothing left hanging over when $revertA = Utils::shareWithViews('__livewire', $component); $revertB = Utils::shareWithViews('_instance', $component); // @deprecated $viewContext = new ViewContext; $html = $view->render(function ($view) use ($viewContext) { // Extract leftover slots, sections, and pushes before they get flushed... $viewContext->extractFromEnvironment($view->getFactory()); }); $revertA(); $revertB(); protected function trackInRenderStack($component, $callback) { array_push(static::$renderStack, $component); return tap($callback(), function () { array_pop(static::$renderStack); }); } protected function updateProperties($component, $updates, $data, $context) ]); } [ $view, $properties ] = $this->getView($component); return $this->trackInRenderStack($component, function () use ($component, $view, $properties) { $finish = trigger('render', $component, $view, $properties); $revertA = Utils::shareWithViews('__livewire', $component); $revertB = Utils::shareWithViews('_instance', $component); // @deprecated if (config('app.debug')) $start = microtime(true); $finish = trigger('mount', $component, $params, $key, $parent); if (config('app.debug')) trigger('profile', 'mount', $component->getId(), [$start, microtime(true)]); if (config('app.debug')) $start = microtime(true); $html = $this->render($component, '<div></div>'); if (config('app.debug')) trigger('profile', 'render', $component->getId(), [$start, microtime(true)]); if (config('app.debug')) $start = microtime(true); trigger('dehydrate', $component, $context); return app(ComponentRegistry::class)->resolveMissingComponent($resolver); } function mount($name, $params = [], $key = null) { return app(HandleComponents::class)->mount($name, $params, $key); } function snapshot($component, $context = null) { return app(HandleComponents::class)->snapshot($component, $context); $html = null; $layoutConfig = SupportPageComponents::interceptTheRenderOfTheComponentAndRetreiveTheLayoutConfiguration(function () use (&$html) { $params = SupportPageComponents::gatherMountMethodParamsFromRouteParameters($this); $html = app('livewire')->mount($this::class, $params); }); $layoutConfig = $layoutConfig ?: new PageComponentConfig; $layoutConfig->normalizeViewNameAndParamsForBladeComponents(); }); on('render', $handler); on('render.placeholder', $handler); $callback(); off('render', $handler); off('render.placeholder', $handler); return $layoutConfig; // Here's we're hooking into the "__invoke" method being called on a component. // This way, users can pass Livewire components into Routes as if they were // simple invokable controllers. Ex: Route::get('...', SomeLivewireComponent::class); $html = null; $layoutConfig = SupportPageComponents::interceptTheRenderOfTheComponentAndRetreiveTheLayoutConfiguration(function () use (&$html) { $params = SupportPageComponents::gatherMountMethodParamsFromRouteParameters($this); $html = app('livewire')->mount($this::class, $params); }); if (method_exists($controller, 'callAction')) { return $controller->callAction($method, $parameters); } return $controller->{$method}(...array_values($parameters)); } /** * Resolve the parameters for the controller. * * * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException */ protected function runController() { return $this->controllerDispatcher()->dispatch( $this, $this->getController(), $this->getControllerMethod() ); } /** { $this->container = $this->container ?: new Container; try { if ($this->isControllerAction()) { return $this->runController(); } return $this->runCallable(); } catch (HttpResponseException $e) { return $e->getResponse(); return (new Pipeline($this->container)) ->send($request) ->through($middleware) ->then(fn ($request) => $this->prepareResponse( $request, $route->run() )); } /** * Gather the middleware for the given route with resolved class names. */ protected function prepareDestination(Closure $destination) { return function ($passable) use ($destination) { try { return $destination($passable); } catch (Throwable $e) { return $this->handleException($passable, $e); } }; } $footer_header=PageContent::whereIN('page', ['footer','header']) ->where('locale', app()->getLocale()) ->pluck('value', 'key') ->toArray(); View::share('footer_header', $footer_header); return $next($request); }} // since the object we're given was already a fully instantiated object. $parameters = [$passable, $stack]; } $carry = method_exists($pipe, $this->method) ? $pipe->{$this->method}(...$parameters) : $pipe(...$parameters); return $this->handleCarry($carry); } catch (Throwable $e) { return $this->handleException($passable, $e); App::setLocale($locale); // dd(0); // return redirect($locale . '/' . $request->path()); } return $next($request); }} // since the object we're given was already a fully instantiated object. $parameters = [$passable, $stack]; } $carry = method_exists($pipe, $this->method) ? $pipe->{$this->method}(...$parameters) : $pipe(...$parameters); return $this->handleCarry($carry); } catch (Throwable $e) { return $this->handleException($passable, $e); } throw $exception; } return $next($request); }} // since the object we're given was already a fully instantiated object. $parameters = [$passable, $stack]; } $carry = method_exists($pipe, $this->method) ? $pipe->{$this->method}(...$parameters) : $pipe(...$parameters); return $this->handleCarry($carry); } catch (Throwable $e) { return $this->handleException($passable, $e); $this->isReading($request) || $this->runningUnitTests() || $this->inExceptArray($request) || $this->tokensMatch($request) ) { return tap($next($request), function ($response) use ($request) { if ($this->shouldAddXsrfTokenCookie()) { $this->addCookieToResponse($request, $response); } }); } // since the object we're given was already a fully instantiated object. $parameters = [$passable, $stack]; } $carry = method_exists($pipe, $this->method) ? $pipe->{$this->method}(...$parameters) : $pipe(...$parameters); return $this->handleCarry($carry); } catch (Throwable $e) { return $this->handleException($passable, $e); // Putting the errors in the view for every view allows the developer to just // assume that some errors are always available, which is convenient since // they don't have to continually run checks for the presence of errors. return $next($request); }} // since the object we're given was already a fully instantiated object. $parameters = [$passable, $stack]; } $carry = method_exists($pipe, $this->method) ? $pipe->{$this->method}(...$parameters) : $pipe(...$parameters); return $this->handleCarry($carry); } catch (Throwable $e) { return $this->handleException($passable, $e); $this->startSession($request, $session) ); $this->collectGarbage($session); $response = $next($request); $this->storeCurrentUrl($request, $session); $this->addCookieToResponse($response, $session); if ($this->manager->shouldBlock() || ($request->route() instanceof Route && $request->route()->locksFor())) { return $this->handleRequestWhileBlocking($request, $session, $next); } return $this->handleStatefulRequest($request, $session, $next); } /** * Handle the given request within session state. * // since the object we're given was already a fully instantiated object. $parameters = [$passable, $stack]; } $carry = method_exists($pipe, $this->method) ? $pipe->{$this->method}(...$parameters) : $pipe(...$parameters); return $this->handleCarry($carry); } catch (Throwable $e) { return $this->handleException($passable, $e); * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $response = $next($request); foreach ($this->cookies->getQueuedCookies() as $cookie) { $response->headers->setCookie($cookie); } // since the object we're given was already a fully instantiated object. $parameters = [$passable, $stack]; } $carry = method_exists($pipe, $this->method) ? $pipe->{$this->method}(...$parameters) : $pipe(...$parameters); return $this->handleCarry($carry); } catch (Throwable $e) { return $this->handleException($passable, $e); * @param \Closure $next * @return \Symfony\Component\HttpFoundation\Response */ public function handle($request, Closure $next) { return $this->encrypt($next($this->decrypt($request))); } /** * Decrypt the cookies on the request. * // since the object we're given was already a fully instantiated object. $parameters = [$passable, $stack]; } $carry = method_exists($pipe, $this->method) ? $pipe->{$this->method}(...$parameters) : $pipe(...$parameters); return $this->handleCarry($carry); } catch (Throwable $e) { return $this->handleException($passable, $e); $pipeline = array_reduce( array_reverse($this->pipes()), $this->carry(), $this->prepareDestination($destination) ); try { return $pipeline($this->passable); } finally { if ($this->finally) { ($this->finally)($this->passable); } } $middleware = $shouldSkipMiddleware ? [] : $this->gatherRouteMiddleware($route); return (new Pipeline($this->container)) ->send($request) ->through($middleware) ->then(fn ($request) => $this->prepareResponse( $request, $route->run() )); } /** $request->setRouteResolver(fn () => $route); $this->events->dispatch(new RouteMatched($route, $request)); return $this->prepareResponse($request, $this->runRouteWithinStack($route, $request) ); } /** * Run the given route within a Stack "onion" instance. * @param \Illuminate\Http\Request $request * @return \Symfony\Component\HttpFoundation\Response */ public function dispatchToRoute(Request $request) { return $this->runRoute($request, $this->findRoute($request)); } /** * Find the route matching a given request. * */ public function dispatch(Request $request) { $this->currentRequest = $request; return $this->dispatchToRoute($request); } /** * Dispatch the request to a route and return the response. * protected function dispatchToRouter() { return function ($request) { $this->app->instance('request', $request); return $this->router->dispatch($request); }; } /** * Call the terminate method on any terminable middleware. */ protected function prepareDestination(Closure $destination) { return function ($passable) use ($destination) { try { return $destination($passable); } catch (Throwable $e) { return $this->handleException($passable, $e); } }; } * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $response = $next($request); if ($response instanceof Response && SupportDisablingBackButtonCache::$disableBackButtonCache){ $response->headers->add([ 'Pragma' => 'no-cache', 'Expires' => 'Fri, 01 Jan 1990 00:00:00 GMT', // since the object we're given was already a fully instantiated object. $parameters = [$passable, $stack]; } $carry = method_exists($pipe, $this->method) ? $pipe->{$this->method}(...$parameters) : $pipe(...$parameters); return $this->handleCarry($carry); } catch (Throwable $e) { return $this->handleException($passable, $e); */ public function handle($request, Closure $next) { $this->clean($request); return $next($request); } /** * Clean the request's data. * if ($callback($request)) { return $next($request); } } return parent::handle($request, $next); } /** * Transform the given value. * // since the object we're given was already a fully instantiated object. $parameters = [$passable, $stack]; } $carry = method_exists($pipe, $this->method) ? $pipe->{$this->method}(...$parameters) : $pipe(...$parameters); return $this->handleCarry($carry); } catch (Throwable $e) { return $this->handleException($passable, $e); */ public function handle($request, Closure $next) { $this->clean($request); return $next($request); } /** * Clean the request's data. * if ($callback($request)) { return $next($request); } } return parent::handle($request, $next); } /** * Transform the given value. * // since the object we're given was already a fully instantiated object. $parameters = [$passable, $stack]; } $carry = method_exists($pipe, $this->method) ? $pipe->{$this->method}(...$parameters) : $pipe(...$parameters); return $this->handleCarry($carry); } catch (Throwable $e) { return $this->handleException($passable, $e); if ($max > 0 && $request->server('CONTENT_LENGTH') > $max) { throw new PostTooLargeException('The POST data is too large.'); } return $next($request); } /** * Determine the server 'post_max_size' as bytes. * // since the object we're given was already a fully instantiated object. $parameters = [$passable, $stack]; } $carry = method_exists($pipe, $this->method) ? $pipe->{$this->method}(...$parameters) : $pipe(...$parameters); return $this->handleCarry($carry); } catch (Throwable $e) { return $this->handleException($passable, $e); null, $this->getHeaders($data) ); } return $next($request); } /** * Determine if the incoming request has a maintenance mode bypass cookie. * // since the object we're given was already a fully instantiated object. $parameters = [$passable, $stack]; } $carry = method_exists($pipe, $this->method) ? $pipe->{$this->method}(...$parameters) : $pipe(...$parameters); return $this->handleCarry($carry); } catch (Throwable $e) { return $this->handleException($passable, $e); * @return \Illuminate\Http\Response */ public function handle($request, Closure $next) { if (! $this->hasMatchingPath($request)) { return $next($request); } $this->cors->setOptions($this->container['config']->get('cors', [])); if ($this->cors->isPreflightRequest($request)) { // since the object we're given was already a fully instantiated object. $parameters = [$passable, $stack]; } $carry = method_exists($pipe, $this->method) ? $pipe->{$this->method}(...$parameters) : $pipe(...$parameters); return $this->handleCarry($carry); } catch (Throwable $e) { return $this->handleException($passable, $e); { $request::setTrustedProxies([], $this->getTrustedHeaderNames()); $this->setTrustedProxyIpAddresses($request); return $next($request); } /** * Sets the trusted proxies on the request. * // since the object we're given was already a fully instantiated object. $parameters = [$passable, $stack]; } $carry = method_exists($pipe, $this->method) ? $pipe->{$this->method}(...$parameters) : $pipe(...$parameters); return $this->handleCarry($carry); } catch (Throwable $e) { return $this->handleException($passable, $e); * @param \Closure $next * @return \Symfony\Component\HttpFoundation\Response */ public function handle(Request $request, Closure $next) { return $next($request); } /** * Invoke the deferred callbacks. * // since the object we're given was already a fully instantiated object. $parameters = [$passable, $stack]; } $carry = method_exists($pipe, $this->method) ? $pipe->{$this->method}(...$parameters) : $pipe(...$parameters); return $this->handleCarry($carry); } catch (Throwable $e) { return $this->handleException($passable, $e); $pipeline = array_reduce( array_reverse($this->pipes()), $this->carry(), $this->prepareDestination($destination) ); try { return $pipeline($this->passable); } finally { if ($this->finally) { ($this->finally)($this->passable); } } $this->bootstrap(); return (new Pipeline($this->app)) ->send($request) ->through($this->app->shouldSkipMiddleware() ? [] : $this->middleware) ->then($this->dispatchToRouter()); } /** * Bootstrap the application for HTTP requests. * $this->requestStartedAt = Carbon::now(); try { $request->enableHttpMethodParameterOverride(); $response = $this->sendRequestThroughRouter($request); } catch (Throwable $e) { $this->reportException($e); $response = $this->renderException($request, $e); } */ public function handleRequest(Request $request) { $kernel = $this->make(HttpKernelContract::class); $response = $kernel->handle($request)->send(); $kernel->terminate($request, $response); } /**// Register the Composer autoloader...require __DIR__.'/../vendor/autoload.php';// Bootstrap Laravel and handle the request...(require_once __DIR__.'/../bootstrap/app.php') ->handleRequest(Request::capture()); throw new UniqueConstraintViolationException( $this->getName(), $query, $this->prepareBindings($bindings), $e ); } throw new QueryException( $this->getName(), $query, $this->prepareBindings($bindings), $e ); } } protected function tryAgainIfCausedByLostConnection(QueryException $e, $query, $bindings, Closure $callback) { if ($this->causedByLostConnection($e->getPrevious())) { $this->reconnect(); return $this->runQueryCallback($query, $bindings, $callback); } throw $e; } { if ($this->transactions >= 1) { throw $e; } return $this->tryAgainIfCausedByLostConnection( $e, $query, $bindings, $callback ); } /** // caused by a connection that has been lost. If that is the cause, we'll try // to re-establish connection and re-run the query with a fresh connection. try { $result = $this->runQueryCallback($query, $bindings, $callback); } catch (QueryException $e) { $result = $this->handleQueryException( $e, $query, $bindings, $callback ); } // Once we have run the query we will calculate the time that it took to run and * @param bool $useReadPdo * @return array */ public function select($query, $bindings = [], $useReadPdo = true) { return $this->run($query, $bindings, function ($query, $bindings) use ($useReadPdo) { if ($this->pretending()) { return []; } // For select statements, we'll simply execute the query and return an array * * @return array */ protected function runSelect() { return $this->connection->select( $this->toSql(), $this->getBindings(), ! $this->useWritePdo ); } /** * @return \Illuminate\Support\Collection<int, \stdClass> */ public function get($columns = ['*']) { $items = new Collection($this->onceWithColumns(Arr::wrap($columns), function () { return $this->processor->processSelect($this, $this->runSelect()); })); return $this->applyAfterQueryCallbacks( isset($this->groupLimit) ? $this->withoutGroupLimitKeys($items) : $items ); if (is_null($original)) { $this->columns = $columns; } $result = $callback(); $this->columns = $original; return $result; } * @param array|string $columns * @return \Illuminate\Support\Collection<int, \stdClass> */ public function get($columns = ['*']) { $items = new Collection($this->onceWithColumns(Arr::wrap($columns), function () { return $this->processor->processSelect($this, $this->runSelect()); })); return $this->applyAfterQueryCallbacks( isset($this->groupLimit) ? $this->withoutGroupLimitKeys($items) : $items * @return array<int, TModel> */ public function getModels($columns = ['*']) { return $this->model->hydrate( $this->query->get($columns)->all() )->all(); } /** * Eager load the relationships for the models. $builder = $this->applyScopes(); // If we actually found models we will also eager load any relationships that // have been specified as needing to be eager loaded, which will solve the // n+1 query issue for the developers to avoid running a lot of queries. if (count($models = $builder->getModels($columns)) > 0) { $models = $builder->eagerLoadRelations($models); } return $this->applyAfterQueryCallbacks( $builder->getModel()->newCollection($models) /** @inheritDoc */ public function getResults() { return ! is_null($this->getParentKey()) ? $this->query->get() : $this->related->newCollection(); } /** @inheritDoc */ public function initRelation(array $models, $relation) throw new LogicException(sprintf( '%s::%s must return a relationship instance.', static::class, $method )); } return tap($relation->getResults(), function ($results) use ($method) { $this->setRelation($method, $results); }); } /** } // If the "attribute" exists as a method on the model, we will just assume // it is a relationship and will load and return results from the query // and hydrate the relationship's value on the "relationships" array. return $this->getRelationshipFromMethod($key); } /** * Determine if the given key is a relationship method on the model. * if (method_exists(self::class, $key)) { return $this->throwMissingAttributeExceptionIfApplicable($key); } return $this->isRelation($key) || $this->relationLoaded($key) ? $this->getRelationValue($key) : $this->throwMissingAttributeExceptionIfApplicable($key); } /** * Either throw a missing attribute exception or return null depending on Eloquent's configuration. } return $this->getAttributeOrFallback($locale, $attribute); } return parent::getAttribute($key); } public function getDefaultLocale(): ?string { return $this->defaultLocale; * @param string $key * @return mixed */ public function __get($key) { return $this->getAttribute($key); } /** * Dynamically set attributes on the model. * && $this->translation->getAttribute($this->getLocaleKey()) == $key ) { return $this->translation; } return $this->translations->firstWhere($this->getLocaleKey(), $key); } protected function toArrayAlwaysLoadsTranslations(): bool { return config('translatable.to_array_always_loads_translations', true); $configFallbackLocale = $this->getFallbackLocale(); $locale = $locale ?: $this->locale(); $withFallback = $withFallback === null ? $this->useFallback() : $withFallback; $fallbackLocale = $this->getFallbackLocale($locale); if ($translation = $this->getTranslationByLocaleKey($locale)) { return $translation; } if ($withFallback && $fallbackLocale) { if ($translation = $this->getTranslationByLocaleKey($fallbackLocale)) { public function getAttribute($key) { [$attribute, $locale] = $this->getAttributeAndLocale($key); if ($this->isTranslationAttribute($attribute)) { if ($this->getTranslation($locale) === null) { return $this->getAttributeValue($attribute); } // If the given $attribute has a mutator, we push it to $attributes and then call getAttributeValue // on it. This way, we can use Eloquent's checking for Mutation, type casting, and * @param string $key * @return mixed */ public function __get($key) { return $this->getAttribute($key); } /** * Dynamically set attributes on the model. *</div><div class="row g-5 mt--30"><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__currentLoopData = $services; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $service): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?> <div class="col-lg-3 col-md-4 col-sm-6 col-12"><!-- single course category --><a href="/<?php echo e(app()->getLocale()); ?>/services/<?php echo e($service->id); ?>/<?php echo e($service->name); ?>"class="single-category-2"><img src="<?php echo e(Storage::url($service->icon)); ?>" alt="<?php echo e($service->name); ?>"style="width: 100%; try { $component = ExtendBlade::currentRendering(); \Closure::bind(function () use ($__path, $__data) { extract($__data, EXTR_SKIP); include $__path; }, $component, $component)(); } catch (\Exception|\Throwable $e) { $this->handleViewException($e, $obLevel); } $component = ExtendBlade::currentRendering(); \Closure::bind(function () use ($__path, $__data) { extract($__data, EXTR_SKIP); include $__path; }, $component, $component)(); } catch (\Exception|\Throwable $e) { $this->handleViewException($e, $obLevel); } return ltrim(ob_get_clean()); // Once we have the path to the compiled file, we will evaluate the paths with // typical PHP just like any other templates. We also keep a stack of views // which have been rendered for right exception messages to be generated. try { $results = $this->evaluatePath($this->compiler->getCompiledPath($path), $data); } catch (ViewException $e) { if (! Str::of($e->getMessage())->contains(['No such file or directory', 'File does not exist at path'])) { throw $e; } $currentComponent = ExtendBlade::currentRendering(); trigger('view:compile', $currentComponent, $path); return parent::get($path, $data); } protected function evaluatePath($__path, $__data) { if (! ExtendBlade::isRenderingLivewireComponent()) { * * @return string */ protected function getContents() { return $this->engine->get($this->path, $this->gatherData()); } /** * Get the data bound to the view instance. * // clear out the sections for any separate views that may be rendered. $this->factory->incrementRender(); $this->factory->callComposer($this); $contents = $this->getContents(); // Once we've finished rendering the view, we'll decrement the render count // so that each section gets flushed out next time a view is created and // no old sections are staying around in the memory of an environment. $this->factory->decrementRender(); * @throws \Throwable */ public function render(?callable $callback = null) { try { $contents = $this->renderContents(); $response = isset($callback) ? $callback($this, $contents) : null; // Once we have the contents of the view, we will flush the sections if we are // done rendering all views so that there is nothing left hanging over when $revertA = Utils::shareWithViews('__livewire', $component); $revertB = Utils::shareWithViews('_instance', $component); // @deprecated $viewContext = new ViewContext; $html = $view->render(function ($view) use ($viewContext) { // Extract leftover slots, sections, and pushes before they get flushed... $viewContext->extractFromEnvironment($view->getFactory()); }); $revertA(); $revertB(); protected function trackInRenderStack($component, $callback) { array_push(static::$renderStack, $component); return tap($callback(), function () { array_pop(static::$renderStack); }); } protected function updateProperties($component, $updates, $data, $context) ]); } [ $view, $properties ] = $this->getView($component); return $this->trackInRenderStack($component, function () use ($component, $view, $properties) { $finish = trigger('render', $component, $view, $properties); $revertA = Utils::shareWithViews('__livewire', $component); $revertB = Utils::shareWithViews('_instance', $component); // @deprecated if (config('app.debug')) $start = microtime(true); $finish = trigger('mount', $component, $params, $key, $parent); if (config('app.debug')) trigger('profile', 'mount', $component->getId(), [$start, microtime(true)]); if (config('app.debug')) $start = microtime(true); $html = $this->render($component, '<div></div>'); if (config('app.debug')) trigger('profile', 'render', $component->getId(), [$start, microtime(true)]); if (config('app.debug')) $start = microtime(true); trigger('dehydrate', $component, $context); return app(ComponentRegistry::class)->resolveMissingComponent($resolver); } function mount($name, $params = [], $key = null) { return app(HandleComponents::class)->mount($name, $params, $key); } function snapshot($component, $context = null) { return app(HandleComponents::class)->snapshot($component, $context); $html = null; $layoutConfig = SupportPageComponents::interceptTheRenderOfTheComponentAndRetreiveTheLayoutConfiguration(function () use (&$html) { $params = SupportPageComponents::gatherMountMethodParamsFromRouteParameters($this); $html = app('livewire')->mount($this::class, $params); }); $layoutConfig = $layoutConfig ?: new PageComponentConfig; $layoutConfig->normalizeViewNameAndParamsForBladeComponents(); }); on('render', $handler); on('render.placeholder', $handler); $callback(); off('render', $handler); off('render.placeholder', $handler); return $layoutConfig; // Here's we're hooking into the "__invoke" method being called on a component. // This way, users can pass Livewire components into Routes as if they were // simple invokable controllers. Ex: Route::get('...', SomeLivewireComponent::class); $html = null; $layoutConfig = SupportPageComponents::interceptTheRenderOfTheComponentAndRetreiveTheLayoutConfiguration(function () use (&$html) { $params = SupportPageComponents::gatherMountMethodParamsFromRouteParameters($this); $html = app('livewire')->mount($this::class, $params); }); if (method_exists($controller, 'callAction')) { return $controller->callAction($method, $parameters); } return $controller->{$method}(...array_values($parameters)); } /** * Resolve the parameters for the controller. * * * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException */ protected function runController() { return $this->controllerDispatcher()->dispatch( $this, $this->getController(), $this->getControllerMethod() ); } /** { $this->container = $this->container ?: new Container; try { if ($this->isControllerAction()) { return $this->runController(); } return $this->runCallable(); } catch (HttpResponseException $e) { return $e->getResponse(); return (new Pipeline($this->container)) ->send($request) ->through($middleware) ->then(fn ($request) => $this->prepareResponse( $request, $route->run() )); } /** * Gather the middleware for the given route with resolved class names. */ protected function prepareDestination(Closure $destination) { return function ($passable) use ($destination) { try { return $destination($passable); } catch (Throwable $e) { return $this->handleException($passable, $e); } }; } $footer_header=PageContent::whereIN('page', ['footer','header']) ->where('locale', app()->getLocale()) ->pluck('value', 'key') ->toArray(); View::share('footer_header', $footer_header); return $next($request); }} // since the object we're given was already a fully instantiated object. $parameters = [$passable, $stack]; } $carry = method_exists($pipe, $this->method) ? $pipe->{$this->method}(...$parameters) : $pipe(...$parameters); return $this->handleCarry($carry); } catch (Throwable $e) { return $this->handleException($passable, $e); App::setLocale($locale); // dd(0); // return redirect($locale . '/' . $request->path()); } return $next($request); }} // since the object we're given was already a fully instantiated object. $parameters = [$passable, $stack]; } $carry = method_exists($pipe, $this->method) ? $pipe->{$this->method}(...$parameters) : $pipe(...$parameters); return $this->handleCarry($carry); } catch (Throwable $e) { return $this->handleException($passable, $e); } throw $exception; } return $next($request); }} // since the object we're given was already a fully instantiated object. $parameters = [$passable, $stack]; } $carry = method_exists($pipe, $this->method) ? $pipe->{$this->method}(...$parameters) : $pipe(...$parameters); return $this->handleCarry($carry); } catch (Throwable $e) { return $this->handleException($passable, $e); $this->isReading($request) || $this->runningUnitTests() || $this->inExceptArray($request) || $this->tokensMatch($request) ) { return tap($next($request), function ($response) use ($request) { if ($this->shouldAddXsrfTokenCookie()) { $this->addCookieToResponse($request, $response); } }); } // since the object we're given was already a fully instantiated object. $parameters = [$passable, $stack]; } $carry = method_exists($pipe, $this->method) ? $pipe->{$this->method}(...$parameters) : $pipe(...$parameters); return $this->handleCarry($carry); } catch (Throwable $e) { return $this->handleException($passable, $e); // Putting the errors in the view for every view allows the developer to just // assume that some errors are always available, which is convenient since // they don't have to continually run checks for the presence of errors. return $next($request); }} // since the object we're given was already a fully instantiated object. $parameters = [$passable, $stack]; } $carry = method_exists($pipe, $this->method) ? $pipe->{$this->method}(...$parameters) : $pipe(...$parameters); return $this->handleCarry($carry); } catch (Throwable $e) { return $this->handleException($passable, $e); $this->startSession($request, $session) ); $this->collectGarbage($session); $response = $next($request); $this->storeCurrentUrl($request, $session); $this->addCookieToResponse($response, $session); if ($this->manager->shouldBlock() || ($request->route() instanceof Route && $request->route()->locksFor())) { return $this->handleRequestWhileBlocking($request, $session, $next); } return $this->handleStatefulRequest($request, $session, $next); } /** * Handle the given request within session state. * // since the object we're given was already a fully instantiated object. $parameters = [$passable, $stack]; } $carry = method_exists($pipe, $this->method) ? $pipe->{$this->method}(...$parameters) : $pipe(...$parameters); return $this->handleCarry($carry); } catch (Throwable $e) { return $this->handleException($passable, $e); * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $response = $next($request); foreach ($this->cookies->getQueuedCookies() as $cookie) { $response->headers->setCookie($cookie); } // since the object we're given was already a fully instantiated object. $parameters = [$passable, $stack]; } $carry = method_exists($pipe, $this->method) ? $pipe->{$this->method}(...$parameters) : $pipe(...$parameters); return $this->handleCarry($carry); } catch (Throwable $e) { return $this->handleException($passable, $e); * @param \Closure $next * @return \Symfony\Component\HttpFoundation\Response */ public function handle($request, Closure $next) { return $this->encrypt($next($this->decrypt($request))); } /** * Decrypt the cookies on the request. * // since the object we're given was already a fully instantiated object. $parameters = [$passable, $stack]; } $carry = method_exists($pipe, $this->method) ? $pipe->{$this->method}(...$parameters) : $pipe(...$parameters); return $this->handleCarry($carry); } catch (Throwable $e) { return $this->handleException($passable, $e); $pipeline = array_reduce( array_reverse($this->pipes()), $this->carry(), $this->prepareDestination($destination) ); try { return $pipeline($this->passable); } finally { if ($this->finally) { ($this->finally)($this->passable); } } $middleware = $shouldSkipMiddleware ? [] : $this->gatherRouteMiddleware($route); return (new Pipeline($this->container)) ->send($request) ->through($middleware) ->then(fn ($request) => $this->prepareResponse( $request, $route->run() )); } /** $request->setRouteResolver(fn () => $route); $this->events->dispatch(new RouteMatched($route, $request)); return $this->prepareResponse($request, $this->runRouteWithinStack($route, $request) ); } /** * Run the given route within a Stack "onion" instance. * @param \Illuminate\Http\Request $request * @return \Symfony\Component\HttpFoundation\Response */ public function dispatchToRoute(Request $request) { return $this->runRoute($request, $this->findRoute($request)); } /** * Find the route matching a given request. * */ public function dispatch(Request $request) { $this->currentRequest = $request; return $this->dispatchToRoute($request); } /** * Dispatch the request to a route and return the response. * protected function dispatchToRouter() { return function ($request) { $this->app->instance('request', $request); return $this->router->dispatch($request); }; } /** * Call the terminate method on any terminable middleware. */ protected function prepareDestination(Closure $destination) { return function ($passable) use ($destination) { try { return $destination($passable); } catch (Throwable $e) { return $this->handleException($passable, $e); } }; } * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $response = $next($request); if ($response instanceof Response && SupportDisablingBackButtonCache::$disableBackButtonCache){ $response->headers->add([ 'Pragma' => 'no-cache', 'Expires' => 'Fri, 01 Jan 1990 00:00:00 GMT', // since the object we're given was already a fully instantiated object. $parameters = [$passable, $stack]; } $carry = method_exists($pipe, $this->method) ? $pipe->{$this->method}(...$parameters) : $pipe(...$parameters); return $this->handleCarry($carry); } catch (Throwable $e) { return $this->handleException($passable, $e); */ public function handle($request, Closure $next) { $this->clean($request); return $next($request); } /** * Clean the request's data. * if ($callback($request)) { return $next($request); } } return parent::handle($request, $next); } /** * Transform the given value. * // since the object we're given was already a fully instantiated object. $parameters = [$passable, $stack]; } $carry = method_exists($pipe, $this->method) ? $pipe->{$this->method}(...$parameters) : $pipe(...$parameters); return $this->handleCarry($carry); } catch (Throwable $e) { return $this->handleException($passable, $e); */ public function handle($request, Closure $next) { $this->clean($request); return $next($request); } /** * Clean the request's data. * if ($callback($request)) { return $next($request); } } return parent::handle($request, $next); } /** * Transform the given value. * // since the object we're given was already a fully instantiated object. $parameters = [$passable, $stack]; } $carry = method_exists($pipe, $this->method) ? $pipe->{$this->method}(...$parameters) : $pipe(...$parameters); return $this->handleCarry($carry); } catch (Throwable $e) { return $this->handleException($passable, $e); if ($max > 0 && $request->server('CONTENT_LENGTH') > $max) { throw new PostTooLargeException('The POST data is too large.'); } return $next($request); } /** * Determine the server 'post_max_size' as bytes. * // since the object we're given was already a fully instantiated object. $parameters = [$passable, $stack]; } $carry = method_exists($pipe, $this->method) ? $pipe->{$this->method}(...$parameters) : $pipe(...$parameters); return $this->handleCarry($carry); } catch (Throwable $e) { return $this->handleException($passable, $e); null, $this->getHeaders($data) ); } return $next($request); } /** * Determine if the incoming request has a maintenance mode bypass cookie. * // since the object we're given was already a fully instantiated object. $parameters = [$passable, $stack]; } $carry = method_exists($pipe, $this->method) ? $pipe->{$this->method}(...$parameters) : $pipe(...$parameters); return $this->handleCarry($carry); } catch (Throwable $e) { return $this->handleException($passable, $e); * @return \Illuminate\Http\Response */ public function handle($request, Closure $next) { if (! $this->hasMatchingPath($request)) { return $next($request); } $this->cors->setOptions($this->container['config']->get('cors', [])); if ($this->cors->isPreflightRequest($request)) { // since the object we're given was already a fully instantiated object. $parameters = [$passable, $stack]; } $carry = method_exists($pipe, $this->method) ? $pipe->{$this->method}(...$parameters) : $pipe(...$parameters); return $this->handleCarry($carry); } catch (Throwable $e) { return $this->handleException($passable, $e); { $request::setTrustedProxies([], $this->getTrustedHeaderNames()); $this->setTrustedProxyIpAddresses($request); return $next($request); } /** * Sets the trusted proxies on the request. * // since the object we're given was already a fully instantiated object. $parameters = [$passable, $stack]; } $carry = method_exists($pipe, $this->method) ? $pipe->{$this->method}(...$parameters) : $pipe(...$parameters); return $this->handleCarry($carry); } catch (Throwable $e) { return $this->handleException($passable, $e); * @param \Closure $next * @return \Symfony\Component\HttpFoundation\Response */ public function handle(Request $request, Closure $next) { return $next($request); } /** * Invoke the deferred callbacks. * // since the object we're given was already a fully instantiated object. $parameters = [$passable, $stack]; } $carry = method_exists($pipe, $this->method) ? $pipe->{$this->method}(...$parameters) : $pipe(...$parameters); return $this->handleCarry($carry); } catch (Throwable $e) { return $this->handleException($passable, $e); $pipeline = array_reduce( array_reverse($this->pipes()), $this->carry(), $this->prepareDestination($destination) ); try { return $pipeline($this->passable); } finally { if ($this->finally) { ($this->finally)($this->passable); } } $this->bootstrap(); return (new Pipeline($this->app)) ->send($request) ->through($this->app->shouldSkipMiddleware() ? [] : $this->middleware) ->then($this->dispatchToRouter()); } /** * Bootstrap the application for HTTP requests. * $this->requestStartedAt = Carbon::now(); try { $request->enableHttpMethodParameterOverride(); $response = $this->sendRequestThroughRouter($request); } catch (Throwable $e) { $this->reportException($e); $response = $this->renderException($request, $e); } */ public function handleRequest(Request $request) { $kernel = $this->make(HttpKernelContract::class); $response = $kernel->handle($request)->send(); $kernel->terminate($request, $response); } /**// Register the Composer autoloader...require __DIR__.'/../vendor/autoload.php';// Bootstrap Laravel and handle the request...(require_once __DIR__.'/../bootstrap/app.php') ->handleRequest(Request::capture()); * @return \PDO */ protected function createPdoConnection($dsn, $username, #[\SensitiveParameter] $password, $options) { return version_compare(phpversion(), '8.4.0', '<') ? new PDO($dsn, $username, $password, $options) : PDO::connect($dsn, $username, $password, $options); /** @phpstan-ignore staticMethod.notFound (PHP 8.4) */ } /** * Handle an exception that occurred during connect execution. * @return \PDO */ protected function createPdoConnection($dsn, $username, #[\SensitiveParameter] $password, $options) { return version_compare(phpversion(), '8.4.0', '<') ? new PDO($dsn, $username, $password, $options) : PDO::connect($dsn, $username, $password, $options); /** @phpstan-ignore staticMethod.notFound (PHP 8.4) */ } /** * Handle an exception that occurred during connect execution. [$username, $password] = [ $config['username'] ?? null, $config['password'] ?? null, ]; try { return $this->createPdoConnection( $dsn, $username, $password, $options ); } catch (Exception $e) { return $this->tryAgainIfCausedByLostConnection( $e, $dsn, $username, $password, $options */ public function connect(array $config) { $options = $this->getOptions($config); $connection = $this->createConnection($this->getDsn($config), $config, $options); $this->configureIsolationLevel($connection, $config); return $connection; } return function () use ($config) { foreach (Arr::shuffle($this->parseHosts($config)) as $host) { $config['host'] = $host; try { return $this->createConnector($config)->connect($config); } catch (PDOException $e) { continue; } } * @return \PDO */ public function getPdo() { if ($this->pdo instanceof Closure) { return $this->pdo = call_user_func($this->pdo); } return $this->pdo; } if ($this->readPdo instanceof Closure) { return $this->readPdo = call_user_func($this->readPdo); } return $this->readPdo ?: $this->getPdo(); } /** * Get the current read PDO connection parameter without executing any reconnect logic. * * @param bool $useReadPdo * @return \PDO */ protected function getPdoForSelect($useReadPdo = true) { return $useReadPdo ? $this->getReadPdo() : $this->getPdo(); } /** * Run an insert statement against the database. * // For select statements, we'll simply execute the query and return an array // of the database result set. Each element in the array will be a single // row from the database table, and will either be an array or objects. $statement = $this->prepared( $this->getPdoForSelect($useReadPdo)->prepare($query) ); $this->bindValues($statement, $this->prepareBindings($bindings)); $statement->execute(); { // To execute the statement, we'll simply call the callback, which will actually // run the SQL against the PDO connection. Then we can calculate the time it // took to execute and log the query SQL, bindings and time in our memory. try { return $callback($query, $bindings); } // If an exception occurs when attempting to run a query, we'll format the error // message to include the bindings with SQL, which will make this exception a // lot more helpful to the developer instead of just the database's errors. protected function tryAgainIfCausedByLostConnection(QueryException $e, $query, $bindings, Closure $callback) { if ($this->causedByLostConnection($e->getPrevious())) { $this->reconnect(); return $this->runQueryCallback($query, $bindings, $callback); } throw $e; } { if ($this->transactions >= 1) { throw $e; } return $this->tryAgainIfCausedByLostConnection( $e, $query, $bindings, $callback ); } /** // caused by a connection that has been lost. If that is the cause, we'll try // to re-establish connection and re-run the query with a fresh connection. try { $result = $this->runQueryCallback($query, $bindings, $callback); } catch (QueryException $e) { $result = $this->handleQueryException( $e, $query, $bindings, $callback ); } // Once we have run the query we will calculate the time that it took to run and * @param bool $useReadPdo * @return array */ public function select($query, $bindings = [], $useReadPdo = true) { return $this->run($query, $bindings, function ($query, $bindings) use ($useReadPdo) { if ($this->pretending()) { return []; } // For select statements, we'll simply execute the query and return an array * * @return array */ protected function runSelect() { return $this->connection->select( $this->toSql(), $this->getBindings(), ! $this->useWritePdo ); } /** * @return \Illuminate\Support\Collection<int, \stdClass> */ public function get($columns = ['*']) { $items = new Collection($this->onceWithColumns(Arr::wrap($columns), function () { return $this->processor->processSelect($this, $this->runSelect()); })); return $this->applyAfterQueryCallbacks( isset($this->groupLimit) ? $this->withoutGroupLimitKeys($items) : $items );<?php
namespace Illuminate\Database\Query;
use BackedEnum;
use Carbon\CarbonPeriod;
use Closure;
use DateTimeInterface;
use Illuminate\Contracts\Database\Query\Builder as BuilderContract;
use Illuminate\Contracts\Database\Query\ConditionExpression;
use Illuminate\Contracts\Database\Query\Expression as ExpressionContract;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Database\Concerns\BuildsQueries;
use Illuminate\Database\Concerns\BuildsWhereDateClauses;
use Illuminate\Database\Concerns\ExplainsQueries;
use Illuminate\Database\ConnectionInterface;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Database\Query\Grammars\Grammar;
use Illuminate\Database\Query\Processors\Processor;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\LazyCollection;
use Illuminate\Support\Str;
use Illuminate\Support\Traits\ForwardsCalls;
use Illuminate\Support\Traits\Macroable;
use InvalidArgumentException;
use LogicException;
use RuntimeException;
use UnitEnum;
use function Illuminate\Support\enum_value;
class Builder implements BuilderContract
{
/** @use \Illuminate\Database\Concerns\BuildsQueries<object> */
use BuildsWhereDateClauses, BuildsQueries, ExplainsQueries, ForwardsCalls, Macroable {
__call as macroCall;
}
/**
* The database connection instance.
*
* @var \Illuminate\Database\ConnectionInterface
*/
public $connection;
/**
* The database query grammar instance.
*
* @var \Illuminate\Database\Query\Grammars\Grammar
*/
public $grammar;
/**
* The database query post processor instance.
*
* @var \Illuminate\Database\Query\Processors\Processor
*/
public $processor;
/**
* The current query value bindings.
*
* @var array
*/
public $bindings = [
'select' => [],
'from' => [],
'join' => [],
'where' => [],
'groupBy' => [],
'having' => [],
'order' => [],
'union' => [],
'unionOrder' => [],
];
/**
* An aggregate function and column to be run.
*
* @var array|null
*/
public $aggregate;
/**
* The columns that should be returned.
*
* @var array|null
*/
public $columns;
/**
* Indicates if the query returns distinct results.
*
* Occasionally contains the columns that should be distinct.
*
* @var bool|array
*/
public $distinct = false;
/**
* The table which the query is targeting.
*
* @var \Illuminate\Database\Query\Expression|string
*/
public $from;
/**
* The index hint for the query.
*
* @var \Illuminate\Database\Query\IndexHint|null
*/
public $indexHint;
/**
* The table joins for the query.
*
* @var array|null
*/
public $joins;
/**
* The where constraints for the query.
*
* @var array
*/
public $wheres = [];
/**
* The groupings for the query.
*
* @var array|null
*/
public $groups;
/**
* The having constraints for the query.
*
* @var array|null
*/
public $havings;
/**
* The orderings for the query.
*
* @var array|null
*/
public $orders;
/**
* The maximum number of records to return.
*
* @var int|null
*/
public $limit;
/**
* The maximum number of records to return per group.
*
* @var array|null
*/
public $groupLimit;
/**
* The number of records to skip.
*
* @var int|null
*/
public $offset;
/**
* The query union statements.
*
* @var array|null
*/
public $unions;
/**
* The maximum number of union records to return.
*
* @var int|null
*/
public $unionLimit;
/**
* The number of union records to skip.
*
* @var int|null
*/
public $unionOffset;
/**
* The orderings for the union query.
*
* @var array|null
*/
public $unionOrders;
/**
* Indicates whether row locking is being used.
*
* @var string|bool|null
*/
public $lock;
/**
* The callbacks that should be invoked before the query is executed.
*
* @var array
*/
public $beforeQueryCallbacks = [];
/**
* The callbacks that should be invoked after retrieving data from the database.
*
* @var array
*/
protected $afterQueryCallbacks = [];
/**
* All of the available clause operators.
*
* @var string[]
*/
public $operators = [
'=', '<', '>', '<=', '>=', '<>', '!=', '<=>',
'like', 'like binary', 'not like', 'ilike',
'&', '|', '^', '<<', '>>', '&~', 'is', 'is not',
'rlike', 'not rlike', 'regexp', 'not regexp',
'~', '~*', '!~', '!~*', 'similar to',
'not similar to', 'not ilike', '~~*', '!~~*',
];
/**
* All of the available bitwise operators.
*
* @var string[]
*/
public $bitwiseOperators = [
'&', '|', '^', '<<', '>>', '&~',
];
/**
* Whether to use write pdo for the select.
*
* @var bool
*/
public $useWritePdo = false;
/**
* Create a new query builder instance.
*
* @return void
*/
public function __construct(
ConnectionInterface $connection,
?Grammar $grammar = null,
?Processor $processor = null,
) {
$this->connection = $connection;
$this->grammar = $grammar ?: $connection->getQueryGrammar();
$this->processor = $processor ?: $connection->getPostProcessor();
}
/**
* Set the columns to be selected.
*
* @param array|mixed $columns
* @return $this
*/
public function select($columns = ['*'])
{
$this->columns = [];
$this->bindings['select'] = [];
$columns = is_array($columns) ? $columns : func_get_args();
foreach ($columns as $as => $column) {
if (is_string($as) && $this->isQueryable($column)) {
$this->selectSub($column, $as);
} else {
$this->columns[] = $column;
}
}
return $this;
}
/**
* Add a subselect expression to the query.
*
* @param \Closure|\Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder<*>|string $query
* @param string $as
* @return $this
*
* @throws \InvalidArgumentException
*/
public function selectSub($query, $as)
{
[$query, $bindings] = $this->createSub($query);
return $this->selectRaw(
'('.$query.') as '.$this->grammar->wrap($as), $bindings
);
}
/**
* Add a new "raw" select expression to the query.
*
* @param string $expression
* @return $this
*/
public function selectRaw($expression, array $bindings = [])
{
$this->addSelect(new Expression($expression));
if ($bindings) {
$this->addBinding($bindings, 'select');
}
return $this;
}
/**
* Makes "from" fetch from a subquery.
*
* @param \Closure|\Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder<*>|string $query
* @param string $as
* @return $this
*
* @throws \InvalidArgumentException
*/
public function fromSub($query, $as)
{
[$query, $bindings] = $this->createSub($query);
return $this->fromRaw('('.$query.') as '.$this->grammar->wrapTable($as), $bindings);
}
/**
* Add a raw from clause to the query.
*
* @param string $expression
* @param mixed $bindings
* @return $this
*/
public function fromRaw($expression, $bindings = [])
{
$this->from = new Expression($expression);
$this->addBinding($bindings, 'from');
return $this;
}
/**
* Creates a subquery and parse it.
*
* @param \Closure|\Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder<*>|string $query
* @return array
*/
protected function createSub($query)
{
// If the given query is a Closure, we will execute it while passing in a new
// query instance to the Closure. This will give the developer a chance to
// format and work with the query before we cast it to a raw SQL string.
if ($query instanceof Closure) {
$callback = $query;
$callback($query = $this->forSubQuery());
}
return $this->parseSub($query);
}
/**
* Parse the subquery into SQL and bindings.
*
* @param mixed $query
* @return array
*
* @throws \InvalidArgumentException
*/
protected function parseSub($query)
{
if ($query instanceof self || $query instanceof EloquentBuilder || $query instanceof Relation) {
$query = $this->prependDatabaseNameIfCrossDatabaseQuery($query);
return [$query->toSql(), $query->getBindings()];
} elseif (is_string($query)) {
return [$query, []];
} else {
throw new InvalidArgumentException(
'A subquery must be a query builder instance, a Closure, or a string.'
);
}
}
/**
* Prepend the database name if the given query is on another database.
*
* @param mixed $query
* @return mixed
*/
protected function prependDatabaseNameIfCrossDatabaseQuery($query)
{
if ($query->getConnection()->getDatabaseName() !==
$this->getConnection()->getDatabaseName()) {
$databaseName = $query->getConnection()->getDatabaseName();
if (! str_starts_with($query->from, $databaseName) && ! str_contains($query->from, '.')) {
$query->from($databaseName.'.'.$query->from);
}
}
return $query;
}
/**
* Add a new select column to the query.
*
* @param array|mixed $column
* @return $this
*/
public function addSelect($column)
{
$columns = is_array($column) ? $column : func_get_args();
foreach ($columns as $as => $column) {
if (is_string($as) && $this->isQueryable($column)) {
if (is_null($this->columns)) {
$this->select($this->from.'.*');
}
$this->selectSub($column, $as);
} else {
if (is_array($this->columns) && in_array($column, $this->columns, true)) {
continue;
}
$this->columns[] = $column;
}
}
return $this;
}
/**
* Force the query to only return distinct results.
*
* @return $this
*/
public function distinct()
{
$columns = func_get_args();
if (count($columns) > 0) {
$this->distinct = is_array($columns[0]) || is_bool($columns[0]) ? $columns[0] : $columns;
} else {
$this->distinct = true;
}
return $this;
}
/**
* Set the table which the query is targeting.
*
* @param \Closure|\Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder<*>|\Illuminate\Contracts\Database\Query\Expression|string $table
* @param string|null $as
* @return $this
*/
public function from($table, $as = null)
{
if ($this->isQueryable($table)) {
return $this->fromSub($table, $as);
}
$this->from = $as ? "{$table} as {$as}" : $table;
return $this;
}
/**
* Add an index hint to suggest a query index.
*
* @param string $index
* @return $this
*/
public function useIndex($index)
{
$this->indexHint = new IndexHint('hint', $index);
return $this;
}
/**
* Add an index hint to force a query index.
*
* @param string $index
* @return $this
*/
public function forceIndex($index)
{
$this->indexHint = new IndexHint('force', $index);
return $this;
}
/**
* Add an index hint to ignore a query index.
*
* @param string $index
* @return $this
*/
public function ignoreIndex($index)
{
$this->indexHint = new IndexHint('ignore', $index);
return $this;
}
/**
* Add a join clause to the query.
*
* @param \Illuminate\Contracts\Database\Query\Expression|string $table
* @param \Closure|\Illuminate\Contracts\Database\Query\Expression|string $first
* @param string|null $operator
* @param \Illuminate\Contracts\Database\Query\Expression|string|null $second
* @param string $type
* @param bool $where
* @return $this
*/
public function join($table, $first, $operator = null, $second = null, $type = 'inner', $where = false)
{
$join = $this->newJoinClause($this, $type, $table);
// If the first "column" of the join is really a Closure instance the developer
// is trying to build a join with a complex "on" clause containing more than
// one condition, so we'll add the join and call a Closure with the query.
if ($first instanceof Closure) {
$first($join);
$this->joins[] = $join;
$this->addBinding($join->getBindings(), 'join');
}
// If the column is simply a string, we can assume the join simply has a basic
// "on" clause with a single condition. So we will just build the join with
// this simple join clauses attached to it. There is not a join callback.
else {
$method = $where ? 'where' : 'on';
$this->joins[] = $join->$method($first, $operator, $second);
$this->addBinding($join->getBindings(), 'join');
}
return $this;
}
/**
* Add a "join where" clause to the query.
*
* @param \Illuminate\Contracts\Database\Query\Expression|string $table
* @param \Closure|\Illuminate\Contracts\Database\Query\Expression|string $first
* @param string $operator
* @param \Illuminate\Contracts\Database\Query\Expression|string $second
* @param string $type
* @return $this
*/
public function joinWhere($table, $first, $operator, $second, $type = 'inner')
{
return $this->join($table, $first, $operator, $second, $type, true);
}
/**
* Add a subquery join clause to the query.
*
* @param \Closure|\Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder<*>|string $query
* @param string $as
* @param \Closure|\Illuminate\Contracts\Database\Query\Expression|string $first
* @param string|null $operator
* @param \Illuminate\Contracts\Database\Query\Expression|string|null $second
* @param string $type
* @param bool $where
* @return $this
*
* @throws \InvalidArgumentException
*/
public function joinSub($query, $as, $first, $operator = null, $second = null, $type = 'inner', $where = false)
{
[$query, $bindings] = $this->createSub($query);
$expression = '('.$query.') as '.$this->grammar->wrapTable($as);
$this->addBinding($bindings, 'join');
return $this->join(new Expression($expression), $first, $operator, $second, $type, $where);
}
/**
* Add a lateral join clause to the query.
*
* @param \Closure|\Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder<*>|string $query
* @return $this
*/
public function joinLateral($query, string $as, string $type = 'inner')
{
[$query, $bindings] = $this->createSub($query);
$expression = '('.$query.') as '.$this->grammar->wrapTable($as);
$this->addBinding($bindings, 'join');
$this->joins[] = $this->newJoinLateralClause($this, $type, new Expression($expression));
return $this;
}
/**
* Add a lateral left join to the query.
*
* @param \Closure|\Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder<*>|string $query
* @return $this
*/
public function leftJoinLateral($query, string $as)
{
return $this->joinLateral($query, $as, 'left');
}
/**
* Add a left join to the query.
*
* @param \Illuminate\Contracts\Database\Query\Expression|string $table
* @param \Closure|\Illuminate\Contracts\Database\Query\Expression|string $first
* @param string|null $operator
* @param \Illuminate\Contracts\Database\Query\Expression|string|null $second
* @return $this
*/
public function leftJoin($table, $first, $operator = null, $second = null)
{
return $this->join($table, $first, $operator, $second, 'left');
}
/**
* Add a "join where" clause to the query.
*
* @param \Illuminate\Contracts\Database\Query\Expression|string $table
* @param \Closure|\Illuminate\Contracts\Database\Query\Expression|string $first
* @param string $operator
* @param \Illuminate\Contracts\Database\Query\Expression|string|null $second
* @return $this
*/
public function leftJoinWhere($table, $first, $operator, $second)
{
return $this->joinWhere($table, $first, $operator, $second, 'left');
}
/**
* Add a subquery left join to the query.
*
* @param \Closure|\Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder<*>|string $query
* @param string $as
* @param \Closure|\Illuminate\Contracts\Database\Query\Expression|string $first
* @param string|null $operator
* @param \Illuminate\Contracts\Database\Query\Expression|string|null $second
* @return $this
*/
public function leftJoinSub($query, $as, $first, $operator = null, $second = null)
{
return $this->joinSub($query, $as, $first, $operator, $second, 'left');
}
/**
* Add a right join to the query.
*
* @param \Illuminate\Contracts\Database\Query\Expression|string $table
* @param \Closure|string $first
* @param string|null $operator
* @param \Illuminate\Contracts\Database\Query\Expression|string|null $second
* @return $this
*/
public function rightJoin($table, $first, $operator = null, $second = null)
{
return $this->join($table, $first, $operator, $second, 'right');
}
/**
* Add a "right join where" clause to the query.
*
* @param \Illuminate\Contracts\Database\Query\Expression|string $table
* @param \Closure|\Illuminate\Contracts\Database\Query\Expression|string $first
* @param string $operator
* @param \Illuminate\Contracts\Database\Query\Expression|string $second
* @return $this
*/
public function rightJoinWhere($table, $first, $operator, $second)
{
return $this->joinWhere($table, $first, $operator, $second, 'right');
}
/**
* Add a subquery right join to the query.
*
* @param \Closure|\Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder<*>|string $query
* @param string $as
* @param \Closure|\Illuminate\Contracts\Database\Query\Expression|string $first
* @param string|null $operator
* @param \Illuminate\Contracts\Database\Query\Expression|string|null $second
* @return $this
*/
public function rightJoinSub($query, $as, $first, $operator = null, $second = null)
{
return $this->joinSub($query, $as, $first, $operator, $second, 'right');
}
/**
* Add a "cross join" clause to the query.
*
* @param \Illuminate\Contracts\Database\Query\Expression|string $table
* @param \Closure|\Illuminate\Contracts\Database\Query\Expression|string|null $first
* @param string|null $operator
* @param \Illuminate\Contracts\Database\Query\Expression|string|null $second
* @return $this
*/
public function crossJoin($table, $first = null, $operator = null, $second = null)
{
if ($first) {
return $this->join($table, $first, $operator, $second, 'cross');
}
$this->joins[] = $this->newJoinClause($this, 'cross', $table);
return $this;
}
/**
* Add a subquery cross join to the query.
*
* @param \Closure|\Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder<*>|string $query
* @param string $as
* @return $this
*/
public function crossJoinSub($query, $as)
{
[$query, $bindings] = $this->createSub($query);
$expression = '('.$query.') as '.$this->grammar->wrapTable($as);
$this->addBinding($bindings, 'join');
$this->joins[] = $this->newJoinClause($this, 'cross', new Expression($expression));
return $this;
}
/**
* Get a new join clause.
*
* @param string $type
* @param \Illuminate\Contracts\Database\Query\Expression|string $table
* @return \Illuminate\Database\Query\JoinClause
*/
protected function newJoinClause(self $parentQuery, $type, $table)
{
return new JoinClause($parentQuery, $type, $table);
}
/**
* Get a new join lateral clause.
*
* @param string $type
* @param \Illuminate\Contracts\Database\Query\Expression|string $table
* @return \Illuminate\Database\Query\JoinLateralClause
*/
protected function newJoinLateralClause(self $parentQuery, $type, $table)
{
return new JoinLateralClause($parentQuery, $type, $table);
}
/**
* Merge an array of where clauses and bindings.
*
* @param array $wheres
* @param array $bindings
* @return $this
*/
public function mergeWheres($wheres, $bindings)
{
$this->wheres = array_merge($this->wheres, (array) $wheres);
$this->bindings['where'] = array_values(
array_merge($this->bindings['where'], (array) $bindings)
);
return $this;
}
/**
* Add a basic where clause to the query.
*
* @param \Closure|string|array|\Illuminate\Contracts\Database\Query\Expression $column
* @param mixed $operator
* @param mixed $value
* @param string $boolean
* @return $this
*/
public function where($column, $operator = null, $value = null, $boolean = 'and')
{
if ($column instanceof ConditionExpression) {
$type = 'Expression';
$this->wheres[] = compact('type', 'column', 'boolean');
return $this;
}
// If the column is an array, we will assume it is an array of key-value pairs
// and can add them each as a where clause. We will maintain the boolean we
// received when the method was called and pass it into the nested where.
if (is_array($column)) {
return $this->addArrayOfWheres($column, $boolean);
}
// Here we will make some assumptions about the operator. If only 2 values are
// passed to the method, we will assume that the operator is an equals sign
// and keep going. Otherwise, we'll require the operator to be passed in.
[$value, $operator] = $this->prepareValueAndOperator(
$value, $operator, func_num_args() === 2
);
// If the column is actually a Closure instance, we will assume the developer
// wants to begin a nested where statement which is wrapped in parentheses.
// We will add that Closure to the query and return back out immediately.
if ($column instanceof Closure && is_null($operator)) {
return $this->whereNested($column, $boolean);
}
// If the column is a Closure instance and there is an operator value, we will
// assume the developer wants to run a subquery and then compare the result
// of that subquery with the given value that was provided to the method.
if ($this->isQueryable($column) && ! is_null($operator)) {
[$sub, $bindings] = $this->createSub($column);
return $this->addBinding($bindings, 'where')
->where(new Expression('('.$sub.')'), $operator, $value, $boolean);
}
// If the given operator is not found in the list of valid operators we will
// assume that the developer is just short-cutting the '=' operators and
// we will set the operators to '=' and set the values appropriately.
if ($this->invalidOperator($operator)) {
[$value, $operator] = [$operator, '='];
}
// If the value is a Closure, it means the developer is performing an entire
// sub-select within the query and we will need to compile the sub-select
// within the where clause to get the appropriate query record results.
if ($this->isQueryable($value)) {
return $this->whereSub($column, $operator, $value, $boolean);
}
// If the value is "null", we will just assume the developer wants to add a
// where null clause to the query. So, we will allow a short-cut here to
// that method for convenience so the developer doesn't have to check.
if (is_null($value)) {
return $this->whereNull($column, $boolean, $operator !== '=');
}
$type = 'Basic';
$columnString = ($column instanceof ExpressionContract)
? $this->grammar->getValue($column)
: $column;
// If the column is making a JSON reference we'll check to see if the value
// is a boolean. If it is, we'll add the raw boolean string as an actual
// value to the query to ensure this is properly handled by the query.
if (str_contains($columnString, '->') && is_bool($value)) {
$value = new Expression($value ? 'true' : 'false');
if (is_string($column)) {
$type = 'JsonBoolean';
}
}
if ($this->isBitwiseOperator($operator)) {
$type = 'Bitwise';
}
// Now that we are working with just a simple query we can put the elements
// in our array and add the query binding to our array of bindings that
// will be bound to each SQL statements when it is finally executed.
$this->wheres[] = compact