<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class MstStationPortal extends Model
{
    protected $fillable = ['line_nickname'];
    public $timestamps = false;

    protected $primaryKey = 'staion_unique_id';

    public static function findByNickName($lineName, $stationName, $type){
        $stationName = str_replace("JR", "ＪＲ", $stationName);
        $stationNames = [
                $stationName,
                str_replace("駅", "", $stationName)
            ];
        return MstStationPortal::where('line_nickname', $lineName)
            ->whereIn('station_name', $stationNames)
            ->orderByRaw('FIELD(station_name, '.'"'.implode('", "', $stationNames).'")')
            ->where('type', $type)
            ->first();
    }

}
