Apiato: Why not get real_id although logged in by admin on get all list `Article`

Created on 9 May 2018  路  6Comments  路  Source: apiato/apiato

Expected Behavior

I want get real_id when i log in by admin.

Actual Behavior


I have issue:
i have an container Article and tranfomer of it:

...... $response = $this->ifAdmin([ 'real_id' => $entity->id, 'deleted_at' => $entity->deleted_at, ], $response);
On other action (create, update...) i still get real_id if i logged in by admin.
screen shot 2018-05-09 at 11 30 21 pm

But in list all article (by get method), i could not get real_id .

screen shot 2018-05-09 at 11 44 39 pm

Can you explain for me why?. thank so much !

Steps to Reproduce the Problem

1.
2.
3.

Specifications

  • Apiato Version:

Additional Details

Most helpful comment

the issue is, that the public route is loaded BEFORE the private route.. That is, because laravel loads the route "alphabetically ordered".. It may be the case that your private route is loaded after the public route (because the file-names are different!)

Or, if both route files point to the exact same URI, it may be the case that they "overwrite" each other.. I am not sure about this..

Check this out: http://docs.apiato.io/components/routes/#difference-between-public-private-routes-files

All 6 comments

Hey,

have you ensured that:
1) the user that makes the actual request is an admin user? e.g., the ifAdmin(...) method is properly called?
2) you have this isAdmin(...) block in the ArticleTransformer set up correctly? (e.g., you are using the auto-generated transformers)
3) You are really using the ArticleTransformer from 2 (see above)

Can you give feedack on this?!

yes, i can sure about that .

  1. I alrealdy log in by admin.I have got real_id when i run create method .
  2. This is my tranfomer :
 public function transform(Article $entity)
    {
        $response = [
            'object' => 'Article',
            'id' => $entity->getHashedKey(),
            'title' => $entity->title,
            'slug' => $entity->slug,
            'description' => $entity->description,
            'content' => $entity->content,
            'image_cover' => $entity->image_cover,
            'image_feature' => $entity->image_feature,
            'keywords' => $entity->keywords,
            'created_by' => $entity->created_by,
            'published_by' => $entity->published_by,
            'is_published' => $entity->is_published,
            'enable_comment' => $entity->enable_comment,
            'viewed' => $entity->viewed,
            'created_at' => $entity->created_at,
            'updated_at' => $entity->updated_at,

        ];

        $response = $this->ifAdmin([
            'real_id'    => $entity->id,
            'deleted_at' => $entity->deleted_at,
        ], $response);

        return $response;
    }
  1. i already used tranfomer
    my code :
 public function getAllArticles(GetAllArticlesRequest $request)
    {
        $articles = Apiato::call('Article@GetAllArticlesAction', [$request]);

        return $this->transform($articles, ArticleTransformer::class);
    }

anybody can help me resolve it ?please!

can you check the isAdmin() method.. and just dd($user) within this method, after the user is fetched?
If the route you are accessing is not protected (e.g., via the auth:api middleware), you are not getting a user, and, therefore, the isAdmin() method does nothing..

Is your route protected?

I found that i have two route: 1 private and 1 public
GetAllArticles.v1.private.php
GetAllArticles.v1.public.php
All case of my check, my route /articles still go to public route.
And in public route, i don't have auth:api
That is reason why i don't get real_id.
But, i still don't know how to private route work?.
and Why route only going to public route?

the issue is, that the public route is loaded BEFORE the private route.. That is, because laravel loads the route "alphabetically ordered".. It may be the case that your private route is loaded after the public route (because the file-names are different!)

Or, if both route files point to the exact same URI, it may be the case that they "overwrite" each other.. I am not sure about this..

Check this out: http://docs.apiato.io/components/routes/#difference-between-public-private-routes-files

Was this page helpful?
0 / 5 - 0 ratings

Related issues

autaut03 picture autaut03  路  6Comments

Mohammad-Alavi picture Mohammad-Alavi  路  3Comments

lukaszduda picture lukaszduda  路  5Comments

Mahmoudz picture Mahmoudz  路  6Comments

FWidm picture FWidm  路  3Comments