LoginSignup
3
4

More than 5 years have passed since last update.

LaravelでPug(旧Jade)を使う

Last updated at Posted at 2018-04-12

bladeだけだと、html自体は素なので
Railsやってた時の様にhamlやslimっぽく書けたらなーと思って探してみた。

意外とこの手のやつは少なくて見つけたのはこちら。
GitHub - BKWLD/laravel-pug: Pug view adapter for Laravel and Lumen

環境

  • Laravel v5.6.6

インストール

README通り

$ composer require bkwld/laravel-pug
app/Exceptions/Handler.php
<?php                                                                                                                                                             

namespace App\Exceptions;

use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Auth\AuthenticationException;
+ use Bkwld\LaravelPug\ExceptionHandlerTrait;

class Handler extends ExceptionHandler
{
+   use ExceptionHandlerTrait;

    /**
     * A list of the exception types that are not reported.
     *
     * @var array
     */
    protected $dontReport = [
        //
    ];

    ...

   /**
     * Render an exception into an HTTP response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Exception  $exception
     * @return \Illuminate\Http\Response
     */
    public function render($request, Exception $exception)
    {
-       return parent::render($request, $exception);
+       return $this->filterErrorResponse($exception, $request, parent::render($request, $exception));
    }
}

テンプレート

index.pub.blade
html                                                                                                                                                              
head
  meta(charset="utf-8")
body
  h1 ユーザ一覧
  table
    @foreach($users as $user)
    tr
      td {{ $user->name }}
    @endforeach

簡潔で綺麗なテンプレートですね。

ただ実践投入してないので、速度的に少し心配です。

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4