blob: 5c8127813a55fc4bab2d297369e128fc5bca644e (
plain)
| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
 | <?php
namespace App\Rugby\Model;
use App\Rugby\Concerns\Matchable;
use App\Rugby\Model\Match;
use Illuminate\Database\Eloquent\Model;
class Tournament extends Model
{
    use Matchable;
    protected $table = 'tournaments';
    protected $fillable = ['name'];
    public function matchableFilters()
    {
        $name_parts = collect(explode(' ', $this->name));
        $out = $name_parts->map(
            function ($value) {
                if ($this->isDate($value)) {
                    return ['date', $value];
                }
                if ($this->isNumeric($value)) {
                    return ['number', $value];
                }
                return ['string', $value];
            }
        );
        return $out;
    }
    public function matches()
    {
        return $this->belongsToMany(Match::class);
    }
}
 |