User.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace Maatwebsite\Excel\Tests\Data\Stubs\Database;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Database\Eloquent\Relations\BelongsToMany;
  5. use Laravel\Scout\Engines\DatabaseEngine;
  6. use Laravel\Scout\Engines\Engine;
  7. use Laravel\Scout\Engines\NullEngine;
  8. use Laravel\Scout\Searchable;
  9. use Maatwebsite\Excel\Tests\Concerns\FromQueryTest;
  10. use Maatwebsite\Excel\Tests\QueuedQueryExportTest;
  11. class User extends Model
  12. {
  13. use Searchable;
  14. /**
  15. * @var array
  16. */
  17. protected $guarded = [];
  18. /**
  19. * @var array
  20. */
  21. protected $casts = [
  22. 'options' => 'array',
  23. ];
  24. /**
  25. * @var array
  26. */
  27. protected $hidden = ['password', 'email_verified_at', 'options'];
  28. /**
  29. * @return BelongsToMany
  30. */
  31. public function groups(): BelongsToMany
  32. {
  33. return $this->belongsToMany(Group::class);
  34. }
  35. /**
  36. * Laravel Scout under <=8 provides only
  37. * — NullEngine, that is searches nothing and not applicable for tests and
  38. * — AlgoliaEngine, that is 3-d party dependent and not applicable for tests too.
  39. *
  40. * The only test-ready engine is DatabaseEngine that comes with Scout >8
  41. *
  42. * Then running tests we will examine engine and skip test until DatabaseEngine is provided.
  43. *
  44. * @see QueuedQueryExportTest::can_queue_scout_export()
  45. * @see FromQueryTest::can_export_from_scout()
  46. */
  47. public function searchableUsing(): Engine
  48. {
  49. return class_exists('\Laravel\Scout\Engines\DatabaseEngine') ? new DatabaseEngine() : new NullEngine();
  50. }
  51. }