Member Since 4 Years Ago

at Nunuma, Inc.

Experience Points 29,140
Experience Level 6

860 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 430
Best Reply Awards 12
Best Reply
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.


    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.


    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    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.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

11 Oct
2 years ago

belisar left a reply on Storing Dynamic Columns

Two solutions I can think of:

  1. Use a JSON column to store the form data, and use keys for attributes and forget about the need for 'dynamic columns'
  2. Use a classic relational approach as follows, with a Forms and FormsData tables, where FormsData would be likely structured as:

id | attribute | value | form_id ------------ | ------------- | ------------- 1 | first_name | John | 1 2 | last_name | Doe | 1 3 | first_name | Zonda | 2 4 | last_name | Lover | 2

The general idea is that there can be no 'dynamic columns', but your data can be modeled in such way as to solve the problem you have. There are different ways as well, but those two came in my mind on the fly.

03 Oct
2 years ago

belisar left a reply on Pass Data From Listener To Event

One solution is to fire the first event a give it the reject value.

// HasBeenUpdated.php
public $rejects;

public function __construct($rejects)
        $this->rejects = $rejects;

fire as event(new HasBeenUpdated($rejects)

You can then listen only once and from there fire subsequent jobs.

// Action1.php (Listener)
public function handle(HasBeenUpdated $event)
        // pass the rejects value not the event.
        dispatch(new SecondAction($event->rejects++)

// SecondAction.php (Job)
public $rejects;

public function __construct($rejects)
    $this->rejects = $rejects;
public function handle($rejects)
        dispatch(new ThirdAction($rejects++)

So listen once, and pass the actual data rejects not the event itself to subsequent jobs, each of them can fire other jobs that take in the rejects action. However, for uses like this I would look into the Pipeline pattern, either using Laravel's own implementation:

or checking out the League\Pipeline package.

belisar left a reply on Pass Data From Listener To Event

It will not do what you expect because the App\Events\HasBeenUpdated instance is the same in both cases and it is not a singleton (neither should it be). The event is fired with a rejects property set at 0. This instance of it has it set at zero. Both listeners receive it. One of them makes a change to the property but the other one does not really care. It shouldn't care, the instance it receives is the unmodified one.

The most important thing however is that events are meant as simple data transfer objects and I would not alter the event itself after it has been fired. Think of their instances as write once, read many times kind of thing.

So the reject property should be given to the event when it is called, not set internally with the intention to be changed afterwards. Even if you fire the event itself again within the first event, while I am note sure, it will create a new instance internally and set the rejects to 0 again as specified in the constructor.

If you can say what exactly are you trying to achieve, maybe I can suggest a concrete solution.

30 Mar
3 years ago

belisar left a reply on Laracast - Not Impressed

There are two things that come with Laravel. The framework itself and some (rather extensive) boilerplate for your own app.

Now the problem becomes that most complaining new users have is that they do not like the specific boilerplate or a specific part of it. They want it different. They want to fit their current task better. It cannot. You have no guarantees it will. You should not have any expectations of that specific part of the framework. See it like this:

The framework comes with some boilerplate. Sure it cuts down some development time, but approach it more like a framework capability showcase and not like a one size fits them all thing. It is not.

You are also here, and Laracasts is probably the best place to get insight into how to make the framework work for you, build your own thing on its foundations.

In regards to changes, if you want the most stable interface stick to something like the LTS. If you want the shiniest new features that someone tweeted about and cannot live without them, be prepared to spend a little time upgrading, just a composer update most probably won't do it.

03 Dec
3 years ago

belisar left a reply on Laravel 5.2 (What Features Do We All Want?)

I would just like specific uses of traits to be reviewed. In some instances I find they do not provide value but make the code less readable ("followable"). Mainly the default Auth (register/login) class/trait tree which I basically recreate in a trait-less form for sanity checks.

24 Nov
3 years ago

belisar left a reply on Vue Components With Different Templates

Maybe you can try passing a literal as a prop when you call the component, based on the value of which you can set the template on the component in its 'created' or 'beforeCompile' hooks.

21 Nov
3 years ago

belisar left a reply on Vue.js Acces Parent Methods

I would go with using the event system. In your listeners, if you want the event to propagate upwards after the first response return true and the event propagation will not stop at the first response, going up the root.

//on the child. payload is just some data you want to pass along if any
    this.$dispatch('childIsCalling', payload)

//on the parent(s). other parents up the chain (the parent's parent will also respond if true is returned
events: {
    childIsCalling: function (payload) {
        this.something = payload;
    return true;

//or other wise
events: {
    childIsCalling: 'handleChildCall'

methods: {
    handleChildCall: function (payload) {
        this.something = payload;
    return true;

belisar left a reply on Prerequisites For Vue

Tinker with it. Open the JSFiddle examples from Vue's documentation and tinker with them, make changes, see what happens. Break them, fix them back. Take a small thing you have in query and see how you would go about replicating it in Vue without jquery. You can use jquery with Vue though, I am just saying try isolate Vue from the rest so you can understand its bits and pieces when you learn.

Step back, take it easy, it is really simple actually and I mean simple as in elegant and not in lacking. It is a very good tool to have under your belt. You get stuck on something, well that;s what the forums are for :)

belisar left a reply on Deleting A Object

You can use:


01 Nov
3 years ago

belisar left a reply on Is Vue.js Just For Single Page Applications?

@MathewHany ,

How do you define a 'Big Laravel Application'?

It has nothing to do with the size of your Laravel application. Vuejs appeal is exactly in the fact that it does not assume you will build a SPA.

24 Oct
3 years ago

belisar left a reply on Best Way To Save A Model With Many Data


or a specific class to handle student registration i.e a job, RegisterStudent, or StudentRegistrationService, which you can fire from your controller. If the processing (conversion) is of a complicated nature I would use a dedicated class to process them.

23 Oct
3 years ago

belisar left a reply on Scope Query Unable To Return False (zero) Instead Eloquent Builder Returns An Object

You need to drop the count and call count out of the scope. Or make a new method that does what you want inside the model (not the scope itself) and have your logic there. Sure they are made for reducing repetition, but within their intended use. The problem they solve is build queries ready to be acted on.

belisar left a reply on Scope Query Unable To Return False (zero) Instead Eloquent Builder Returns An Object

Because it is working as intended, by returning the query builder itself. Scopes are meant to provide a shortcut to common query logic you might have.

$user = User::where('active', true);

will yield the same result as you having a scope as follows:

public function scopeActive($query)
    return $query->where('active', true);

You would query it as User::active() chaining to it the 'action' methods if you will ('get', 'first' whatever you need). The returns from those will be what you expect and you can check against them for the presence or not of data. Acting on the query via 'first' with no data will result in null returned; acting on the data via 'get' will (on the top of my head) return an empty collection with no results.

Thus as I understand it scopes are working as meant to. Maybe your use case might specific, but scopes are not meant to provide/return data itself, they are meant to provide quick access to query building blocks.

21 Oct
3 years ago

belisar left a reply on Building An Api With Lumen

Lumen is not just like Laravel but faster. It is a stripped down version of Laravel, if you will, with some changes in a couple of key aspects like the routing library used. You can start with Lumen and if needed switch to Laravel without much effort if you find yourself needing more and more of Laravel's included functionality.

Compare the documentation of Laravel and Lumen (especially Services in Laravel documentation). That would give you a good idea of how they compare. If you can conclude that you do not need for the moment a good part of Laravel's functionality, Lumen might be a good choice.

My final advice, build something small, a test thing in Lumen so you get acquainted with it. They are both tools, means to an end, it does not hurt knowing both to a degree that would enable you quicker decisions in the future.

belisar left a reply on Changing Blade Files Never Change When Refreshing/clearing Cache

If not a typo, the only time when I might have had such issue was with PHP opcache enabled in php.ini, but then probably that would not work when you return text either.

However, by your calls, your directory in views should be like:

-views ---articles ------index.blade.php ------show.blade.php --app.blade.php

If it is like that it should work and the culprit escapes me.

18 Oct
3 years ago

belisar left a reply on IoC Container | Multiple Bindings Simultaneously

You can attach multiple listeners to your "StatusWasUpdated" event. You can typehint the Notifier interface in two of these listeners that would deal with notifying whoever needs to be notified via email/sms. Thus for the two listeners, presumably "SendSMSNotification" and "SendEmailNotification", you can contextually bind the Notifier interface:


You could also rethink the way you design this i.e something in the lines of Notify::with($payload)->via(['email', 'sms'])->push(); As a general rule I tend to write the code I want to read first, preferably in a test, and then write more code to make it happen.

07 Oct
3 years ago
04 Oct
3 years ago

belisar left a reply on Laravel Cheat Sheet

My eyes are hurting with all the facades and aliases :P "Controllers, prepare to be boarded"

It is a very nice quick reference, but for some reason I never used it much.

25 Sep
3 years ago

belisar left a reply on Can Someone Help Me Here

Well this might do the trick:

(I am brand new to Laravel. Where should I start?)[]

24 Sep
3 years ago

belisar left a reply on Vue NextTick

@jekinney I do not use Vue much so maybe someone will have a better understanding, however I see it as a kind of "documentUpdated" condition to make sure that direct changes to the DOM are actually completed and the DOM is updated before you call a function that depends on the value of the updated data.

I think (Vue's async updates section)[] in the guide is more clear than the API docs nextTick() documentation. Maybe you already read that, but it provides an example for nextTick(), albeit not very extensive.

belisar left a reply on How To Set Minumum Laravel Version For My Public Package Which I'm Gonna Develop

Well, see, * is just a wildcard: "laravel/framework": "5.0.*"

=5.0 but <6.0

belisar left a reply on How To Set Minumum Laravel Version For My Public Package Which I'm Gonna Develop

The same for laravel/laravel instead of php is not working for you?

belisar left a reply on A Video/series/tutorial That Explains The Repository Pattern?

Why are you tying your knowledge about a framework and language agnostic pattern to its Laravel implementation?

  1. You will learn it wrong.
  2. You will not understand its limitations when applied in different scenarios.
  3. You will not be able to identify when the need for the pattern actually arises.

Do a search on YouTube for "repository pattern php". Get the basics on at least a framework independent way (preferably even language independent way).

I would suggest learning patterns independently of the framework. You see the repository pattern is not even php specific, let alone it being Laravel specific.

If I can make an analogy, you need to learn to multiply in general, no matter the numbers. Learning to multiply two specific numbers is basically not of much use. It basically takes the same effort, with much more return.

belisar left a reply on Mutator For Multiple Columns

What @pmall said and also add:

protected $appends = ['address'];

in your model,

belisar left a reply on [NPM3] Windows Users, Solution To All Your Problems!

Yep, this is most certainly a welcome addition.

belisar left a reply on Best Place To Put An API File

Both packages are very valuable. With Guzzle you will be able to make calls to your API or third party services APIs within your php code base. Fractal provides the transformation and serialization layer for your API, it is not related to Laravel.

They are both framework agnostic, both are packages that are deemed of high quality. Fractal shows its worth more when the API is not incidental but sits at the core of your application. Laravel in this case is the API codebase and you develop the front end as a client that will consume the API. Fractal makes life easier.

You do not use them from the start, you use them when need arises, can be foreseen with a certain confidence or is known from the start. When not sure, start coding the app, the need shows up pretty fast if you need Guzzle, Fractal or need to implement JWT authentication or a plethora of other issues. They inevitably come up.

Don't pollute your brain with package integrations and such issues when you start a project. A moment might come when you need data to be produced in a certain format, with a certain structure. Fractal might save you time there and off you go. You might find yourself distributing your code into micro services, each with their own API, and having them come together, or making complex "domestic" calls to your API, setting up coms with third party APIs to consume their services and so on. Well, for that and more, Guzzle is a wonderful library to have around.

Hope that helps,

belisar left a reply on How To Insert Multiple Equal Records Into Database From Multiple Form Inputs?

No there is not, the query builder uses PDO parameters.

(The Laravel query builder uses PDO parameter binding to protect your application against SQL injection attacks. There is no need to clean strings being passed as bindings.)[]

23 Sep
3 years ago

belisar left a reply on Response View Links Not Working?

I see. Where do you have that JS code and is that on the page when you see the new post? It looks like the JS is not attaching the event listener. Did you try:

$(document).on("click", ".like-btn", function(e){
    var url = $( this ).attr( "href" );
        url: url,
        type: "post",
        success: function(data){

belisar left a reply on How To Insert Multiple Equal Records Into Database From Multiple Form Inputs?

@jekinney I am not sure as I do not use them, but I think the Html+Form helpers run htmlentities() when building the string to put in the view (?). It works on select boxes because they explicitly parse the array in the respective method, but it gets in a state of shock if what you want is an array out of the text fields :D

@alierfani I tried this on Laravel code without Form helpers, it works as expected, though.

belisar left a reply on Response View Links Not Working?

OK, the like is saved but instead of getting back the post you liked, you get back another post? It is not confusing, we are having language difficulties :D

So, when you say "newly returned post" you mean the post you liked with the updated number of likes? or An actual new post, not related to the first, but which you cannot like because the link does not work?

belisar left a reply on Response View Links Not Working?

    var url = $( this ).attr( "href" );
        url: url,
        type: "post",
        success: function(data){
            var lnk = $('#'+data['postid']+'-like').html(data['likes']);

What do you see in the console?

belisar left a reply on Response View Links Not Working?

@maniaquiz I asked that before you posted the links.

Your expectation is for the link to be on the same post but show 1 like instead of zero, correct?

belisar left a reply on Response View Links Not Working?

Are you preventing the default action on the anchor link with e.preventDefault() in your JS?

belisar left a reply on Response View Links Not Working?

How are you getting that data['likes'] to your view? If you console log data just after you open the function what do you get in the console?

belisar left a reply on Response View Links Not Working?

The server might not accept your javascript if you enclose it in script tags.

You said the links generated do not work compared to the original route. Can you please post the routes? I suspect the variable is not being available to the partial when it is called, but to be sure, can you copy and paste the two links generated.

belisar left a reply on Design Problem With Accessor And Mutators

@giopetris I am afraid your problem is that you are making the wrong kind of transformation in the wrong place.

The reason why you need the original value I believe is because you need to do calculations on it and I guess you are getting a string for that value.

Delay the transformation to when you actually are done with data manipulation. Even better, ask the model to tell you the currency, and pass to your view both the currency and the value, formatting that currency however you want.

belisar left a reply on Best Place To Put An API File

Well, no on the first question. I cannot see a problem. Put it wherever you think it fits. It's your party, unless you have to vote on it.

Making an ApiController that extends the base controller and in turn gets extended by the UserController might be good too. Whether it fits there or not depends on what kind of logic lives inside this Api file.

You can make a config pointer to it so you can change its location in one place only and save API variables there, have a service provider registered for it.

On the second one, I would just fire an event from the controller/save method and have a listener that makes the api call after that save happens (or listen to the model event that fires when the model is saved).

As always, make it work first. If it works fine, you work along and once you feel like "Nah, I do not feel this belongs here" take it where you think it belongs. There are too many ways to do the same thing and it usually never ends up being as you first write it no matter how hard you try. Focus on making it work fine and doing what you want it to do. If you would go by a principle, just follow the rules of the specific business and put things where do you think that it would provide more clarity to you when read it back.

belisar left a reply on Response View Links Not Working?

@maniaquiz Can you show both links and how they differ? Also the code where you are passing the $post variable to the view?

belisar left a reply on How To Insert Multiple Equal Records Into Database From Multiple Form Inputs?

@alierfani I guess this happens immediately as you load the view? So it is triggered by the view itself not by the actual processing for the request? If that is the case, can you please try and see if you try the input without the Form helper, does it work?

belisar left a reply on Response View Links Not Working?

<a id="{{ $post->id }}-edit-post-btn" value="{{ $post->id }}" class="nav-link text-muted edit-post-btn" href="{{ route('wallpostedit', ['username' =&gt; $post-&gt;user-&gt;username, 'id' =&gt; $post-&gt;id]) }}">Edit</a>

@maniaquiz use three ` to make it work (grave accents).

belisar left a reply on Open Source Website

People would benefit more from learning some vanilla PHP than to get a look at the guts of Laracasts. That will cut the problems people have by 60-70%.

That considered, this is not a very complicated website to make, and this is not what the worth of Laracasts is. The value of this place is driven by the quality of the videos in content and in delivery and also by the community that dwells here. Also, it might also be a case where, front end wise, if third party commercial code was used (as far as I remember it is), he might not be able to open source it due to licencing issues. Laracasts is business and one that delivers in that. It is interesting how on the internet we find it OK to ask for things we would not ask for in real life.

belisar left a reply on [L5] Dingo + JWT Unable To Authenticate With Invalid Token

That's great! Remember if you are using Dingo and want to make use of the full set of features from Fractal, it has some issues as it's composer requirement is for v0.12, which lacks some of the, or in the JsonAPISerializer, almost everything, from the features explained in the Fractal documentation.

belisar left a reply on How To Insert Multiple Equal Records Into Database From Multiple Form Inputs?

You cook something like this, sorry for not using your Form facade, but you get the idea:

<select name="education_levels[]" class="form-control"/>

PHP can then parse education_levels as an array and you can check with for its presence. If array is empty it will turn invalid, if not, there will be at least one entry.

If you need a more detailed example, I can provide it.

belisar left a reply on [L5] Dingo + JWT Unable To Authenticate With Invalid Token

I struggled over something similar (well identical) a couple of weeks ago when I was giving a try to Dingo. In fact I gave up on it for this and for another reason.

First of all, if you default to JWT own middlewares and make an Auth Controller for out of JWT, it works with no fuss. I also remember that the problem was arose when using api.auth with Postman, but I could make Angular calls on it fine. Anyways, too much trouble for something that was working and integrating with my code base fine.

But now I would like you to see a bit further down your development:

You are trying to implement stateless authentication. Most probably you will also make use of the other things in Dingo, including its use of Fractal for the transformation/serialization layer. Here is the catch though. You will have to circumvent Dingo's own requirements. Dingo requires Fractal 0.12 while in most cases you will want Fractal dev-master (until a proper version is tagged out of it), especially if you want to use the JsonApiSerializer. Fractal's documentation is build with dev-master in mind not v0.12. In pulling in packages that basically depend heavily on certain versions of other packages, with no guarantee of being updated to the next version, you limit or create unnecessary complications to your workflow, furthermore you also complicate Laravel upgrades.

Dingo is very good. Unfortunately is one of those cases that I try to steer away from. I will have to learn its way of doing things, go through the code, and it will "hide" knowledge away from you, pull in certain dependencies that may or may not be updated, have you go through 3 ore more packages on Github and review issues with all of them. Debugging becomes more cumbersome.

While I am aware that this does not answer to your question, and in fact I could not get one myself and decided it was not worth the time investigating the issue since the actual auth package works (JWT Auth), I will permit myself the following piece of advice based on unnecessary frustration I have had in the past.

  1. Whenever possible, stick to non Laravel specific packages. Why would you need a specific Laravel flavor of Fractal for example? It works perfectly fine with any framework, it is independent on the Laravel version you are using, it will never be something on your TODO list when you upgrade.

  2. For simple things, as a middleware that adds CORS headers, make your own. It is just a couple of lines and way more efficient than pulling in another dependency.

  3. When using packages, pick the ones that tackle one thing and do not take a lot on themselves. The later are cool, but end up being a burden.

What is most important, it is very easy to be obsessed with the current task at hand and if that task is making a package work, that can damage your productivity. Packages should not influence much the way you plan your application, they should just provide ready made code that once configured, integrates organically with your own code base. They should provide something you know how to do, ideally provide it the way to want it, and just save you the typing.

To wrap up, from my own experience, and I do no claim to be someone whose advice is worth much, but maybe its commonsense:

  • Do simple things yourself.
  • Prefer framework agnostic packages
  • Prefer packages that do not themselves depend a lot on other dependencies. Choose minimal packages that tackle one problem.
  • Avoid wrappers for Laravel. Laravel does not need them. For example if you need uuid functionality, stick to ramsey/uuid, no need for another package, that depends on this package to do same thing, the thing can do perfectly on its own.
  • Do not let packages dictate your code. Your code should speak your language, so you always know what says and what it means.
21 Sep
3 years ago

belisar left a reply on Investing Time In Vuejs Vs Other Frameworks

You are right. Time should be spent wisely, or invested as you say. Now would Laravel be of any use to someone who does not have much knowledge on PHP? Some might argue that it would. I don't agree. I think frameworks use case is to save you the typing, not the understanding of the underlying code or the thinking.

Same is true for javascript. Try to get the language first. Javascript Essentials (Revised) by Travis Tidwell is a good start. I would also recommend "Javascript is weird... and awesome" by Learncode Academy on YouTube. Following try to grasp an understanding of callbacks and promises in javascript.

Now follow up with Dan Wahlin Angular in 60ish minutes, an old but relevant video so you get a feeling of Angular. Vuejs videos are available here.

Now to the actual question. Let me tell you that you will end up with an understanding of both. I prefer Angular by a large margin. In fact I find simpler than Vuejs to understand for anything other than simple data binding.

So give yourself some time to learn more about Javascript. Then explore a little both. I personally would recommend Angular

belisar left a reply on Eloquent Model Vs Repository

@wise You can use repositories. In Laravel it would be wiser to actually use them as a place to dump complex read queries so that the controllers can actually can be readable.

Have a read at: and another watch at:

I find that to be a very good take on the subject. Again, do not get too much obsessed on patterns. Learn them so you have a tool in your belt, but make sure that is not the only tool you have. If the only tool you have is a hammer, every problem looks like a nail.

Again on the service class;

  • How do you call it? Well you are dada and mama. Call it whatever you like. Just don't go weird about it. Follow common sense class naming.
  • Where do you put it? Again, wherever you feel it fits. Make a services folder and dump it there. Maybe make User folder and have the UserService and the User model and UserRegistrationRequest or other user related classes there. Put it wherever it feels right to. Document it and kiss it sayonara.

Ad developers our end goal is to build a product that works and does something in a consistent manner. As a favor to ourselves and fellow developers that might work on our code we tend to fellow common best practices. Keep at the essentials first and refactor based on need. First priority is to make it work. Focus on that. Second priority make it clean and pretty.

  • Develop tests
  • Get those tests passing by developing the needed code
  • Refactor if needed for cleaner code, abstraction, avoiding copy and paste code.
  • Run tests so that you are happy green.
  • Move on to the next awesome feature.

You are in charge :)

belisar left a reply on JSON API With Composite Keys

A composite key is indicative of a table that connects to resources together. As far as resources are concerned, they do not have to mimic your actual SQL tables. If you have a students table, a subjects table and a tests table that has a composite key of student id and subject id, as far as resources are concerned, you are far better off using an id on that tests table rather than try to make the composite key your unique identifier. Furthermore, just because it says id it does not mean your actual id field on your SQL table. You can have there everything you choose, including something that you can build up from the composite key in your SQL table. I personally would go by composite keys only and only on "pivot tables" that on their own do not make an entity, they are just linking tables for actual entities. In this case they are not even a resource to be concerned with. If they indeed will be a resource I would fetch or interact with directly, I would have that id field to uniquely identify them.

The above example might look fine at first, but what if a student can have more than one take at test for the same subject. For example the student might fail the first test and can have another one. The composite key flies out of the window, now you need another key that defines the sequence (student_d: 1; subject_id: 3; try_sequence: 2). We would have to change the primary key composition to fit the scenario.

In short:

  • If your table is linking table only, a many to many pivot table for example, it is not a resource (or an Eloquent model for that matter).

  • If your table is an actual entity you plan to interact with, you are far better off having a sequential id and/or uuid on uniquely identifying each record.

I have always found this approach to make my life easier and more flexible to business logic changes (like giving students three tries at the same subject for the above example).

belisar left a reply on Overthinking In Which Class To Put A Method In.

@PavanKataria fractal supports Json Api via the JsonApiSerilizer with some limitations. DataArraySerializer works very well for me. Fractal supports default nested relationships (Includes) or you can set up available includes which you can call via the query string.


Both data array and the json api serialize support them. One thing, you would output a transformation serialized with the data array serializer to json as well. Json api just means the response will conform to the JsonApi standard, so mainly it changes the data structure on the response.

Don't know if I made sense since I am on my phone but I might show you the difference later in code.