From adf07b310bddf751584db0717b8f501b8acda32a Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Fri, 24 Aug 2018 16:19:39 +0200 Subject: Added models for post types --- api/Posts/Models/MediaPost.php | 28 ++++++++++++++++++++++++++++ api/Posts/Models/Post.php | 41 +++++++++++++++++++++++++++++++++++++++++ api/Posts/Models/PostImage.php | 21 --------------------- api/Posts/Models/PostText.php | 21 --------------------- api/Posts/Models/PostType.php | 19 +++++++++++++++++++ api/Posts/Models/TextPost.php | 28 ++++++++++++++++++++++++++++ api/Posts/routes.php | 2 +- api/Users/Models/User.php | 5 +++++ 8 files changed, 122 insertions(+), 43 deletions(-) create mode 100644 api/Posts/Models/MediaPost.php create mode 100644 api/Posts/Models/Post.php delete mode 100644 api/Posts/Models/PostImage.php delete mode 100644 api/Posts/Models/PostText.php create mode 100644 api/Posts/Models/PostType.php create mode 100644 api/Posts/Models/TextPost.php diff --git a/api/Posts/Models/MediaPost.php b/api/Posts/Models/MediaPost.php new file mode 100644 index 0000000..e6f1629 --- /dev/null +++ b/api/Posts/Models/MediaPost.php @@ -0,0 +1,28 @@ +belongsTo('Api\Posts\Models\Post'); + } +} diff --git a/api/Posts/Models/Post.php b/api/Posts/Models/Post.php new file mode 100644 index 0000000..321c38c --- /dev/null +++ b/api/Posts/Models/Post.php @@ -0,0 +1,41 @@ +belongsTo('Api\Users\Models\User'); + } + + public function post_type() + { + return $this->belongsTo('Api\Posts\Models\Post'); + } + + public function media_post() + { + return $this->hasOne('Api\Posts\Models\MediaPost'); + } + + public function text_post() + { + return $this->hasOne('Api\Posts\Models\TextPost'); + } +} diff --git a/api/Posts/Models/PostImage.php b/api/Posts/Models/PostImage.php deleted file mode 100644 index 637d1ec..0000000 --- a/api/Posts/Models/PostImage.php +++ /dev/null @@ -1,21 +0,0 @@ -hasMany('Api\Posts\Models\Post'); + } +} diff --git a/api/Posts/Models/TextPost.php b/api/Posts/Models/TextPost.php new file mode 100644 index 0000000..30593a1 --- /dev/null +++ b/api/Posts/Models/TextPost.php @@ -0,0 +1,28 @@ +belongsTo('Api\Posts\Models\Post'); + } +} diff --git a/api/Posts/routes.php b/api/Posts/routes.php index c34c120..c3b90e4 100644 --- a/api/Posts/routes.php +++ b/api/Posts/routes.php @@ -1,5 +1,5 @@ get('/posts', 'PostController@getAll'); $router->get('/posts/{id}', 'PostController@getById'); $router->post('/posts', 'PostController@create'); diff --git a/api/Users/Models/User.php b/api/Users/Models/User.php index 9e5b0b7..e568608 100644 --- a/api/Users/Models/User.php +++ b/api/Users/Models/User.php @@ -27,4 +27,9 @@ class User extends Authenticatable protected $hidden = [ 'password', 'remember_token', ]; + + public function posts() + { + return $this->hasMany('Api\Posts\Models\Post'); + } } -- cgit v1.2.3