rest controller

This commit is contained in:
2024-09-26 14:47:13 +03:00
parent 810ca49de4
commit d49416a7d2
10 changed files with 282 additions and 4 deletions

View File

@ -2,10 +2,13 @@
namespace kernel\modules\post\models;
use \Illuminate\Database\Eloquent\Model;
use kernel\modules\user\models\User;
/**
* @property int $id
* @property string $content
* @property string $title
* @property string $slug
// * @property string $username
* @property int $user_id
* @method static where(int[] $array)
@ -14,15 +17,22 @@ use \Illuminate\Database\Eloquent\Model;
class Post extends Model
{
protected $table = 'post';
protected $fillable = ['content', 'user_id'];
protected $fillable = ['content', 'user_id', 'title', 'slug'];
public static function labels(): array
{
return [
'content' => 'Контент',
'title' => 'Заголовок',
'slug' => 'Slug',
'user_id' => 'Id пользователя',
'created_at' => 'Создан',
'updated_at' => 'Обновлен'
];
}
public function user()
{
return $this->belongsTo(User::class);
}
}

View File

@ -9,7 +9,9 @@ class CreatePostForm extends FormModel
public function rules(): array
{
return [
'content' => 'required|min-str-len:1',
'content' => 'required|min-str-len:10',
'title' => 'required|min-str-len:5',
'slug' => '',
'user_id' => 'required',
];
}