Grade.php 743 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace App\Repositories\Models\Mentor;
  3. use App\Repositories\Models\Model;
  4. use Carbon\Carbon;
  5. use Illuminate\Support\Facades\Cache;
  6. class Grade extends Model
  7. {
  8. /**
  9. * @var string
  10. */
  11. protected $table = 'mentor_grades';
  12. protected $guarded = [];
  13. /**
  14. * The attributes excluded from the model's JSON form.
  15. *
  16. * @var array
  17. */
  18. protected $hidden = [];
  19. public static function byNameAndCreate($name)
  20. {
  21. return Cache::remember("model:Grade:byNameAndCreate:{$name}", Carbon::now()->addHours(1), function () use ($name) {
  22. $model = self::query()->firstOrCreate([
  23. 'name' => trim($name)
  24. ], []);
  25. return $model;
  26. });
  27. }
  28. }