Featured tours working
This commit is contained in:
27
app/Models/Continent.php
Normal file
27
app/Models/Continent.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use LaravelIdea\Helper\App\Models\_IH_Continent_C;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Continent extends Model
|
||||
{
|
||||
protected $fillable = ['name', 'internal_name'];
|
||||
public $timestamps = false;
|
||||
|
||||
public static function allContinentsWithTours(): _IH_Continent_C|Collection|array
|
||||
{
|
||||
return Continent::whereHas('countries.tours')
|
||||
->orderBy('name')
|
||||
->get();
|
||||
}
|
||||
|
||||
public function countries(): HasMany
|
||||
{
|
||||
return $this->hasMany(Country::class);
|
||||
}
|
||||
|
||||
}
|
||||
28
app/Models/Country.php
Normal file
28
app/Models/Country.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
class Country extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'internal_name',
|
||||
'name',
|
||||
'country_code',
|
||||
'continent_id',
|
||||
];
|
||||
public $timestamps = false;
|
||||
|
||||
public function continent(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Continent::class);
|
||||
}
|
||||
|
||||
public function tours(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Tour::class, 'tour_countries', 'country_id', 'tour_id');
|
||||
}
|
||||
}
|
||||
17
app/Models/Tour.php
Normal file
17
app/Models/Tour.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
class Tour extends Model
|
||||
{
|
||||
protected $fillable = ['name', 'internal_name', 'short_description'];
|
||||
public $timestamps = false;
|
||||
|
||||
public function countries()
|
||||
{
|
||||
return $this->belongsToMany(Country::class, 'tour_countries', 'tour_id', 'country_id');
|
||||
}
|
||||
}
|
||||
12
app/Models/TourCountry.php
Normal file
12
app/Models/TourCountry.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class TourCountry extends Model
|
||||
{
|
||||
protected $fillable = ['tour_id', 'country_id'];
|
||||
public $timestamps = false;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user