tiagomatosweb

Full Stack Web Developer at Tiago Matos web developer

Experience

2,560

0 Best Reply Awards

  • Member Since 2 Years Ago
  • 4 Lessons Completed
  • 0 Favorites

26th September, 2018

tiagomatosweb left a reply on Laravel API Endpoint Pattern • 2 weeks ago

Yep, thank you for your input @hollyit

tiagomatosweb started a new conversation Laravel API Endpoint Pattern • 2 weeks ago

Hi guys, just a quick curious question to see how would you devs set up your endpoints.

Models

  • User
  • Job

Relationship User hasMany Job

Considering that:

  • Normal users can only update their own jobs
  • Admin users can update any jobs

With that simple scenario in mind to get the current user (authenticated) job, would you use /me/jobs/{jobId}

or

/jobs/{jobId}

Won't talk much trying to not be biased.

Tks

10th August, 2018

tiagomatosweb left a reply on Cloudflare + SSL + Vultr • 2 months ago

@ejdelmonico gotcha! I’ve chosen this way because on the claudflare side I’ve generated the certificate as well as the key. Is not the corret way? Cheers

tiagomatosweb left a reply on Cloudflare + SSL + Vultr • 2 months ago

@aurawindsurfing I'm using full not flex.

@ejdelmonico I already have a certificate, that is why I am using existing certificate.

I assume when we use existing certificate forge does not update nginx config with the certificate/key path, is that right?

8th August, 2018

tiagomatosweb started a new conversation Cloudflare + SSL + Vultr • 2 months ago

Hi all,

Trying to manage SSL through these services. My cloudflare is set as SSL Full. I have created the certificate as well as private key. Then I added those via forge dashboard using "Install Existing Certificate". I've read this article https://medium.com/@taylorotwell/free-wildcard-ssl-using-forge-cloudflare-ab0ebfbf129f and seems all we need, really?

After that, I checked nginx config and it seemed was missing all the ssl setup such as certificate path, SSL port etc. Then, I manually added those. Doesn't forge do it for us automatically?

But, I'm getting this error when access using ssl. Without SSL is fine.

This site can’t be reached
staging.mydomain.com.au refused to connect.
Try:

Checking the connection
Checking the proxy and the firewall
ERR_CONNECTION_REFUSED

Also, if I check the ssl on https://www.sslchecker.com/sslchecker it says "No certificates were found."

my nginx congi

# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/staging.mydomain.com.au/before/*;

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name staging.mydomain.com.au;
    root /home/forge/staging.mydomain.com.au/public;

    # FORGE SSL (DO NOT REMOVE!)
    ssl_certificate /etc/nginx/ssl/staging.mydomain.com.au/391714/server.crt;
    ssl_certificate_key /etc/nginx/ssl/staging.mydomain.com.au/391714/server.key;

    ssl_protocols TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384;
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/nginx/dhparams.pem;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    # FORGE CONFIG (DO NOT REMOVE!)
    include forge-conf/staging.mydomain.com.au/server/*;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /var/log/nginx/staging.mydomain.com.au-error.log error;

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/staging.mydomain.com.au/after/*;

Any idea? Cheers.

1st August, 2018

tiagomatosweb left a reply on Pagination Json Structure • 2 months ago

Never mind, I just figure out. It depends on whether the response is a model or collection, then the pagination will be treated differently.

Cheers.

tiagomatosweb started a new conversation Pagination Json Structure • 2 months ago

Hi all, I'm confusing about how should be the real pagination json structure. In the docs, it shows in two different ways. Please have a look on https://laravel.com/docs/5.6/pagination#converting-results-to-json and https://laravel.com/docs/5.6/eloquent-resources#pagination.

Is it a mistake or is there a way to set pagination with links and meta keys?

Cheers

2nd July, 2018

tiagomatosweb started a new conversation Vuejs Test Utils + Mocha Webpack UserAgent Error • 3 months ago

Hi all, Has anyone come across with this error when run tests?

TypeError: Cannot read property 'userAgent' of undefined

I'm using this stack https://vue-test-utils.vuejs.org/guides/#testing-single-file-components-with-mocha-webpack

14th June, 2018

tiagomatosweb left a reply on How To Load Campaignmonitor/createsend-php Api Wrapper • 4 months ago

You should share your solution so that others can be helped. Tks

5th April, 2018

tiagomatosweb left a reply on Small Issue With Policy • 6 months ago

Yes! I thought so, I just wanted to know if everybody else uses the same approach :D

4th April, 2018

tiagomatosweb started a new conversation Small Issue With Policy • 6 months ago

Hi all, I'm new at Policy in Laravel.

I have User Model and Project Model. To add images to a project the scenario must be:

  • User must be an applicant.
  • Project must have in_progress status

My ProjectPolicy file

public function addImages(User $user, Project $project)
{
    return $project->isApplicant($user) AND $project->status === 'in_progress' ;
}

My question is would you declare the project status statement in the policy layer?

Cheers

28th March, 2018

tiagomatosweb left a reply on Laravel Test Different Scenarios • 6 months ago

@m-rk legend! Cheers.

tiagomatosweb left a reply on Laravel Test Different Scenarios • 6 months ago

Hey @m-rk, Thank you for replying me.

Yeah, things will get much and much more complex. My example was only a simple sample. I will have participants, collaborators, reviewers, etc, and all depends on also the user status. So it is quite a lot logic and permissions.

I liked you example but I also agree that it can be messy very soon. In addition, other developers will not understand on the first look.

I will keep writing separated methods for the time being.

By the way, do you know how I run a method only once before the test suit starts? Currently, my logic is running every time before each function because I am using the setUp methods. I think this wastes time and slow down considerably the testing process.

Cheers and thank you for the tips.

tiagomatosweb started a new conversation Laravel Test Different Scenarios • 6 months ago

Hi all,

I am doing testings in Laravel 5.3+. Everything is going well, but there is a particular case that there must be a better/quicker way to create unit test.

  • Lets say I have Project model which has an attribute called status.
  • Status can be draft, in_progress and closed
  • A project belongs to a user who is the owner.
  • The owner can add other users to a project as a participant.
  • The owner only can add users while a project is in draft.

So, my ProjectTest file would have one single method for each of the scenario above? For instance:

owner_can_add_users_to_draft_project(){ ... } owner_cant_add_users_to_inprogress_project(){ ... } owner_cant_add_users_closed_project(){ ... } etc...

Is that you guys usually do or is there any other better approach to avoid repetition?

cheers!

7th February, 2018

tiagomatosweb left a reply on Deployment To Production • 8 months ago

Thank you for sharing! That seems to be a good starting point!

Thanks

tiagomatosweb left a reply on Deployment To Production • 8 months ago

That should be food! Do you mind to share any source that contain a tutorial for it?

Tks

6th February, 2018

tiagomatosweb started a new conversation Deployment To Production • 8 months ago

How everybody is deploying Vue.js app to production? Are you committing the dist directory? Are you running npm build on production server? Another approach?

Thoughts?

31st January, 2018

tiagomatosweb left a reply on Socket.io Works Only On Localhost • 8 months ago

I sort this out. The server is hosted on Google and it needed to allow the port on Google panel. :(.

Actually it was a workmate that has found out.

tiagomatosweb left a reply on Socket.io Works Only On Localhost • 8 months ago

@zabi.zamir could you share your solution, I have the same problem here.

30th January, 2018

tiagomatosweb left a reply on Authorizing Private Event Channels (not Triggering WebSocket Server Listener). Public Events Work! - Laravel 5.5 • 8 months ago

Hey @cdr95985, thank you for sharing the solution of the prefix. it did the trick.

Have you found out why it is not hitting the authorisation on channels.php file? I am also facing that.

Tks

26th January, 2018

tiagomatosweb left a reply on How To Catch A Child's $emit In The Parent With Vue? • 8 months ago

Possible yes, you would need to emit event in all children components. If it is too much I would say, use event bus instead.

https://vuejs.org/v2/guide/components.html#Non-Parent-Child-Communication

22nd December, 2017

tiagomatosweb started a new conversation Laravel Testing Workflow • 9 months ago

Hi all,

What are your testing workflow guys and what is best for big project auto deployment with testing?

Any advise is welcome!

tiagomatosweb left a reply on Best Practice For Repository Patten • 9 months ago

@bobbybouwmann yeah mate I inject it separately but some times I feel like I should inject always services and no the repo. I don't really know...

Any one else?

20th December, 2017

tiagomatosweb started a new conversation Best Practice For Repository Patten • 9 months ago

Hi all, Quick question in term of best practice, lets say I have: UserController UserService UserRepository

and

ProductController ProductService ProductRepository

If I want to access any ProductRepository method from UserService should I inject ProductService and then by hierarchy it would access ProductRepository or should I inject ProductRepository straight?

Cheers.

13th December, 2017

tiagomatosweb left a reply on Problems With Spatie/Newsletter And Laravel 5.5 • 10 months ago

I've got this on Laravel 5.3 as well. Have you fixed?

29th November, 2017

tiagomatosweb left a reply on Endpoint And Service Layer (Pattern And Best Practice ) • 10 months ago

That's it. when you have sub entity you create a new controller for it, like

you have Product entity you have Seller entity

Then, you have a relation between those showing in the seller/{seller}/product endpoint. So, in this case you created SellerProductController to handle the request.

However, SellerProductController would use ProductService and/or ProductRepository, wouldn't?

Cheers?

tiagomatosweb left a reply on Endpoint And Service Layer (Pattern And Best Practice ) • 10 months ago

@ejdelmonico you are right, it should be plural. There is not productId, I thing you missed that?

Currently, I opted to be api/orders/project/{projectId} due to the fact that the product_id field is in the Order table, so, to me makes more sense find order by project under Order entity.

Not sure if it could have better approach, but it was my perception.

Thanks for your input.

tiagomatosweb started a new conversation Endpoint And Service Layer (Pattern And Best Practice ) • 10 months ago

Hi all,

I'm just wondering which way you would make the following

I have Order and Project Models. Order has project_id which is not always populated. I can have order without Project.

To get project order would you build

api/project/{projectId}/order -> pointing to a getOrder method in the Project Entity. api/project/{projectId}/order -> pointing to a getOrderByProjectId method in the Order Entity. api/order/project/{projectId} -> pointing to a getOrderByProjectId method in the Order Entity. Or any other better way?

Cheers.

26th November, 2017

tiagomatosweb left a reply on HTTP Request Vs Request() • 10 months ago

Thanks guys for the inputs...

tiagomatosweb started a new conversation HTTP Request Vs Request() • 10 months ago

Hey all, Just wondering what is the best practice for getting the request information. Lets say a have the scenario bellow

Scenario 1

// controller
public function store(MyRequest $request) {
}

// MyRequest.php
class MyRequest extends FormRequest
{
    public function rules()
    {
        return [
            'field'     => 'required|string',
            'field'    => 'required|string',
            'field'    => 'required|string',
            'field'          => 'required|integer',
        ];
    }
}

Scenario 2

public function store() {
   $request = request()->only(['field', 'field', 'field']);
}

12th November, 2017

tiagomatosweb left a reply on Xdebug + Phpstorm + Laravel Valet • 11 months ago

Unchecked the Break at first line in PHP scrips option made the trick!

tiagomatosweb left a reply on Using Php70-xdebug With Valet • 11 months ago

Unchecked Break at first line in PHP scrips and it worked!

tiagomatosweb left a reply on Laravel + Valet + XDebug • 11 months ago

I just unchecked the Break at first line in PHP scrips and boom, magic!

11th November, 2017

tiagomatosweb started a new conversation Xdebug + Phpstorm + Laravel Valet • 11 months ago

Hi guys, I just set up the xdebug with Laravel valet. Everything seems to work fine apart from it stops on valet server.php every time. I've unchecked these two options as recommended on other posts, but did not make difference.

  • Force break at first line when no path mapping specified
  • Force break at first line when a script is outside the project

Any clue?

tiagomatosweb left a reply on Using Php70-xdebug With Valet • 11 months ago

Hi, I've unchecked those 2 options but xdebug still stops on server.php. Any other help?

tiagomatosweb left a reply on Laravel + Valet + XDebug • 11 months ago

Did anyone figure out why it hits valet server.php first?

5th November, 2017

tiagomatosweb left a reply on When I Get Some Traffic, Server Crashed 502 Gateway Timeout Nginx • 11 months ago

Tks @jeroenherczeg, this solved my local issue with valet. Although I changed only pm.max_children to 25. :D

7th August, 2017

tiagomatosweb left a reply on Custom Guard • 1 year ago

No, the webapp is connect to the API. Everything comes from the API. The webapp is kinda dump, it doesn't store any data.

6th August, 2017

tiagomatosweb left a reply on Custom Guard • 1 year ago

Oh! Sorry, let me explain again. I have the API written in Laravel which issue JWT. I also have a webapp written in Laravel which receives JWT from the API. Currently, on the webapp I just store the JWT in the session. It works fairly well and I don't have any issue. I can catch the the JWT anytime using session() facade.

However, I would like do have another approach using guard to obtain Auth::check() facilities for instance.

I have been reading about it and I almost convinced that it is possible. I haven't gave a try yet though.

tiagomatosweb left a reply on Custom Guard • 1 year ago

Hi, thank you! However, I don't wanna issue token. Just need to store. Also, I didn't like to install packages. I think I can achieve this just plain Laravel.

5th August, 2017

tiagomatosweb started a new conversation Custom Guard • 1 year ago

Hi all, I have frontend website which connects to the API via JWT as many apps out there. Is there a way to create a custom guard to store the token in the session in order to use Auth facilities like Auth::check() ?

Currently, I just save manually the token in the session and check session data normally using session().

However, I would like to use guard, how would I do it? Any article?

19th July, 2017

tiagomatosweb started a new conversation API + Frontend Pure Js • 1 year ago

Hi all, I have a scenario that most projects nowadays have which is an api jwt based + pure js frontend.

So, I'm wondering if you guys use any proxy server between those two to hide the back endpoints. For instance,

mydomain.com -> frontend myproxy.mydomain.com -> proxy api.mydomain.com -> api

In this case, a call would be make via the proxy and then then the proxy server would make the actual request to the API and vice-versa.

Does anyone use this approach or you guys call the api straightaway without hiding the backend endpoints?

Cheers

26th June, 2017

tiagomatosweb started a new conversation One Website, Multiple Themes • 1 year ago

Hi everyone, I'm stuck in a tricky situation. I have a website which has multiple domains and themes. Each domain has its own theme which is pretty much css files. To fetch a theme, I need to call the API sending the domain name as a parameter in order to get the theme colors. After that, I need to apply those colors in the current website css file.

The issue is, the website uses SASS and the css is already compiled with the default theme.

I also have an admin section which allows the administrator manage the websites (domain name, color, and other basic stuff).

So, I'm wondering what is the best way to handle that.

So far, the best approach I have got is once a new website is added in the admin, the API will compile a new css files for this domain. However, I can see a couple issues already such as: how do I compile SSAS to CSS via PHP (Laravel)? Each website will have its own css stored in the API which will make maintenance really hard. Frontenders will need to work on the api site to change SASS file and compile all the time. I don't like much that...

Any better approach?

7th May, 2017

tiagomatosweb left a reply on How To Store JWT And Give User Access Using Laravel 5.2 + Guzzle 6 • 1 year ago

After awhile I realised that it is easier than I though. Literally you should store the JWT anywhere you want to. It doesn't really matter, as long as it's safe and and it is easy to catch anytime you need to.

No need to worry about Laravel Guard, which you could do it, actually, but too much effort for a simple stuff.

In this case, I saved in the Laravel session. When I use javascript, I store in the localStorage.

Simple as that.

Cheers

5th May, 2017

27th April, 2017

tiagomatosweb left a reply on How To Catch A Child's $emit In The Parent With Vue? • 1 year ago

Hey, if the components are parent/child you should use $emit to emit the data and v-on to catch the data. Even if you have child of a child i think it is advised to use this methodology.

In you scenario, you would use $emit from the second child, catch the data in the first child using v-on. After that, you would $emit again from the first child and finally catch it using v-on in the parent component.

If the components aren't parent/child you could use "bus", found here https://vuejs.org/v2/guide/components.html#Non-Parent-Child-Communication

If you logic is too complex, I would suggest using state management found here https://vuejs.org/v2/guide/state-management.html.

6th March, 2017

tiagomatosweb started a new conversation API Data Structure • 1 year ago

Hi guys, Recently, we have had so much discussion in the office about how we should structure our API data to provide better data to the front end. Thus, I would like to know how devs think about it nowadays. I'm sorry for the long post.

  1. First discussion => One level data or nested data. Some devs rather consume an API receiving that with just one when the record has any related models, like so:
{
  "status": "ok",
  "data": {
    "id": 1,
    "title": "My title",
    "category_id": 1,
    "category_name": "News",
    "post_type_id": 5,
    "post_type_name": "Highlight"
  }
}

Others prefere nested data like so:

{
  "status": "ok",
  "data": {
    "id": 1,
    "title": "My title",
    "category_id": 1,
    "post_type_id": 5,
    "category": {
      "id": 1,
      "name": "News",
    },
    "postType": {
      "id": 5,
      "name": "Highlight"
    }
  }
}

What do you prefer, what is better in your opinion and reasons?

  1. Second discussion: Single endpoint vs multiple endpoint We have had a discussion about what is the best way to provide data to front end. Let say that the front end need to have a bunch of data to make the system works. This data is kinda big because it has a lot of stuff involved. Let say we could have this:
{
  "status": "ok",
  "data": {
    "id": 1,
    "title": "My title",
    "files": [...],
    "invitedCollaborators": [...],
    "invitedInstitutions": [...],
    "tasks": [...],
    "faculties": [...],
    ...
  }
}

Would you create one endpoint that resolves all dependencies and throw only on big object like above, or would you prefere create separate endpoints to call each chunks, for instance: http://api.myproject.com/project/1 http://api.myproject.com/project/1/files http://api.myproject.com/project/1/invited-collaborators http://api.myproject.com/project/1/invited-institutions http://api.myproject.com/project/1/tasks http://api.myproject.com/project/1/faculties And then let the front end resolve this dependencies?

  1. Third discussion: generic object name (data) or descriptive object name (project). For instance, would you prefer return this with generic object called always data
{
  "status": "ok",
  "data": {
    "id": 1,
    "title": "My title",
  }
}

or this with a more descriptive name for the object

{
  "status": "ok",
  "project": {
    "id": 1,
    "title": "My title",
  }
}

These are only small representative example to illustrate our scenario. Glad you hear your thoughts. Thank you very much!

15th February, 2017

tiagomatosweb left a reply on Storage::moveDirectory() Not Working As Expected • 1 year ago

Hey, I know this is old but I was having the same issue. I fix using File::moveDirectory or File::copyDirectory from this guy here Illuminate\Support\Facades\File.

10th February, 2017

tiagomatosweb left a reply on Vuejs Screwing Up The Selected Option In A Select Component • 1 year ago

It did the trick! Thank you!

9th February, 2017

tiagomatosweb started a new conversation Vuejs Screwing Up The Selected Option In A Select Component • 1 year ago

Hi all, I'm passing data from parent to child component in order to select a default option in a select element. This select, which is in the child component, is populated by the child component itself. The default value should come from the parent.

So, once everything renders the select is not marked the default option according to the parent value, also, the parent value is being deleted.

App.vue

<template>
  <div id="app">
    <img src="./assets/logo.png">
    <h1></h1>

    <h4>Example 1</h4>
    <user :account="account"></user>
  </div>
</template>

<script>
import user from './User.vue'

export default {
  name: 'app',

  components: {user},

  created() {
    this.getAccount();
  },

  data () {
    return {
      account: {
        id: '',
        name: ''
      }
    }
  },

  methods: {
    getAccount() {
      this.$http.get('account.json')
      .then((res) => {
        this.account.id = res.body.id
      })
    }
  }
}
</script>

User.vue

<template>
  <div>
    {{ account }}<br>
    <select v-model="account.id">
    <option value="">Choose</option>
    <option v-for="(user, index) in users" :value="user.id">{{ user.name }}</option>
  </select>

  </div>
</template>

<script>
export default {
  props: {
    account: {
      type: Object,
      required: true
    }
  },

  created() {
    this.getUsers();
  },

  data() {
    return {
      users: [],
    }
  },

  methods: {
    getUsers() {
      this.$http.get('https://jsonplaceholder.typicode.com/users')
      .then((res) => {
        this.users = res.body;
      })
    }
  }
}
</script>

I made a package using https://github.com/vuejs-templates/webpack in order to facilitate your help. You can download the package here

Edit Your Profile
Update

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