post crud fix
This commit is contained in:
parent
f5f546ba95
commit
2d8f945cad
@ -30,7 +30,7 @@ class PostController extends Controller
|
||||
$postForm = new CreatePostForm();
|
||||
$postService = new PostService();
|
||||
$postForm->load($_REQUEST);
|
||||
if((new UserService)->check($_REQUEST['user_id'])) {
|
||||
if(UserService::check($_REQUEST['user_id'])) {
|
||||
if ($postForm->validate()) {
|
||||
$post = $postService->create($postForm);
|
||||
if ($post) {
|
||||
|
@ -9,7 +9,7 @@ class CreatePostForm extends FormModel
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'content' => 'required|min-str-len:1|max-str-len:2048',
|
||||
'content' => 'required|min-str-len:1',
|
||||
'user_id' => 'required|min-str-len:1',
|
||||
];
|
||||
}
|
||||
|
@ -34,8 +34,9 @@ class UserService
|
||||
return false;
|
||||
}
|
||||
|
||||
public function check(int $user_id): bool
|
||||
public static function check(int $user_id): bool
|
||||
{
|
||||
|
||||
if (User::where(['id' => $user_id])->first())
|
||||
{
|
||||
return true;
|
||||
|
16
app/tables/columns/PostEditActionColumn.php
Normal file
16
app/tables/columns/PostEditActionColumn.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace app\tables\columns;
|
||||
|
||||
use Itguild\Tables\ActionColumn\ActionColumn;
|
||||
|
||||
class PostEditActionColumn extends ActionColumn
|
||||
{
|
||||
protected string $prefix = "/update/";
|
||||
|
||||
public function fetch(): string
|
||||
{
|
||||
$link = $this->baseUrl . $this->prefix . $this->id;
|
||||
return " <a href='$link' class='btn btn-success'>Редактировать</a> ";
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ class UserEditActionColumn extends ActionColumn
|
||||
public function fetch(): string
|
||||
{
|
||||
// $link = $this->baseUrl . $this->prefix . $this->id . $this->prefix . "update";
|
||||
$link = $this->baseUrl . $this->prefix . "update" . $this->prefix . $this->id;
|
||||
$link = $this->baseUrl . $this->prefix . $this->id;
|
||||
return " <a href='$link' class='btn btn-success'>Редактировать</a> ";
|
||||
}
|
||||
}
|
@ -10,9 +10,8 @@ class JSONCreator
|
||||
|
||||
public function __construct(array $meta, array $data)
|
||||
{
|
||||
|
||||
$params = empty($meta['params']) ? ["class" => "table table-bordered", "border" => "1"] : $meta['params'];
|
||||
if ($meta && $data) {
|
||||
if ($meta) {
|
||||
$this->informationArray = [
|
||||
"meta" => [
|
||||
"columns" => $meta['columns'] ?? [],
|
||||
@ -24,7 +23,7 @@ class JSONCreator
|
||||
"params" => $params
|
||||
|
||||
],
|
||||
"data" => $data
|
||||
"data" => $data ?? []
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -18,13 +18,14 @@ $dataProvider = new ListJsonTableEloquentCollection($contents, [
|
||||
'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||
'baseUrl' => "/admin/post",
|
||||
]);
|
||||
|
||||
$table = new ListJsonTable($dataProvider->getJson());
|
||||
$table->beforePrint(function (){
|
||||
return PrimaryBtn::create("Создать", "/admin/post/create")->fetch();
|
||||
//return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch();
|
||||
});
|
||||
$table->addAction(UserViewActionColumn::class);
|
||||
$table->addAction(UserEditActionColumn::class);
|
||||
$table->addAction(\app\tables\columns\PostEditActionColumn::class);
|
||||
$table->addAction(UserDeleteActionColumn::class);
|
||||
$table->create();
|
||||
$table->render();
|
Loading…
Reference in New Issue
Block a user