2024-09-26 14:47:13 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace kernel\modules\post\controllers;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2024-09-26 16:49:01 +03:00
|
|
|
use JetBrains\PhpStorm\NoReturn;
|
2024-09-26 14:47:13 +03:00
|
|
|
use kernel\modules\post\models\Post;
|
|
|
|
use kernel\RestController;
|
|
|
|
|
|
|
|
class PostRestController extends RestController
|
|
|
|
{
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->model = new Post();
|
|
|
|
}
|
|
|
|
|
2024-09-26 16:49:01 +03:00
|
|
|
#[NoReturn] public function actionView($id): void
|
2024-09-26 14:47:13 +03:00
|
|
|
{
|
|
|
|
$model = $this->model->where("id", $id)->first();
|
|
|
|
$model->load("user");
|
|
|
|
$res = [];
|
|
|
|
if ($model){
|
|
|
|
$res = $model->toArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->renderApi($res);
|
|
|
|
}
|
2024-09-26 16:49:01 +03:00
|
|
|
|
|
|
|
#[NoReturn] public function actionDelete($id): void
|
|
|
|
{
|
|
|
|
$model = $this->model->where("id", $id)->first();
|
|
|
|
$model->load("user");
|
|
|
|
$res = [];
|
|
|
|
if ($model){
|
|
|
|
$res = $model->toArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
$model->delete();
|
|
|
|
|
|
|
|
$this->renderApi($res);
|
|
|
|
|
|
|
|
}
|
2024-09-26 14:47:13 +03:00
|
|
|
}
|