juandmegon

Hire Me

Experience

19,370

14 Best Reply Awards

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

21st March, 2017

juandmegon left a reply on Laravel Standard Authentication In Different Languages • 9 months ago

Maybe is a better idea to establish the language globally using a middleware. In that way, you will be able to show the entire site on Japanese and not only the authentication stuff. You maybe want to change the language based on a user preference or based on any URL segment or even in a session value (it is up on you)

6th February, 2017

juandmegon left a reply on Eloquent Model Events In Laravel 5.4 • 11 months ago

You're welcome. I am glad it helped.

4th February, 2017

juandmegon left a reply on Eloquent Model Events In Laravel 5.4 • 11 months ago

Take a look here: https://laravel.com/docs/5.4/eloquent#events

Now the model events can be managed using Object Oriented approach.

It is done using an $events attributes which cause your issue.

You can just change the name of your attribute on the trait, or go with the new approach.

23rd November, 2016

juandmegon left a reply on When To Use Exceptions • 1 year ago

Hello.

Based on the codes shared by you, it seems very similar to me. Using try/catch, in this case, is almost the same as the if/else.

A better approach is to, catch the exception in the Laravel handler (app/Exception/Handler.php). It provides you a centralized place to manage that kind of exceptions.

You should create your own exception too, something like "NotRemovableException" (or what you prefer) and throw that exception from your code.

Fianlly, you can create a method like.

´´´ function deleteIfPossible($model, $relation) { if(!$model->$relation->isEmpty()) { throw new NotRemovableException; } } ´´´

Then you can handle the NotRemovableException on you exception handler.

It allows you to use the same exception for different models as well.

Hope it give you some ideas.

Best wishes.

juandmegon left a reply on Only Created_at Timestamp Filling In Laravel 5.3 • 1 year ago

I am no sure if there is a way to this directly, but you can just change your timestamps attribute on your model to false.

public $timestamps = false;

With this, Laravel is not going to manage and try to add the creted_at and updated_at every time.

Then you can just add only the creted_at field as a date attribute.

protected $dates = ['created_at'];

Probably it will allow you to have the creted_at field parsed as a carbon date, but you may need to establish it manually for every insertion.

8th June, 2016

juandmegon left a reply on Api Saving Data • 1 year ago

Ok, well I really do not know what could be.

Can you try to do it in a controller, instead of a closure in the routes? Try to do the same directly in a controller.

juandmegon left a reply on Api Saving Data • 1 year ago

Try to use dd($data), to see what exactly $data have inside.

That should be an associative array.

juandmegon left a reply on Api Saving Data • 1 year ago

I am not completely sure, but if your request is JSON data, you should access it in this way:

$request->json()->all();

Hope it helps.

7th June, 2016

juandmegon left a reply on API Development Using Laravel 5.1 • 1 year ago

I arrived a little late, but I can add some clarity on this.

  1. Laravel has many useful features for this, like the RESTful Resource Controllers
  2. An API is stateless, so do not have sessions and the CSRF stuff can not be achieved in the same way. In fact, you have to disable the CSRF middleware
  3. As a way to secure your API and avoid the problems when disabled the CSRF middleware, you should validate the access to the API. For this, you can use OAuth2 or JWT

Additionally, you can take a look at this contents to have a very best idea about APIs on Laravel.

PD: About the rate-limit on Laravel 5.1, you can not use it directly, but you can check the code on Laravel 5.2 and use it in your API.

9th March, 2016

juandmegon left a reply on Dynamic Dependency Injection From User Input? • 1 year ago

You are welcome. I'm glad it helped. Best wishes.

4th March, 2016

juandmegon left a reply on Dynamic Dependency Injection From User Input? • 1 year ago

Hello @Romain , yes in fact I did some little tricks for this, using the session and mixing some patterns. It is a little confusing, but works. Here the details:

  • When the user choose an specific so store in the Session the name of the Payment method.
  • Then in the AppServiceProvider, you need to specify what to do when an instance of PaymentMethod is requestes. In this case, what I did was to create a PaymentMethodFactory, this class returns an instance of the specific paymentmethod class depending of the value in the Session (for example a PaypalPaymentMethod instance if the value in the Session is paypal).

Hope it give you a little idea.

Best wishes.

31st January, 2016

juandmegon left a reply on Are Longer Session Lifetimes Dangerous? • 1 year ago

Well in fact you have a remember me feature, should use it instead for the user who want the keep an active session.

Basically it is not dangerous for your application, it is more for the user, if they forget to logout. In fact, you can enable the feature to remove session after browser/window closing. Equally it can reduce the quantity of active sessions, because many of them aren't really from active users.

22nd January, 2016

juandmegon left a reply on Laravel 5.2: Form Not Being Repopulated After Validation Fails • 1 year ago

Based on the documentatiosn it should be required to add the old method on every field: https://laravel.com/docs/5.2/requests#old-input

14th January, 2016

juandmegon left a reply on Passing Entire Object In Restful API • 2 years ago

To solve it you can just create in your model the fillable attribute to allow mass assignment, just be careful with the sensible data like foreign keys (do not take it directly from the inputs).

Then you can just use the fillable method sending the array with all the received values.

....
$fields = $request->json()->all();

$u_p = UserProfile::where('id', $id)->first();
if($u_p)
{
    $u_p->fill($fields);
    $u_p->save();
}
....

Hope it helps.

13th January, 2016

juandmegon left a reply on Saving An Array Of Objects • 2 years ago

Hello @Maskers-1 please take into account thet $request is a instance of an object which have much more information and to get access to the input fields you should use $request->get('field') or $request->all() or in the case of JSON request $request->json()->all(), but use only $request does not the job. You need to access direclty to the input fields.

Best wishes.

12th January, 2016

juandmegon left a reply on Undefined Variable • 2 years ago

You have to send the variabel to the view in this way:

public function view()
{        
        $uploads = ImageTest::all();
        return view('test.show', ['uploads' => $uploads]);
  }

juandmegon left a reply on Saving An Array Of Objects • 2 years ago

I'm not completely sure here, but, I see that you are receiving a JSON array do you? So you have to use:

$request->json()->all(); To obtain all the field sent in the request (inside the JSON).

Just use dd($request->json()->all()) to have an idea of what are you getting.

Hope it helps.

10th January, 2016

juandmegon left a reply on Connecting To DigitalOcean Droplet (managed Via Forge) On Windows With Putty • 2 years ago

Sorry Zander, possibly we are missing something here, maybe it is due to a configuration made during the droplet configuration on Forge, may you want to contact the DigitalOcean support or forge (if they have).

Best wishes on it.

9th January, 2016

juandmegon left a reply on Connecting To DigitalOcean Droplet (managed Via Forge) On Windows With Putty • 2 years ago

It looks like a problem with your ssh keys (probably). I founf this article which can help you to solve this: https://www.digitalocean.com/community/tutorials/how-to-create-ssh-keys-with-putty-to-connect-to-a-vps

Hope it works.

juandmegon left a reply on Connecting To DigitalOcean Droplet (managed Via Forge) On Windows With Putty • 2 years ago

Just go to your DigitalOcean account or Forge and copy the IP address of your droplet.

Download putty for windows here: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

Then the host is your droplet IP, the port is 22.

In the left side go to SSH and choose 2 only.

Thats all, should work.

After that just enter your username and password (created by forge or your own).

juandmegon left a reply on Lumen Authentication • 2 years ago

Yes, normally you have to sent an access_token (or api_token) to validate the request. It is mandatory to validate the request that the access_token comes from a valid user of the system.

In this way, if you prefeer to implement it by your own, you have to obtain the access_token and then found if there exists a user who own that access_token.

Take into account that the access_token shpuld be compromised in some way, so it is a good idea to have som time to be valid and a way to refresh the token.

Hope I was clear on it, let me know if you want to know something else.

juandmegon left a reply on Lumen Authentication • 2 years ago

I'm not sure if it is a good idea to use the APP_KEY to validate requests, basically once you get that value it still the same, at least that you change it every time, and the APP_KEY is going to be exposed as well.

I recommend you something more suitable like JWT or OAuth2:

JWT: https://goo.gl/XmbeYS

or OAuth2: https://goo.gl/Pyp5qQ

Check here some videos of OAuth2:

Hope it helps.

juandmegon left a reply on Homestead And Nginx Subdomain Wildcard • 2 years ago

Try to use in your businesspage.local:

server_name .businesspage.local;

Intead of

server_name businesspage.local *.businesspage.local;

Source: http://goo.gl/6h59ZR

Hope it helps.

7th January, 2016

juandmegon left a reply on How Can I Create Custom Validation Rules • 2 years ago

You can use a request and it allow you to define the rules:

You can use for example:

'image' => 'required|image|max:20000'

It validates if it is an image

Based on this list: http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types

For the documents you should use doc or dot and pdf, additionally try to use the MIME type, instead of the extension: application/pdf, application/msword

Please check this good resource: https://goo.gl/jE4sOF

Let me know if it works.

juandmegon left a reply on Laravel 5 Restful API - Return Validation Errors • 2 years ago

Try to catch the exception directly in the handler and return a json response:

return response()->json('Repeated content', 409);

Get some very helful content for this here: https://goo.gl/G6ymJi

Hope it helps.

juandmegon left a reply on Trouble With Eager Loading BelongsToMany Relationship • 2 years ago

@JeffreyWay It is ok, at least you are accepting that it is because I'm sharing content related with yours, ok, sound logic we are competitors... are we? I suppouse because your behaviour, equally I understand is your business and I'm nothing beside you, ahaha you are the admin here :P.

PS: There were many of posts that I answered without share any link, do not judge the honesty of someone for a really weak reason.

Equally thanks.

Best wishes.

juandmegon left a reply on Trouble With Eager Loading BelongsToMany Relationship • 2 years ago

Hello @JeffreyWay well I know that you oppinion about Udemy is not the best, but wao man, really many of my comments wre in fact choosen as the best answer, it is not spam, I'm just sharing the ocntent like you share yours here and in other sites, Laracasts forum is public, I'm not just pasting the URL and no more, I'm answering and recommending the content if related. Lets be honest man, you are removing it because you can, but not because you have to. I'm a hones guy creating my contents, just like you I'm friendly here, can we work and coexists together? It is just that. Please re-consider your actions. Best wishes.

juandmegon left a reply on Trouble With Eager Loading BelongsToMany Relationship • 2 years ago

Omg @JeffreyWay do you seriously di it?? That is not fair competition I'm not spaming, I'm just answering and sharing the coruse when is a topica related, not spam, do you seriuosly take the time to edit every one of my posts to remove the links, wao It is like I removed the links yto your site from my website man, it is a really bad behaviour, waooo seriusly I can't believe it man.

juandmegon left a reply on Trouble With Eager Loading BelongsToMany Relationship • 2 years ago

Whoops my bad, you are absolutely right.

In this case, there should be some different reasons. The first one is:

  • Do you create the pivot table?
  • The pivot table has the right name? Must be in alphabetical order: role_user
  • The pivot table has correcly created the foreign keys? user_id pointing to users and role_id to roles table.

Please share (if you have one) the migration for the pivot table, and the other tables if it still not working.

Best wishes.

juandmegon left a reply on Learning Process • 2 years ago

Well, the best way to learn something new for programming is doing some interesting projects on it and learn in the way, of course you are going to need some documentation and learn some stuff to that (that is the deal) luckly there are tons of thing on Internet for this.

First the Laravel docs: https://laravel.com/docs/master/quickstart Aditionaly the PHP docs: https://secure.php.net/manual/index.php

Let me share some good contents to learn Laravel, and create some projects in the way.

Hope it helps. Best wishes.

juandmegon left a reply on Trouble With Eager Loading BelongsToMany Relationship • 2 years ago

I suppose, that a User has many Roles, so the relationship is bad.

//User Model public function roles() { return $this->hasMany('App\Role'); }

Take into account that the model Role must have a foreign key called user_id.

Hope it helps.

Let me share with you a course tha surely is going to help you in your Laravel projects: https://www.udemy.com/laravel-5-course-learn-php-laravel/?couponCode=forum2

Best wishes.

6th January, 2016

juandmegon left a reply on [L5] Avoiding CSRF Middleware On API POST Routes • 2 years ago

A RESTful API should be stateless, it means that it is not neccessary to keep the state through requests (sessions) in this way the CSRF verification is not completely necessary. To "disable" the sesssion, just go to the .env file and there change SESSION_DRIVER to array: SESSION_DRIVER=array

In this way it is not possible that someone take advantage of a stored sessions.

Aditionaly is a very good idea add some validation mechanism like basic auth (at least), or preferibly oauth2 or JWT.

Please check this very complete course to have a much better idea of this:

Hope many of you found this helpful.

28th December, 2015

juandmegon started a new conversation Dynamic Dependency Injection From User Input? • 2 years ago

Well I have a little idea about using dependency injection for a project, lesta cll this Payment Methods.

I created an interface (cal this PaymentMethodInterface) which has a executePayment method, so all the payment methods must implement this interface to be "accepted".

To this I decided to use dependency injection, accepting only instances of the PaymentMethodInterface.

The probolem is that I need to resolve the dependency dynamically based on the user input.

For example: There exists a class called PaypalPaymentMethod which implements the PaymentMethodInterface. If the user choose Paypal as a payment method, so I need to resolve the dependency of PaymentMethodInterface as an instance of PaypalPaymentMethod.

I hope it was clear, please lt me know if not to add more details.

PS: If you think in a better way to achieve this, I'll be glad to know that.

Thanks in advance,

1st December, 2015

juandmegon left a reply on Apply Maintenance Mode • 2 years ago

Hello, when you use php artisan down, it basically thrown an HTTPException for all the requests, so you can catch this request and check for example the IP address or any particular hasher or parameter value in the headers or somthing like that (I prefeer the last one).

'' if($e instanceof HttpException && $e->getStatusCode() === 503) { $sha1value = sha1('supersecretkey'); if($request->get('customParameter') !== $sha1Value) { //return view for 503 exception } }

''

Hope it helps.

29th November, 2015

juandmegon left a reply on Save Null Timestamp Values In An Eloquent Model • 2 years ago

Why not try to use a defualt value, instead of nullable? something like 0000-00-00, could works for you.

28th November, 2015

juandmegon left a reply on Lumen For APIs And Laravel For Website? • 2 years ago

It is simple:

  • Lumen is for micro services, it normally includes a RESTful API
  • Laravel is high featured projects

Now, some RESTful APIs (a few set) could require advanced features that lumen does not provide, in that case you have to use Laravel.

Basically you can start with Lumen for the API and in the future change to Laravel if required.

I can recommend you these courses to develop a RESTful API:

If you want something more specific for web projects, check it here: https://www.udemy.com/laravel-5-course-learn-php-laravel/?couponCode=forum2

Hope it helps.

Best wishes.

juandmegon left a reply on A Way To Handle APIs For Android/iOS With Auth • 2 years ago

Hello! For this kind of things it is a good idea to use OAuth2, currently it is very easy to use it for Laravel or Lumen.

It allows you to obtain an access_token with a user and/or client credentials and with that access_token your API/service can be requested safely during the expiration time.

Chack this link for much more details about oauth2: https://www.digitalocean.com/community/tutorials/an-introduction-to-oauth-2

Also, you can check this course about Laravel which includes a section about OAuth2: https://www.udemy.com/laravel-5-php-framework-agile-and-practical-php-restful-api/?couponCode=oauth2_2

Ir is available for Lumen too: https://www.udemy.com/lumen-restful-api-and-homestead-for-lumen-by-laravel-and-php/?couponCode=oauth2

Hope it helps. Best wishes.

24th November, 2015

juandmegon left a reply on Forbidden Error When Sending Email • 2 years ago

Great I'm glad it solves the problem :P. Please choose the answer, could help some body else.

juandmegon left a reply on Forbidden Error When Sending Email • 2 years ago

Possibly you are using some custom Request in your controller method and forgot to change the authorize method to return true.

22nd November, 2015

juandmegon left a reply on How To Secure My REST Api? • 2 years ago

Hello, take into account that JWT and OAuth2 are confused as "similars" many times, but they have complete different "goals" and in fact can work together: http://www.seedbox.com/en/blog/2015/06/05/oauth-2-vs-json-web-tokens-comment-securiser-un-api/ (please read to clarify this). Basically JWT is the way as the token is created/valdiated while OAuth2 is the way as you restrict the acces or control the protected resources management. In fact if you want you can use OAuth2 to protect/restrict the access to some operations/resoruces and issuing the access tokens with JWT. In conclusion, you can use both, but for ease OAuth has his own issuing method (called bearer) and works pretty good.

Let me recommedn you a course about RESTful API in Laravel, where is explained the OAuth2 process too: https://www.udemy.com/laravel-5-php-framework-agile-and-practical-php-restful-api/?couponCode=oauth2_2

or if you prefeer something faster like Lumen, you can check this Lumen course, also to develop a RESTful API including a section about OAuth2: https://www.udemy.com/lumen-restful-api-and-homestead-for-lumen-by-laravel-and-php/?couponCode=oauth2

Hope it helps.

Best wishes.

21st November, 2015

juandmegon left a reply on Localizing Date In View Laravel 5 • 2 years ago

Hello!

Maybe you want to achieve this using Carbon, just convert your attrbutes to Carbon instances and use the localization feature: http://carbon.nesbot.com/docs/#api-localization

Hope it helps.

10th November, 2015

juandmegon left a reply on Learn, How To Create A RESTful API With Laravel 5.0 => 5.1 And PHP • 2 years ago

Hello @socialflasher I'm sorry for the big delay. Please try to contact me from udemy, to send you the link, here you can do that: https://www.udemy.com/user/juandavidmezagonzlez/

Or directly here: https://www.udemy.com/message/send/?user_id=8031846

May be do you solved the issue?

Receive my best wishes.

5th November, 2015

juandmegon left a reply on Learn, How To Create A RESTful API With Laravel 5.0 => 5.1 And PHP • 2 years ago

Recently was added a new section to Update the OAuth2 server. Due to the latest changes in the OAuth2 dependency I created a new section teaching:

  • How to remove the old version (optional).
  • How to install the new version with the middlewares, grant_type and the new version.

Check more here: https://www.udemy.com/laravel-5-php-framework-agile-and-practical-php-restful-api/?couponCode=oauth2

Best wishes.

4th November, 2015

juandmegon left a reply on Is The $fillable Attribute Insecure In Laravel 5.1 Yet? • 2 years ago

Thanks for the replies. I read this post: http://stackoverflow.com/questions/22279435/what-does-mass-assignment-mean-in-laravel

Basically the problem is when you add in the $fillable attribute a field that you don't want to allow the user to "stablish" for example a foreign key.

If the user include a new field with the foreign key in the form is going to be allow to stablish his "parent" model with this and not you as a programmer. I tought that if I included also a new fields in the form these fields are goign to be included in the insestion query, but seems like Laravel ignore it.

juandmegon started a new conversation Is The $fillable Attribute Insecure In Laravel 5.1 Yet? • 2 years ago

I read about the $fillable attribute and the problems with the mass assignment. Basically (as I understand) the problem is when you use $request->all to fill the model using the create method (mass assignment).

I create a little test:

  1. I created a model with attr1, attr2, attr3, and attr4 (all of them in the $fillable array).
  2. Created a form with 6 fields attr1 ... attr6.
  3. When submited the form I use Mymodel::create($request->all());

The results? Well, basically the insertion was successfully done without problems and Laravel basically ignores the additional attribute (attr5, and attr6).

Now the question!! Is currently, in Laravel 5.1, insecure to use the mass assignment feature or is just a myth for the older versions?

Thanks for your attention and your replies.

28th October, 2015

juandmegon left a reply on Create A OAuth2 Microservice With Lumen • 2 years ago

Hello!

I know that it is a little "old" post, but I found it on the Internet and want to share a link for a course, where you can easily learn, how to create a OAuth2 server into a Lumen RESTful API

Here is the link: https://www.udemy.com/lumen-restful-api-and-homestead-for-lumen-by-laravel-and-php/?couponCode=oauth2

Hope it helps to who comes here.

Best wishes.

27th October, 2015

juandmegon left a reply on [Contribution] Lumen 5.1 And Homestead Of Laravel: Create A RESTful API • 2 years ago

I understand, but there are tons of honest people teaching awesome courses and valuable contents on Udemy, it is not a good idea to generalize and I'm sure that @JeffreyWay knows. Give it an opportunity all the classes are original created by me. Best wishes.

juandmegon started a new conversation [Contribution] Lumen 5.1 And Homestead Of Laravel: Create A RESTful API • 2 years ago

Hello people.

I'm glad to share with all of you my most recent course about Lumen and the RESTful APIs: https://www.udemy.com/lumen-restful-api-and-homestead-for-lumen-by-laravel-and-php/?couponCode=forum.

As many of you possibly know, with Lumen, you can create a really faster RESTful API and micro-services, (at least 5 times more efficient than Laravel and 2-3 times than other micro-frameworks).

With Lumen your API will support at least twelve hundred (1200) requests in a range of 10 seconds with 10 simultaneous requests. This great speed makes it the perfect candidate for implementing a RESTful API and it is completely easy!

During the course, you are going to learn, how to create a RESTful API in a different and better way; route by route, request by request and of course with many new concepts:

https://www.udemy.com/lumen-restful-api-and-homestead-for-lumen-by-laravel-and-php/?couponCode=forum

  • Major differences and facilities of Lumen VS Laravel
  • Creating a development environment with Homestead
  • Interaction with Vagrant virtual machines
  • Configure Homestead with Vagrant virtual sites
  • Configure and use the code editor Sublime Text 3
  • Using PHP artisan for creating code
  • Global middleware and route middleware
  • Create models
  • Relationships one to many between models (1: N)
  • Relationships many to many between models (N: N)
  • Tables intermediary or pivot
  • Validation of requests
  • Management and control of exceptions and errors
  • Migrations (automatic creation of databases)
  • Seeds (Automatic Insertion databases)
  • Factories , to create test/fake data
  • Creating a server OAuth 2
  • Generate access_token
  • Resource protection with access token
  • Restrict access through access token
  • Improving framework for production
  • Interaction with the database through Eloquent
  • Much, much more.

Of course, you can contact me at any moment with your comments, questions or issues, and I am going to be glad to attend every one personally as soon as possible, I really do.

Receive my best wishes and go ahead with your skills and knowledge. Take the course here: https://www.udemy.com/lumen-restful-api-and-homestead-for-lumen-by-laravel-and-php/?couponCode=forum.

Here is the Intro Video in Youtube: https://www.youtube.com/watch?v=BV7rmvPJZQk

Let me your comments!

8th October, 2015

juandmegon left a reply on When Does Laravel Refresh The... • 2 years ago

Great. I'm glad it helps. Best wishes.

7th October, 2015

juandmegon left a reply on When Does Laravel Refresh The... • 2 years ago

Laravel create a token for every active session (every user loged in). This tokens ans sessions get invalid after the configured time. Check config/session.php lifetime = 120 (by default - line 32).

The cookies depends of the specified life time:

Cookie::make('name', 'value', $minutes);

Hope it helps.

Edit Your Profile
Update

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