Backend/20250217/F2Ingatlan/app/Models/Ingatlan.php
2025-03-10 13:58:21 +01:00

34 lines
946 B
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Ingatlan extends Model
{
//use HashFactory;
protected $table='ingatlanok';
protected $fillable = ['kategoria', 'leiras', 'hirdetesDatuma', 'tehermentes', 'ar', 'kepUrl'] ;
public $timestamps = false;
public function kategoriak(){
return $this->belongsTo(Kategoria::class, 'kategoria');
}
public static function getAllWithCategory(){
return self::with('kategoriak:id,nev')->get()->map(function ($ingatlan){
return [
'id' => $ingatlan->id,
'kategoria' => $ingatlan->kategoriak->nev ?? null,
'leiras' => $ingatlan->leiras,
'hirdetesDatuma' => $ingatlan->hirdetesDatuma,
'tehermentes' => $ingatlan->tehermentes,
'ar' => $ingatlan->ar,
'kepUrl' => $ingatlan->kepUrl,
];
});
}
}