rest controller
This commit is contained in:
27
kernel/modules/post/controllers/PostRestController.php
Normal file
27
kernel/modules/post/controllers/PostRestController.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\modules\post\controllers;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use kernel\modules\post\models\Post;
|
||||
use kernel\RestController;
|
||||
|
||||
class PostRestController extends RestController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new Post();
|
||||
}
|
||||
|
||||
public function actionView($id): void
|
||||
{
|
||||
$model = $this->model->where("id", $id)->first();
|
||||
$model->load("user");
|
||||
$res = [];
|
||||
if ($model){
|
||||
$res = $model->toArray();
|
||||
}
|
||||
|
||||
$this->renderApi($res);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user