0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Laravelでconfigによるステータス定義

Posted at

#configを作成する。

config/membership.php
<?php
return [
    'status' => ['representative' => '0', 'member' => '1', 'staff' => '2'],
];
?>

#Bashで動きを見てみる。

.bash
php artisan config:cache

Psy Shell v0.10.8 (PHP 7.4.3 — cli) by Justin Hileman
>>> config('membership.status.staff')
=> "2"

#コントローラ内でのコードが美しくなる。

MemberController.php

 $user->status = config('membership.status.staff');
 
//従来は、、、以下のようなダサい書き方をしていた。

 $user->status = 2; //スタッフの番号

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?