74 lines
2.3 KiB
PHP
74 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* App\Models\Draft
|
|
*
|
|
* @property int $id
|
|
* @property string $name
|
|
* @property int $active
|
|
* @property \Illuminate\Support\Carbon|null $created_at
|
|
* @property \Illuminate\Support\Carbon|null $updated_at
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Draft whereActive($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Draft whereCreatedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Draft whereId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Draft whereName($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Draft whereUpdatedAt($value)
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\DraftItem[] $draft_items
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\TravelProgramDraft[] $travel_program_drafts
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Draft newModelQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Draft newQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Draft query()
|
|
* @property-read int|null $draft_items_count
|
|
* @property-read int|null $travel_program_drafts_count
|
|
* @mixin \Eloquent
|
|
*/
|
|
class Draft extends Model
|
|
{
|
|
protected $connection = 'mysql';
|
|
|
|
protected $table = 'drafts';
|
|
|
|
public function draft_items()
|
|
{
|
|
return $this->hasMany('App\Models\DraftItem', 'draft_id', 'id')->orderBy('pos', 'ASC');
|
|
}
|
|
|
|
public function travel_program_drafts()
|
|
{
|
|
return $this->hasMany(TravelProgramDraft::class, 'draft_id', 'id');
|
|
}
|
|
|
|
|
|
public function findBeforeRelation($reid)
|
|
{
|
|
$before = false;
|
|
foreach($this->draft_items as $draft_item) {
|
|
if ($draft_item->id == $reid) {
|
|
return $before;
|
|
}
|
|
$before = $draft_item;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public function findAfterRelation($reid)
|
|
{
|
|
$next = false;
|
|
foreach($this->draft_items as $draft_item) {
|
|
if($next){
|
|
return $draft_item;
|
|
}
|
|
if ($draft_item->id == $reid) {
|
|
$next = true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
|
|
|
|
}
|