aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMarvin Borner2018-08-28 16:05:01 +0200
committerMarvin Borner2018-08-28 16:05:01 +0200
commit781438fc4cd54c885e52af22e1dc0ccaaace015e (patch)
tree3cdbf2e2a6df6e0a321084dbc1c3d7370f0eb498
parent113dfd2bc5089c66b7ff5d1ddccbd8c895bdd766 (diff)
Finished api of getting posts
-rw-r--r--api/Posts/Models/Post.php2
-rw-r--r--api/Posts/Models/PostType.php6
-rw-r--r--api/Posts/Services/PostService.php14
3 files changed, 11 insertions, 11 deletions
diff --git a/api/Posts/Models/Post.php b/api/Posts/Models/Post.php
index c93fc4f..9da1401 100644
--- a/api/Posts/Models/Post.php
+++ b/api/Posts/Models/Post.php
@@ -26,7 +26,7 @@ class Post extends Model
public function post_type()
{
- return $this->hasOne('Api\Posts\Models\PostType');
+ return $this->belongsTo('Api\Posts\Models\PostType');
}
public function media_post()
diff --git a/api/Posts/Models/PostType.php b/api/Posts/Models/PostType.php
index 455dd9e..3547a0a 100644
--- a/api/Posts/Models/PostType.php
+++ b/api/Posts/Models/PostType.php
@@ -2,11 +2,11 @@
namespace Api\Posts\Models;
-use Laravel\Passport\HasApiTokens;
-use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\Model;
+use Illuminate\Notifications\Notifiable;
+use Laravel\Passport\HasApiTokens;
-class TextPost extends Model
+class PostType extends Model
{
use HasApiTokens, Notifiable;
diff --git a/api/Posts/Services/PostService.php b/api/Posts/Services/PostService.php
index 7fc5dbb..a4af3cf 100644
--- a/api/Posts/Services/PostService.php
+++ b/api/Posts/Services/PostService.php
@@ -2,15 +2,15 @@
namespace Api\Posts\Services;
-use Exception;
-use Illuminate\Auth\AuthManager;
-use Illuminate\Database\DatabaseManager;
-use Illuminate\Events\Dispatcher;
-use Api\Posts\Exceptions\PostNotFoundException;
use Api\Posts\Events\PostWasCreated;
use Api\Posts\Events\PostWasDeleted;
use Api\Posts\Events\PostWasUpdated;
+use Api\Posts\Exceptions\PostNotFoundException;
+use Api\Posts\Models\Post;
use Api\Posts\Repositories\PostRepository;
+use Illuminate\Auth\AuthManager;
+use Illuminate\Database\DatabaseManager;
+use Illuminate\Events\Dispatcher;
class PostService
{
@@ -36,7 +36,7 @@ class PostService
public function getAll($options = [])
{
- return $this->postRepository->get($options);
+ return Post::with('post_type')->with('user')->get();
}
public function getById($postId, array $options = [])
@@ -77,7 +77,7 @@ class PostService
private function getRequestedPost($postId)
{
- $post = $this->postRepository->getById($postId);
+ $post = Post::with('post_type')->with('user')->where('id', $postId)->get();
if (is_null($post)) {
throw new PostNotFoundException();