app/Models/Sakila/Actor.php

<?php

namespace App\Models\Sakila;

use Illuminate\Database\Eloquent\Model;

class Actor extends Model
{
    protected $connection = 'sakila';

    protected $table = 'actor';
}

app/Models/Sakila/Address.php

<?php

namespace App\Models\Sakila;

use Illuminate\Database\Eloquent\Model;

class Address extends Model
{
    protected $connection = 'sakila';

    protected $table = 'address';

    public function city()
    {
        return $this->belongsTo(City::class);
    }

    public static function options($id)
    {
        return static::where('id', $id)->get()->map(function ($address) {

            return [$address->id => $address->address];

        })->flatten();
    }
}

app/Models/Sakila/Category.php

<?php

namespace App\Models\Sakila;

use Illuminate\Database\Eloquent\Model;

class Category extends Model
{
    protected $connection = 'sakila';

    protected $table = 'category';
}

app/Models/Sakila/City.php

<?php

namespace App\Models\Sakila;

use Illuminate\Database\Eloquent\Model;

class City extends Model
{
    protected $connection = 'sakila';

    protected $table = 'city';

    public function country()
    {
        return $this->belongsTo(Country::class);
    }
}

app/Models/Sakila/Country.php

<?php

namespace App\Models\Sakila;

use Illuminate\Database\Eloquent\Model;

class Country extends Model
{
    protected $connection = 'sakila';

    protected $table = 'country';

    public function cities()
    {
        return $this->hasMany(City::class);
    }
}

app/Models/Sakila/Customer.php

<?php

namespace App\Models\Sakila;

use Illuminate\Database\Eloquent\Model;

class Customer extends Model
{
    protected $connection = 'sakila';

    protected $table = 'customer';

    public function city()
    {
        return $this->belongsTo(City::class);
    }

    public function address()
    {
        return $this->belongsTo(Address::class);
    }
}

app/Models/Sakila/Film.php

<?php

namespace App\Models\Sakila;

use Illuminate\Database\Eloquent\Model;

class Film extends Model
{
    protected $connection = 'sakila';

    protected $table = 'film';

    public function language()
    {
        return $this->belongsTo(Language::class);
    }

    public function originalLanguage()
    {
        return $this->belongsTo(Language::class, 'original_language_id');
    }

    public function categories()
    {
        return $this->belongsToMany(Category::class, 'film_category');
    }

    public function actors()
    {
        return $this->belongsToMany(Actor::class, 'film_actor');
    }

    public function text()
    {
        return $this->hasOne(FilmText::class);
    }
}

app/Models/Sakila/FilmText.php

<?php

namespace App\Models\Sakila;

use Illuminate\Database\Eloquent\Model;

class FilmText extends Model
{
    protected $connection = 'sakila';

    protected $table = 'film_text';
}

app/Models/Sakila/Inventory.php

<?php

namespace App\Models\Sakila;

use Illuminate\Database\Eloquent\Model;

class Inventory extends Model
{
    protected $connection = 'sakila';

    protected $table = 'inventory';

    public function film()
    {
        return $this->belongsTo(Film::class);
    }

    public function store()
    {
        return $this->belongsTo(Store::class);
    }
}

app/Models/Sakila/Language.php

<?php

namespace App\Models\Sakila;

use Illuminate\Database\Eloquent\Model;

class Language extends Model
{
    protected $connection = 'sakila';

    protected $table = 'language';
}

app/Models/Sakila/Payment.php

<?php

namespace App\Models\Sakila;

use Illuminate\Database\Eloquent\Model;

class Payment extends Model
{
    protected $connection = 'sakila';

    protected $table = 'payment';

    public function customer()
    {
        return $this->belongsTo(Customer::class);
    }

    public function staff()
    {
        return $this->belongsTo(Staff::class);
    }

    public function rental()
    {
        return $this->belongsTo(Rental::class);
    }
}

app/Models/Sakila/Rental.php

<?php

namespace App\Models\Sakila;

use Illuminate\Database\Eloquent\Model;

class Rental extends Model
{
    protected $connection = 'sakila';

    protected $table = 'rental';

    public function inventory()
    {
        return $this->belongsTo(Inventory::class);
    }

    public function customer()
    {
        return $this->belongsTo(Customer::class);
    }

    public function staff()
    {
        return $this->belongsTo(Staff::class);
    }
}

app/Models/Sakila/Staff.php

<?php

namespace App\Models\Sakila;

use Illuminate\Database\Eloquent\Model;

class Staff extends Model
{
    protected $connection = 'sakila';

    protected $table = 'staff';

    public function address()
    {
        return $this->belongsTo(Address::class);
    }

    public function store()
    {
        return $this->belongsTo(Store::class);
    }
}

app/Models/Sakila/Store.php

<?php

namespace App\Models\Sakila;

use Illuminate\Database\Eloquent\Model;

class Store extends Model
{
    protected $connection = 'sakila';

    protected $table = 'store';

    public function staff()
    {
        return $this->belongsTo(Staff::class, 'manager_staff_id');
    }

    public function address()
    {
        return $this->belongsTo(Address::class);
    }

    public function manager()
    {
        return $this->belongsTo(Staff::class, 'manager_staff_id');
    }
}

results matching ""

    No results matching ""