1. confirmEmptyArrayメソッド
App/Lib/MyFunc.php
<?php
namespace App\Lib;
class MyFunc
{
public static function confirmEmptyArray($array, $empty_message)
{
if (empty($array)) {
return $empty_message;
} else {
return $array;
}
}
}
2. 使い方
App/Controllers/HomeController.php
<?php
namespace App\Http\Controllers;
use App\Lib\MyFunc;
class HomeController extends Controller
{
public function *** {
$array = Model::where()-> ...略...->get()->all();
$array = MyFunc::confirmEmptyArray($array, '空です');
}
}