LoginSignup
0
0

More than 1 year has passed since last update.

Laravelの404エラーページを、bladeの中だけで簡潔にフロントページと管理画面でデザイン変更したい

Posted at

シンプルに三項演算子とPHPを使って分岐を作ろう

通常はフロント用のレイアウト用の共通ファイルを、/resources/view/layoutsに入れて使っていればこのように書いているとします。
404エラーは、フロント用のデザインに404エラーを表示しますね。

404.blade.php
@extends('layouts.frontend')

フロントと管理画面で、404エラーのデザインを分けたいので、
管理画面用に別途用意した、admin_error.blade.phpを/resources/view/layoutsに入れておきます。

管理画面のURL(/admin)かどうかを
URIの2つめにadminが入っているURLかで
判別して、レイアウト共通ファイルを分岐させてやります。

404.blade.php
@extends((explode("/", $_SERVER['REQUEST_URI'])[1]=='admin'?'layouts.admin_error':'layouts.frontend'))

こんな感じで、三項演算子とPHPを使って、bladeの中だけで完結することも可能ですね。

0
0
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
0
0