3,900 experience to go until the next level!
In case you were wondering, you earn Laracasts experience when you:
Earned once you have completed your first Laracasts lesson.
Earned once you have earned your first 1000 experience points.
Earned when you have been with Laracasts for 1 year.
Earned when you have been with Laracasts for 2 years.
Earned when you have been with Laracasts for 3 years.
Earned when you have been with Laracasts for 4 years.
Earned when you have been with Laracasts for 5 years.
Earned when at least one Laracasts series has been fully completed.
Earned after your first post on the Laracasts forum.
Earned once 100 Laracasts lessons have been completed.
Earned once you receive your first "Best Reply" award on the Laracasts forum.
Earned if you are a paying Laracasts subscriber.
Earned if you have a lifetime subscription to Laracasts.
Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.
Earned once you have achieved 500 forum replies.
Earned once your experience points passes 100,000.
Earned once your experience points hits 10,000.
Earned once 1000 Laracasts lessons have been completed.
Earned once your "Best Reply" award count is 100 or more.
Earned once your experience points passes 1 million.
Earned once your experience points ranks in the top 50 of all Laracasts users.
@mabasic I choose to use ArraySerializer, but if you want to use other, just bind it:
So, you will define a serializer and then it will be used globally for all responses.
For the second example, your application outputs JSON object, but Fractal itself returns php array. You can
dd($this->fractal->collection($arrangements, new ArrangementTransformer())); in your controller and you will see array.
You do not need to create a service provider, you can use larasponse or mentioned laravel-fractal. Only you need is to register a service provider in your app.php.
Btw, laravel-fractal lib seems more complete, there is a facade, and probably more options, but personally, I don't like the architecture.
On the other hand, with larasponse you will write less and more readable code, especially when you need to output paginated collection. Also, there is a default transformer that can output object as it is, include key is configurable on runtime, etc.
If you have a trouble to setup, please be more specific, it should be really straightforward, I've used on few projects and it works like a charm.
Hi @jgravois thanks for the comment.
You can read more about transformers here - http://fractal.thephpleague.com/transformers/ scroll down for "Classes for Transformers". Also, scroll more and see how to nest and transform related objects.
I'll try to update a library with more examples, but it's crucial for you to know how Fractal works.
If you are interested in, please take a look and I'll be very pleased to hear some comments and reviews :)
@Kemito it's not bad, you must reference to the resource you want to change. So, if admin wants to change some data for an user, there must be a reference to the user. The only reason why is it bad is when an user changing data for himself.
@Devon Sending ID as parameter in POST to
/route/:id or in the case of GET to use
/route/:id?id=something is ugly, sorry :)
Sure, I'm using a decorator for authorization, that's fine :)
I'm not sure about using Route in handlers, mixing routes with business logic is not option for me, and discovering id in handler is too late, I need it in decorators.
Also, I don't like idea about merging inputs, but it seems there is no better way...
It's clear how to use a command with controller store method, but what is approach and how to use command with show and update methods? Now, there is $id parameter that needs to be reached in the handler?
Do you merge Input:all() and $id, and then pass to execute as second argument, or maybe find model by id and merge it with input and pass to execute?
Is there any other approach?
Note that controller methods are command (request) handlers now, and there is a method injection also, so probably you don't need a separate class to execute a command.
But if you want to, you can just simple call
new ScheduleTaskHandler($task), right? Or better, to use IoC.
Maybe it's just me, but I tried to use you commander and now I have a lot of commands, handlers and decorators, and it is to hard to follow the code. For example, in PhpStorm, I can not jump (cmd+click) to the handler, I must read a command name and then to cmd+o and type the name (or copy) plus to type 'Handler' at the end. So, for now, I think it's not the best way :(
Currently I'm playing with Commander library and maybe I'm wrong, but I want to build multiple decorators for some checks, for example, I have to have decorator that need to check if model exists, and next decorator should use the same model to check if user has permissions to manage it, probably before that I will use a decorator that validates command and so on. Finally I might want to use that model in the handler.
So, is there any good approach to reuse the same model? Is it a good practice to cache it inside Command class or maybe in Repository? Any thoughts?