What the HELL#%!& is Laravel Inertia for?

What the heck can we use Laravel Inertia for? It's a question I've been asking myself for several months now. Before you answer, remember that you can always respond and give your opinion in the comments section. I want to add a little context, so to speak.

Context

As I said, I've been asking myself the same thing for months and I still haven't found the answer. I'm mostly here talking about projects that I work with mainly, which are administrative in nature, and on the other hand, we have, as they say, what I call it for the end user, that is, a blog type, for example, obviously the blog that has an administrative part to create the publications and everything else. This is repeated in any topic, in other words, it could be like this for a blog type application, just as I was telling you, and I'm going to show you now, and it's the same thing that we handle in my courses and books, so it shouldn't be any surprise if you're going to sell cars, if you're going to sell tickets online, if you're going to sell hats, if you're going to rent houses, if you're going to rent hotels, whatever it is, it's always the same, we have an administrative part and we have another part for the end user.

SPA and SEO are not the best of friends.

Another important key is that we usually want to position it positioning a SPA type website is a big problem, in other words, it is earning a problem for free because for that we have to follow the classic approach here and the main problem is that precisely because it loads in pieces, Google or directly search engines like Google sometimes have no idea what it is loading, therefore you do not know what to read if you have to wait or whatever because it loads pieces so this is the main problem of being able to work with SPA type websites for when you want to position them so initially to avoid that problem I would not even use it initially, so that is why in the client, for websites that we usually always want to position, as I have mentioned, hotels or whatever, we will always want to position them to some extent, it would not be recommended to use a SPA website.

Inertia, Vue instead of Blade and little else

The strong feature we have in inertia is that here a component is returned in view instead of a blade, it's that simple, that's 90% of inert here as you can see here we have instead of view we have inertia:

public function create()
{
    $categories = Category::get();
    return inertia("dashboard/post/Save", compact('categories'));
}

By using Inertia, we gain nothing more than that, unlike Livewire, in which we can define operations related to the operation through livewire events:

<x-button class="flex-shrink-0" wire:click="tagSave">
    {{ __('Set') }}
</x-button>

And call component methods directly:

public function tagSave()
{
    // dd($this->tags[$this->tag_selected]);

    if ($this->tag_selected != null) {
        $t = Tag::find($this->tag_selected);
        $this->tagsSelected[$t->id] = $t->title;

        if ($this->post)
            $this->post->tags()->sync(array_keys($this->tagsSelected));
    }
}

Inertia for a Dashboard… not the best option

I would not use Inertia for the dashboard, I really always see Vue and all those technologies more than anything for the end user, understand for this this is what I mean because how can we add buttons animations the little bit of plum that we have for those stupid things the CCS and everything else to make it pleasant for the user I would use it there while the dashboard you have surely seen many memes out there on the internet you always think the front is a princess and the and the backend like a monster and it is really like that because we usually always invest a little either in personal projects or projects for third parties we always invest more it is for the end user because he is the one who pays it is that simple while for the backend we do the minimum necessary and we always try at some point to continue implementing it but we always have things to do in the client so for that reason I also do not see a, as who says, something strong in which I say that we have to use Vue yes or yes in the dashboard for the management unless you want to use a plugin or something very specific but even so, well it is a a little forced as I say then and still and still fix something for the Dashboard

Livewire better than Inertia for the Dashboard

I would always use Livewire because we have more features, or rather, we have a better connection because, in the end, all of that is Blade or Laravel, unlike what we have in Vue. Based on what was shown before, if we want a module to update a POST:

  1. Assign labels
  2. Remove labels
  3. Clone

All of these operations, performed from Inertia, don't change much from what we would do in base Laravel. We would have to create routes, associated controllers, Axios requests, or through Inertia... but in Livewire we call it directly, as we showed before, thus gaining time, scalability, and modularization in our project.

Based on what I've said, I would always use Livewire in the dashboard, but maybe at some point the stars align and you say, "Look, there's a plugin or some issue here because I want it to be really pretty, let's use Sensational, but even so, even if they tell you, it's difficult. I'm not saying it can't be used in any project. There will surely be some very specific cases, but even so, Livewire has a difficult time for ease.

Rest API + Laravel is the best option

Nowadays, *every* web application has its mobile equivalent: Udemy, Duolingo, Gmail… For example, if I had used Inertia for the academic website I have on this blog when I wanted to create the mobile application, I would have had a tremendous problem because, obviously, to keep it simple, here you can see the books and courses, buy them, list them, filter them, and view them. Download them. Ultimately, these are controllers that I have implemented in some way, either with Inertia or, in this case, through a RestApi. If I had used Inertia to create this, I would obviously have developed it faster. Because if we compare the traditional approach to RestApi + Laravel + Vue or React, or whatever you want, it takes longer than using Laravel + Inertia. Even though it is, we stumble upon a few things, although not that much, really. But

What exactly is the problem when we compare it to those applications, as I mentioned, any application today, like Udemy?

If I had used Inertia I wouldn't have had that RestAPI, so I would have had to develop all of that manually when I wanted to create the application in Flutter, which would connect to that RestAPI, therefore, I would have had to duplicate each of the Inertia controllers for the academy website for the Rest API controllers, and each change I wanted to make, I would have to touch the Inertia controllers and the Rest API in parallel, bringing redundancy to our application and hindering its logic.

I agree to receive announcements of interest about this Blog.

I don't know why Laravel Inertia is used, what do you use it for?

- Andrés Cruz

En español

) )