Example #1
1
 /**
  * @param array $with
  * @param string $by
  *
  * @return $this
  */
 public function withAndLatest($with = [], $by = 'created_at')
 {
     $this->model = tap($this->model->latest($by), function ($query) use($with) {
         if ($with) {
             $query->with($with);
         }
     });
     return $this;
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if (!$request->user() || !$request->session()) {
         return $next($request);
     }
     if (!$request->session()->has('password_hash') && $this->auth->viaRemember()) {
         $this->logout($request);
     }
     if (!$request->session()->has('password_hash')) {
         $this->storePasswordHashInSession($request);
     }
     if ($request->session()->get('password_hash') !== $request->user()->password) {
         $this->logout($request);
     }
     return tap($next($request), function () use($request) {
         $this->storePasswordHashInSession($request);
     });
 }
Example #3
1
 /**
  *
  * @param string $username
  * @param string $ip
  *
  * @return mixed
  */
 public function search($username, $ip)
 {
     $logs = tap($this->model->with('user'), function ($query) use($username, $ip) {
         if ($username && !$ip) {
             $query->join('users', function ($join) use($username) {
                 $join->where('users.username', 'like', $username . '%');
             });
         }
         if (!$username && $ip) {
             $query->where('operator_ip', 'like', $ip . '%');
         }
         if ($username && $ip) {
             $query->join('users', function ($join) use($username, $ip) {
                 $join->where('system_logs.operator_ip', 'like', $ip . '%')->where('users.username', 'like', $username . '%');
             });
         }
     })->paginate(getPerPageRows());
     return $logs;
 }
Example #4
1
 /**
  * Update a specific key in the configuration file.
  *
  * @param  string  $key
  * @param  mixed  $value
  * @return array
  */
 function updateKey($key, $value)
 {
     return tap($this->read(), function (&$config) use($key, $value) {
         $config[$key] = $value;
         $this->write($config);
     });
 }
Example #5
1
 /**
  * Get an item from the session, or store the default value.
  *
  * @param  string  $key
  * @param  \Closure  $callback
  * @return mixed
  */
 public function remember($key, Closure $callback)
 {
     if (!is_null($value = $this->get($key))) {
         return $value;
     }
     return tap($callback(), function ($value) use($key) {
         $this->put($key, $value);
     });
 }
Example #6
0
 /**
  * Render the current component.
  *
  * @return string
  */
 public function renderComponent()
 {
     $contents = ob_get_clean();
     $name = array_pop($this->componentStack);
     $baseData = $this->componentData[$name];
     $data = array_merge($baseData, ['slot' => new HtmlString(trim($contents))], $this->slots[$name]);
     return tap($this->make($name, $data)->render(), function () use($name) {
         unset($this->slots[$name]);
         unset($this->slotStack[$name]);
         unset($this->componentData[$name]);
     });
 }