Buy your loved one the ultimate gift. Lifetime gift certificates are $100 off.

joshgallagher24

Experience

14,680

0 Best Reply Awards

  • Member Since 2 Years Ago
  • 115 Lessons Completed
  • 1 Favorite

6th November, 2017

joshgallagher24 left a reply on Vue.js V-for Help! • 1 month ago

Would you suggest a more practical and less intensive way to implement this functionality?

5th November, 2017

joshgallagher24 left a reply on Vue.js V-for Help! • 1 month ago

@sutherland Thanks for the reply.

I thought about using the modulus operator, but it seemed over kill.

The nth child could work - could get messy.

The array of classes are in the article-item component. I was attempting to find the best solution within the component. Maybe I should make a method that using the modulo operator to pull a class from the array?

joshgallagher24 started a new conversation Vue.js V-for Help! • 1 month ago

I have a vue component that spits out a list of articles. I want to apply color classes to these articles.

in the article-item component I have an array of classes:

    data () {
      return {
        titleColors: [
          'article-item__title--green',
          'article-item__title--pink',
          'article-item__title--purple',
          'article-item__title--blue'
        ]
      }
    }

The problem is, i can only add these classes to the first 4 articles that are rendered as the array length is 3.

Is there anyway I can apply these classes to the first 4 articles, and then reset the v-for index?

This is where I am looping through the articles:

<article-item v-for="(article, index) in articles.articles" :article="article" :key="article.id" :index="index" :length="articles.articles.length"></article-item>

Any help would be much appreciated!

28th October, 2017

joshgallagher24 started a new conversation Lumen Fratcal Testing Error • 1 month ago

Hello all,

I am testing features in my application and have ran into a problem. I have wrote this feature test:

public function a_collection_of_articles_are_returned_paginated()
    {
        $user = factory(User::class)->create();
        factory(Article::class, 25)->create();
        $genArticle = factory(Article::class)->create([
            'title' => 'Some title',
            'slug' => 'some-title',
        ]);

        $this->json('GET', '/articles?page=6')
            ->seeJson([
                'data' => [
                    'title' => $genArticle->title,
                    'slug' => $genArticle->slug,
                    'teaser' => $genArticle->teaser,
                    'body' => $genArticle->body,
                    'created_at' => $genArticle->created_at,
                    'updated_at' => $genArticle->updated_at,
                    'user' => [
                        'data' => [
                            'name' => $user->getFullName(),
                        ]
                    ]
                ],
                'meta' => [
                    'pagination' => [
                        'total' => 26,
                        'count' => 1,
                        'per_page' => 5,
                        'current_page' => 6,
                        'total_pages' => 6,
                        'links' => [
                            'previous' => 'http://joshuagallagherapi.dev/articles?page=5',
                        ]
                    ]
                ]
            ])
            ->assertResponseStatus(200);
    }

However, when I run it, I get this error from PHPUnit:

There was 1 failure:

1) Tests\Feature\ArticleTest::a_collection_of_articles_are_returned_paginated
Unable to find JSON fragment ["data":{"body":"Repudiandae ullam praesentium aut totam dolores. Consectetur doloribus temporibus unde unde est pariatur quas. Ea saepe rem quia sed voluptas quia aut. Facilis et error ea velit rerum aut labore.","created_at":"28\/10\/17","slug":"some-title","teaser":"Odio deserunt molestiae soluta sunt adipisci ipsam. Dolor sint fugit perspiciatis est quis dignissimos maxime. Magni laudantium expedita aperiam. Quos odio rem dolorem magnam accusamus sunt non.","title":"Some title","updated_at":"28\/10\/17","user":{"data":{"name":"Warren Corwin"}}}] within [{"data":[{"body":"Repudiandae ullam praesentium aut totam dolores. Consectetur doloribus temporibus unde unde est pariatur quas. Ea saepe rem quia sed voluptas quia aut. Facilis et error ea velit rerum aut labore.","created_at":"28\/10\/17","slug":"some-title","teaser":"Odio deserunt molestiae soluta sunt adipisci ipsam. Dolor sint fugit perspiciatis est quis dignissimos maxime. Magni laudantium expedita aperiam. Quos odio rem dolorem magnam accusamus sunt non.","title":"Some title","updated_at":"28\/10\/17","user":{"data":{"name":"Warren Corwin"}}}],"meta":{"pagination":{"count":1,"current_page":6,"links":{"previous":"http:\/\/localhost\/articles?page=5"},"per_page":5,"total":26,"total_pages":6}}}].
Failed asserting that false is true.

I believe I am getting this error because Fractal returns the data differently, but I am unsure on how to get the data to comply with the seeJson method.

Any help would be appreciated.

26th October, 2017

joshgallagher24 started a new conversation Testing Fractal Transformer In Lumen • 1 month ago

This is Lumen specific.

I am currently creating an API with spatie's package fractalistic.

I am building it using TDD, but I am finding it hard to find the best method of testing them.

My first approach was to create a feature test for getting a collection of articles from the index endpoint.

ArticleTransformer.php

<?php

namespace App\Transformers;

use App\Models\Article;

class ArticleTransformer extends Transformer
{
    /**
     * Transform the given article collection into JSON.
     *
     * @param  Article $article
     * @return array
     */
    public function transform(Article $article)
    {
        return [
            'title' => $article->title,
            'slug' => $article->slug,
            'teaser' => $article->teaser,
            'body' => $article->body,
            'created_at' => $article->created_at,
            'updated_at' => $article->updated_at,
        ];
    }
}

ArticleTest.php

<?php

namespace Tests\Feature;

use Tests\TestCase;
use App\Models\User;
use App\Models\Article;

class ArticleTest extends TestCase
{
    /**
     * @test
     */
    public function a_collection_of_articles_are_returned_as_json()
    {
        factory(User::class)->create();
        $articles = factory(Article::class, 4)->create();

        $this->json('GET', '/articles')
            ->seeJsonStructure([
                'data' => [[
                    'title',
                    'slug',
                    'teaser',
                    'body',
                    'created_at',
                    'updated_at'
                ]]
            ])
            ->assertResponseStatus(200);
    }
}

In ArticleTest.php, I use "seeJsonStructure" to test that the structure is correct, I use this because Lumen's "seeJson" requires an array to be passed - fractal returns json wrapped in 'data'. However, I unsure if theres a better approach like testing a Transformer directly?

Anybody have any experience testing transformers?

23rd June, 2017

joshgallagher24 left a reply on Wrapping Validation Errors In 'data' • 5 months ago

Thanks @quickliketurtle.

I decided in the end to implement form requests as it looked cleaner in my controller methods.

22nd June, 2017

joshgallagher24 left a reply on Laravel - Is It Possible To Learn It In A Few Weeks? • 5 months ago

@teckel Laravel is an amazing Framework! I know people with basic PHP knowledge chuck out a basic blog application in a week. Laravel is simple to use, unless you are building a complex application with many different. Its not Laravel's fault if someone is not up to standards with correct practices and understands the concepts that come along with software development.

That is why you have the good coders and the highly paid software developers. it's a different league and takes time to get promoted.

joshgallagher24 started a new conversation Wrapping Validation Errors In 'data' • 5 months ago

Hi all,

I have a validator in my Lumen project, specifically in my auth controller sign up method. It returns errors like this:

{
    "name": [
        "The name field is required."
    ],
    "email": [
        "The email field is required."
    ],
    "password": [
        "The password field is required."
    ]
}

But I would like them returned like this:

'"data" => [
    {
    "name": [
            "The name field is required."
        ],
        "email": [
            "The email field is required."
        ],
        "password": [
            "The password field is required."
        ]
    }
]

Anyone know how to do this in Lumen? I know in Laravel you can extend the form requests class, but that is not available in Lumen.

19th June, 2017

joshgallagher24 left a reply on Fractal Include • 5 months ago

Just for anyone who stumbles upon this, I found the fix.

It was a bad problem of me not reading the docs provided by spatie!

If you want to include meta data, use this method:

addMeta([
    'token' => 'jumbledjwt'
])

Output:

{
    "data": {
        "id": "f45c9d38-d64c-4489-8b23-2840a485f3f5",
        "email": "[email protected]"
    },
    "meta": {
        "token": "jumbledjwt"
    }
}

joshgallagher24 left a reply on How Do You Determine If The Code Quality Is Good Or How Can I Write Code In Good Way? • 5 months ago

@alenabdula I agree.

I cannot count the amount of times I have taken an application and started from scratch to build it better. Every time, it comes out better.

Also, try prototyping. build the app and get it working, then create the final version based off of that design but refactor. This way, you will see bad design decisions in the prototype and be able to act upon them.

joshgallagher24 left a reply on How Do You Determine If The Code Quality Is Good Or How Can I Write Code In Good Way? • 5 months ago

Understand OOP.

If you understand OOP, you will write code in a better more structured way. My lecturer said that learning a language is not key, but understanding how to design applications, how to structure modules and the relationships between these modules.

Then, start exploring design patterns. it will take time, but over time you will start seeing where to use these patterns to clean up code.

It not the most in depth explanation, but it should point you in a good direction.

joshgallagher24 left a reply on How To Calculate Time For Given Project? • 5 months ago

Normally, I base it off of previous projects I've done. So, if someone comes to me asking for a news website and I have built a personal blog before using Laravel for arguments sake. I can base my project completion date off of the blog I built plus extra features. Then, usually I add a week or two on the end to make up for anything that goes wrong.

joshgallagher24 left a reply on Fractal Include • 5 months ago

Bump!

18th June, 2017

joshgallagher24 left a reply on Object Oriented Design Technique Tips And Tricks • 5 months ago

Over the last year, my comp sci lecturer has sworn by the client + server design.

joshgallagher24 left a reply on How To Access Vuex Module Actions From A Component • 5 months ago

Firstly import 'vuex' into your component.

Then, in your components method property use:

...mapActions([ Action names here ])

joshgallagher24 started a new conversation Fractal Include • 5 months ago

Hi all,

I am developing a small API using Lumen, JWT Auth and Fractal. I am having trouble implementing some functionality within fractal.

I am returning a user using a transformer, however, in some controller methods I want to include the generated token.

The method I want to do this in:

    public function store(Request $request)
    {
        $this->validateUser($request);

        $user = new User;
        
        $user->email = $request->email;
        $user->password = bcrypt($request->password);

        $user->save();

        $token = $this->jwt->attempt($request->only('email', 'password'));

        return fractal()
            ->item($user)
            ->transformWith(new UserTransformer)
            ->toArray();
    }

How would I take the "$token" variable and add it o the transformer output?

I would like the structure to be on the lines of:

{
    "data": {
        "id": "05720397-c625-4be6-a52f-10e85eb9de5b",
        "email": "[email protected]"
    },
    "meta": {
    "token": Token here
    }
}

Thanks in advance!


16th March, 2017

joshgallagher24 left a reply on Problem With Laravel Mix • 8 months ago

I just found it - skipped over it!

For anyone else using Sass with fonts or is having problems with URL rewriting add this:

   .options({
      processCssUrls: false
   });

joshgallagher24 started a new conversation Problem With Laravel Mix • 8 months ago

Hi everyone!

I am using Laravel Mix in a project outside of Laravel - a static website. However, I am having an issue with the config.

I have fonts in a font folder, which I add through a SASS file as shown below:

@font-face 
    font-family: 'Graphik-bold'
    font-weight: 500
    src:  url('../fonts/GraphikSemibold.woff') format('woff')

@font-face 
    font-family: 'Graphik-reg'
    font-weight: 300
    src:  url('../fonts/GraphikReg.woff') format('woff')

Here, in the paths I set "../fonts/GraphikSemibold.woff", however, upon compilation this path is changed to "/fonts/GraphikSemibold.woff".

How do I stop Laravel Mix from changing the file path?

13th February, 2017

joshgallagher24 left a reply on Passport - Customising Token Response • 10 months ago

@cisco The class I have to edit is not part of Passport - it is part of the League OAuth package.

The specific class is 'PasswordGrant.php'. I have looked and I am not sure how to implement it still.

joshgallagher24 left a reply on Passport - Customising Token Response • 10 months ago

bump

11th February, 2017

joshgallagher24 started a new conversation Passport - Customising Token Response • 10 months ago

Hi all,

I am working on an API at the moment and have hit a brick wall. I am using Passport with the 'Password' grant type.

I want to return the user's username with the access tokens, however, I am not sure how to.

For example, currently this is returned:

  "token_type": "Bearer",
  "expires_in": 31536000,
  "access_token": "token omitted",
  "refresh_token": "token omitted"
}

However, I would like this to be returned instead:

  "token_type": "Bearer",
  "expires_in": 31536000,
  "access_token": "token omitted",
  "refresh_token": "token omitted",
    "user": {
        "username": "a username"
    }
}

Thanks in advance!

21st January, 2017

joshgallagher24 left a reply on Forum Help • 10 months ago

Ok, if I go with duplicate posts how can I deal with them?

If a user posts a post called "laravel" and another user posts "laravel" - the exact same title. In this instance, if the user clicked on either one of these posts, they would be directed to the latest one only. This would only be a problem with slugs - which is what I want to use.

How would I overcome this in an API design for an SPA?

20th January, 2017

joshgallagher24 left a reply on Getting Too Many Requests Error On API • 10 months ago

You should not comment out this middleware. Imagine, if I decide to attack your API now - it will sink. You are not limiting the amount of requests that can be made to it, thus enabling someone to send millions of requests if they wanted to.

18th January, 2017

joshgallagher24 started a new conversation Forum Help • 10 months ago

Hello everyone,

I am building out a forum, and wanted your feedback on an area. Should I allow duplicate posts? For example, someone creates a post called 'what is laravel?' and then 2 months down the road someone posts the exact same thing. Should I allow this, or force them to post in an old thread?

Thanks!

14th January, 2017

joshgallagher24 left a reply on Don't Want To Use Vue In Laravel 5.3 • 11 months ago

Yes, just remove it! Then, just use blade templates etc.

16th December, 2016

joshgallagher24 left a reply on Can You Help Me To Rank Up My Website?? • 11 months ago

Of course. Any clients that come my way, I'll forward them to you. I don't need them.

11th December, 2016

joshgallagher24 left a reply on How To Make Table For Student Attendance System? • 1 year ago

ER and EAR diagrams FTW!

8th December, 2016

joshgallagher24 left a reply on Laravel 5.3 Passport For Mobile Client App • 1 year ago

In response to storing the client Id and secret in your app. You can store the client id in the manifest file and then create some middleware to inject the secret on every request. Do this for both SPA and mobile apps. As for the tokens being pruned, you don't have to. It is an optional setting that can be turned on or off I believe.

4th December, 2016

joshgallagher24 left a reply on Do I Have To Create Password Reset Routes? • 1 year ago

I found the routes in Router.php and implemented them!

joshgallagher24 left a reply on Do I Have To Create Password Reset Routes? • 1 year ago

I'm creating an API so I don't want to run that. It will bloat up the project. How do u go about creating the routes, because the methods are in a trait not the controller?

joshgallagher24 left a reply on Do I Have To Create Password Reset Routes? • 1 year ago

I have and they are not listed. However, I though they come pre-installed?

joshgallagher24 started a new conversation Do I Have To Create Password Reset Routes? • 1 year ago

Hi all,

I am creating an API and have come across an issue I don't really understand. I am setting up password resets to work with my api, but when I post through to the password/reset route in Postman with an email address i get an 'NotFoundHttpException'.

Do I have to create these routes manually, and how when I am using a trait with no available methods in my controller?

Thanks!

joshgallagher24 left a reply on How To Configure Password Resets For An API • 1 year ago

When I post to 'myapp.dev/password/reset' within postman with the correct headers and the users email I get a 'NotFoundHttpException'.

joshgallagher24 started a new conversation How To Configure Password Resets For An API • 1 year ago

Hi all,

I just wanted some help on how I could configure the password reset functionality into an API. I am not to sure on how to achieve this, because it is built around views etc.

Any help would be appreciated!

29th November, 2016

joshgallagher24 left a reply on Temporarily Lock A User Into A Certain Route • 1 year ago

Personally, I would go with what you have suggested. I would add a column to your Users table where you would set it to true if the user was required to change their password. Then, couple this with middleware and check this field on all routes you do not want the user to navigate to.

Other than that, I do not know of any other way to achieve this. Also, I do not think this is re-creating the wheel so it should be all good!

27th November, 2016

joshgallagher24 left a reply on API Authentication (with Passport) • 1 year ago

@adiachenko I've been speaking with Alex Bilbie - the creator of PHP's OAuth2 Lib. I clarified with him that, firstly using the Password Grant for a first party SPA was correct which he agreed upon. However, I am awaiting his reply on the cookie situation.

I am in two minds about the cookie use, because in either situation - cookie or no cookie we still create angles of attack through CSFR and XSRF.

I am still messing around with this concept, and I will push my project up soon so you all can give feedback and PR's. I am, also hoping that I can have a package done in the coming weeks to support this functionality.

Finally, to address what you have said are you referring to cross domain cookies?

joshgallagher24 left a reply on Passport Grant Client- Unsupported Grant Type Error • 1 year ago

Double check in your DB that you're not using the 'Personal Access Token' that is auto generated by Laravel Passport.

25th November, 2016

joshgallagher24 left a reply on API Authentication (with Passport) • 1 year ago

Hello all,

The PR I was trying to push through was closed. here it is: PR.

However, I will try and create a package out of this implementation! I'm not sure when I will have time due to Uni.

Do you all agree that this should be a package, or should we self implement this functionality on a per project basis?

16th November, 2016

joshgallagher24 left a reply on API Authentication (with Passport) • 1 year ago

I have also been on a mission to solve this issue!

I wrote about it here, and provided some possible implementations: Post.

Also, why are you hiding the Client ID? it does not matter if that is shown in the sources code. The only thing that should not be shared is the Client Secret. Plus, it makes it easier to send the Client ID with the request as then multiple first party apps can use it, rather than storing a single one in the .env file.

7th November, 2016

joshgallagher24 left a reply on Using ReactJS With Passport? • 1 year ago

@dshields This works if you build your React in blade views? I want to build my SPA seperate and then consume my API with it.

31st October, 2016

joshgallagher24 left a reply on Cloud SaaS Model, Single Database • 1 year ago

I think one database with the correctly structured tables would be fine. I can see where you're coming from, but you are overcomplicating it in my opinion. Also, you have to take cost into consideration. If you are a startup, are you charging your customers enough to give them there own db instance and all the other stuff your doing? If you are then good, but I would still rethink it!

However, I have uni tomorrow and my databases lecture so I'll ask my lecturer.

joshgallagher24 left a reply on Cloud SaaS Model, Single Database • 1 year ago

I do not see why you would use multiple database instances. Just think of the running costs that you would incur. I would suggest 1 database that is correctly structured and you should be fine. Then, in the future you would add more clusters if your site grows. I am not sure how Shopify do it, but I do not think they have multiple databases instances per client.

21st October, 2016

joshgallagher24 left a reply on Using ReactJS With Passport? • 1 year ago

@pmall You can use it with the password grant, however, you have to share the client secret which removes the point of using OAuth2.0. This is why I was asking if anyone knows a way to get around this or if Passport offered functionality like this. BTW it does not.

18th October, 2016

joshgallagher24 left a reply on Using ReactJS With Passport? • 1 year ago

Sorry for the late reply... Uni work. I am still unsure about this area. Is there any updates that give us this type of functionality? Or can we only use vue and the createFreshApiToken still. Haven't touched on this in a while but getting back to work so any suggestions or help would be great.

4th September, 2016

joshgallagher24 left a reply on Using ReactJS With Passport? • 1 year ago

Bump!

30th August, 2016

joshgallagher24 left a reply on Using ReactJS With Passport? • 1 year ago

I understand that Vue is not required, however, Laravel is heavily built around it now. I wanted to know whether I could use Laravel Passport's use of encrypted cookies in an API with a ReactJS app running on node for example.

joshgallagher24 started a new conversation Using ReactJS With Passport? • 1 year ago

Hello everybody!

Now that L5.3 has been released for a couple of days, I have decided to delve into it - specifically Passport.

To make it clear, I prefer ReactJS to VueJS and want to continue using it.

What I wanted to ask is can I use Passport with a ReactJS app? I have read some of the docs, specifically 'consuming your API with Javascript' and it seems that I have to use VueJS with the 'web' routes? However, I want to create an API with Laravel and Passport that communicates with my ReactJS app in a secure way.

Q: Is there a way that I can send the encrypted cookies to my ReactJS app whilst using the API routes?

Also, anybody who has any other suggestions please state them!

16th August, 2016

joshgallagher24 left a reply on OAuth Client Credentials Grant Question • 1 year ago

Is the app that is making HTTP calls a Javascript app?

13th August, 2016

joshgallagher24 left a reply on Help Me Convince My Friend To Use Vue Over React! • 1 year ago

VueJs IMO is a micro Javascript Framework, whereas, React is more powerful and can be used for both small and larger apps with the help of Redux and Relay. Your friend has a point!

11th August, 2016

joshgallagher24 left a reply on Challenging Bcrypt Question • 1 year ago

What you are doing is correct on the PHP and Java side. Don't remove the app key, that is for encrypting sessions. Also, what update are you talking about? An update to your Java or Laravel app?

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.