asd
This commit is contained in:
@@ -11,4 +11,33 @@ class IngatlanController extends Controller
|
||||
public function index(): JsonResponse{
|
||||
return response()->json(Ingatlan::getAllWithCategory(), 200);
|
||||
}
|
||||
|
||||
public function update(Request $request, $id){
|
||||
$validate = $request->validate([
|
||||
'kategoria' => 'required|integer|exists:kategoriak,id',
|
||||
'leiras' => 'required|string',
|
||||
'hirdetesDatuma' => 'required|date',
|
||||
'tehermentes' => 'required|boolean',
|
||||
'ar' => 'required|integer|min:0',
|
||||
'kepUrl' => 'required|url'
|
||||
]);
|
||||
|
||||
$ingatlan = Ingatlan::updateIngatlan($id, $validate);
|
||||
|
||||
if(!$ingatlan){
|
||||
return response()->json(['message' => 'Ingatlan nem létezik'], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'id' => $ingatlan->id,
|
||||
'kategoria' => $ingatlan->kategoria->nev ?? null,
|
||||
'leiras' => $ingatlan->leiras,
|
||||
'ar' => $ingatlan->ar,
|
||||
'hirdetesDatuma' => $ingatlan->hirdetesDatuma,
|
||||
'tehermentes' => $ingatlan->tehermentes,
|
||||
'kepurl' => $ingatlan->kepUrl
|
||||
],200);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,4 +30,11 @@ class Ingatlan extends Model
|
||||
});
|
||||
}
|
||||
|
||||
public static function updateIngatlan($id, $data){
|
||||
$ingatlan = self::find($id);
|
||||
if (!ingatlan) return null;
|
||||
|
||||
$ingatlan->update($data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
use App\Http\Controllers\IngatlanController;
|
||||
|
||||
Route::get('/ingatlan', [IngatlanController::class, 'index']);
|
||||
Route::put('/ingatlan', [IngatlanController::class, 'update']);
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Reference in New Issue
Block a user