<aside> 🚧 This guide is currently a work in progress. If you'd like to help out, check out the Contribution Guide to get started!

</aside>

Ember and Laravel don't serve the same purpose, and are not direct competitors or alternatives. They are highly opinionated MVC frameworks. Both include a comprehensive range of integrated features. Both incorporate a lot of functionality into a CLI utility. Both are inspired by and derived from Rails. Both include comprehensive routers. They support clear separation of concerns. They both use discrete templates. They both have similar attitudes to rational defaults, to convention over configuration, to testing, and to eliminating unnecessary code.

However, Ember and Laravel also achieve different things and have different goals. A Laravel typically application responds to requests, while an Ember application has to more dynamically manage and update the user interface state. This means that some of the approaches and terminology are a little bit different.

Model, View, and Controller

Laravel is an MVC framework, but that's a paradigm that doesn't apply particularly well to the highly interactive nature of a client-side JavaScript framework. For the most part Ember's functionality aligns well in with an MVC mindset, but there are some minor differences that we'll highlight.

Models

There are a few different ways you can do a model in Ember. Essentially anything returned from the model hook is a model, pretty much by definition. But Ember also has a rich data layer called Ember Data, which is built-in. This creates a central data store, and provides convenient methods for working with data.

<aside> 💡 It's important to note that Ember Data is not required. It's quite common for a project to just use something like fetch or axios to get data from an API and return standard JS object and arrays from the model hook. That's completely valid.

</aside>

Defining models in Ember is really very similar to defining a model in Eloquent. However, unlike in Eloquent, an Ember Data model doesn't have a database row to look at, so you have to very explicitly define everything. And like Eloquent you can also define relationships between models.

import Model, { attr, hasMany } from '@ember-data/model';

export default class Post extends Model {
  @attr title;
  @attr content;
  @attr('date') postDate;
  @hasMany('comment') comments;
}

Modern Ember uses decorators quite extensively, to create terse, expressive code. You'll notice the first two don't have any argument in their attribute decorator - string is the default, and @attr title or @attr('string') title are identical.

We'll circle back to using these models in a second.

Views

Ember uses a templating system very much like Blade. The syntax is based on Handlebars. You may occasionally hear the term Glimmer used - that's the engine driving the view.

Displaying data in a template is almost identical to how it would be done in Blade.

<dl class="row">
  <dt class="col-sm-3">Name</dt>
  <dd class="col-sm-9">{ $name }</dd>

  <dt class="col-sm-3">Email</dt>
  <dd class="col-sm-9">{ $email }</dd>
</dl>

Would be done in Ember nearly identically, depending on whether the template is for a component or a route. The following assumes a component, but there are trivial differences.