Вход Регистрация
Файл: app/Models/BaseModel.php
Строк: 44
<?php

declare(strict_types=1);

namespace 
AppModels;

use 
IlluminateDatabaseEloquentModel;
use 
IlluminateDatabaseEloquentRelationsBelongsTo;
use 
IlluminateDatabaseEloquentRelationsRelation;

/**
 * Class BaseModel
 *
 * @property User user
 *
 * @method increment(string $field, $amount = 1, array $extra = [])
 * @method decrement(string $field, $amount = 1, array $extra = [])
 */
class BaseModel extends Model
{
    
/**
     * The attributes that should be cast to native types.
     */
    
protected $casts = [
        
'user_id' => 'int',
    ];

    
/**
     * Bootstrap services.
     *
     * @return void
     */
    
public static function boot()
    {
        
parent::boot();

        
Relation::morphMap([
            
Down::$morphName      => Down::class,
            
Article::$morphName   => Article::class,
            
Photo::$morphName     => Photo::class,
            
Offer::$morphName     => Offer::class,
            
News::$morphName      => News::class,
            
Topic::$morphName     => Topic::class,
            
Post::$morphName      => Post::class,
            
Guestbook::$morphName => Guestbook::class,
            
Message::$morphName   => Message::class,
            
Wall::$morphName      => Wall::class,
            
Comment::$morphName   => Comment::class,
            
Vote::$morphName      => Vote::class,
            
Item::$morphName      => Item::class,
        ]);
    }

    
/**
     * Возвращает связь пользователей
     */
    
public function user(): BelongsTo
    
{
        return 
$this->belongsTo(User::class, 'user_id')->withDefault();
    }

    
/**
     * Возвращает логин пользователя
     *
     * @param string|null $value
     */
    
public function getLoginAttribute($value): string
    
{
        return 
$value ?? setting('deleted_user');
    }
}
Онлайн: 1
Реклама