Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP][Laravel] Czy da się użyć middleware w Web routes?
Johnas
post 26.02.2020, 23:39:51
Post #1





Grupa: Zarejestrowani
Postów: 650
Pomógł: 16
Dołączył: 5.07.2010
Skąd: Ściśle Tajne

Ostrzeżenie: (0%)
-----


Mam takie middlewares:
  1. <?php
  2.  
  3. namespace App\Http\Middleware;
  4.  
  5. use Closure;
  6.  
  7. class MinifyHtml
  8. {
  9. /**
  10.   * Handle an incoming request.
  11.   *
  12.   * @param \Illuminate\Http\Request $request
  13.   * @param \Closure $next
  14.   * @return mixed
  15.   */
  16.  
  17. public function minifyHTML($htmlString)
  18. {
  19. $replace = [
  20. '<!--(.*?)-->' => '', //remove comments
  21. "/<\?php/" => '<?php ',
  22. "/\n([\S])/" => '$1',
  23. "/\r/" => '', // remove carriage return
  24. "/\n/" => '', // remove new lines
  25. "/\t/" => '', // remove tab
  26. "/\s+/" => ' ', // remove spaces
  27. ];
  28. return preg_replace(array_keys($this->replace), array_values($this->replace), $htmlString);
  29. }
  30.  
  31. public function handle(Request $request, Closure $next) {
  32.  
  33. $response = $next($request);
  34. $content = $response->getContent();
  35. $output = $this->minifyHTML($content);
  36. $response->setContent($output);
  37. return $response;
  38. }
  39. }


i chciałbym użyć tego kodu w web routes:

  1. Route::get('/admin/', 'Admin@showSetup')->name("admin-index");


jak dodać to do tego fragmentu? Przepraszam jeśli zbytnio się nie orientuję... uczę się Laravela, a co dopiero to w nim raczkuję... Strasznie dziwne to dla mnie... Myślałem że znając komendy
  1. php artisan make:controller --LifeController


oraz
  1. php artisan make:migration create_the_guys_with_she_cheats_me_table --table=guys_with_she_cheats_me


oraz model
  1. php artisan make:model She


To mogę już wszystko w laravel, a jednak się myliłem smile.gif Ten post to tak pół żartem pół serio

Dobra... już wiem... middleware samo się importuje w praniu smile.gif


--------------------
Jak coś jest dobre, to nie znaczy że nie może być to lepsze - Ideały nie istnieją ;D
Strony internetowe Świnoujście
Go to the top of the page
+Quote Post
markonix
post 28.02.2020, 21:50:00
Post #2





Grupa: Zarejestrowani
Postów: 2 707
Pomógł: 290
Dołączył: 16.12.2008
Skąd: Śląsk

Ostrzeżenie: (0%)
-----


Ta minifikacja Ci nabruździ. To nie jest taka prosta sprawa, że wywalisz białe znaki, bo w niektórych elementach HTML one mają znaczenie, albo nawet są interpretowane. Komentarze można wywalić choć logiczniej i tak używać tych z blade.


--------------------
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 18.04.2024 - 05:09