12345678910111213141516171819202122232425262728293031323334 |
- <?php
- namespace App\Repositories\Models\Mentor;
- use App\Repositories\Models\Model;
- use Carbon\Carbon;
- use Illuminate\Support\Facades\Cache;
- class Grade extends Model
- {
- /**
- * @var string
- */
- protected $table = 'mentor_grades';
- protected $guarded = [];
- /**
- * The attributes excluded from the model's JSON form.
- *
- * @var array
- */
- protected $hidden = [];
- public static function byNameAndCreate($name)
- {
- return Cache::remember("model:Grade:byNameAndCreate:{$name}", Carbon::now()->addHours(1), function () use ($name) {
- $model = self::query()->firstOrCreate([
- 'name' => trim($name)
- ], []);
- return $model;
- });
- }
- }
|