You are here


Subscribe to Laracasts feed
The best source of Laravel training on the web. 2018-09-21T21:04:50-04:00 Jeffrey Way
Updated: 2 years 3 days ago

Many to Many Polymorphic Relations

Wed, 09/19/2018 - 18:07
We've finally made it to the most intimidating of Eloquent relationships: many to many polymorphic. Don't worry; it's far simpler to understand than you might initially think. In this lesson, we'll construct a standard many-to-many relationship: a user can "like" a post. Then, we'll throw a wrench into the mix. What if a user can also "like" a comment? How might we restructure our existing structure to allow for this?
Categories: Laravel

Smaller Additions

Mon, 09/17/2018 - 20:48
Let's review a few smaller - yet still important - updates to Laravel 5.7. You'll learn about a new base directory for your JavaScript and CSS assets, callable action url generation, and guest authorizations.
Categories: Laravel

Improved Artisan Command Testing

Fri, 09/14/2018 - 16:42
Laravel 5.7 ships with improved support for testing your Artisan commands. You can now leverage the helpful expectsQuestion() and expectsOutput() methods to ensure that your commands function exactly as expected.
Categories: Laravel

Count Up

Wed, 09/12/2018 - 22:12
Let's review another real-life example. We need to construct a Vue component that counts from 0 to a given number very quickly. However, this counting should not begin until the element is within the user's viewport. View the source code for this episode on GitHub.
Categories: Laravel

Extract and Generalize: Infinite Scrolling Refactor

Mon, 09/10/2018 - 11:56
If you notice that a segment of logic in your component might be useful and necessary elsewhere in your project, this is likely an indication that you should extract the relevant code into its own component, generalize the specifics, and then emit events to handle side effects on a case-by-case basis.
Categories: Laravel

Dump Server

Fri, 09/07/2018 - 08:58
Laravel 5.7 includes an incredibly useful new php artisan dump-server command. Written by Marcel Pociot, this command provides a wrapper around Symfony's VarDumper component. While running, each time you dump data as part of your response (examples: dump($users) or dd('hello world')), the output will be swallowed up and printed in the console.
Categories: Laravel

Email Verification

Tue, 09/04/2018 - 16:07
First up, we have email verification support out of the box in Laravel 5.7. It's as simple as adding implements MustVerifyEmail to your User class. Seriously.
Categories: Laravel

Polymorphic Relations

Mon, 09/03/2018 - 16:48
We've made it to the scariest of Eloquent relations: polymorphic. Don't worry! As with most things, the word is scarier than the technique. A polymorphic relationship allows a model to belong to any number of models on a single association. Let's demonstrate this with a practical example.
Categories: Laravel

Has Many Through

Thu, 08/30/2018 - 21:14
While not nearly as common, the hasManyThrough relationship, when necessary, can prove to be incredibly useful. This relationship type allows you to perform queries across long-distance relationships.
Categories: Laravel

Many to Many

Mon, 08/27/2018 - 15:55
Many to many relationships are a bit more confusing to understand. Let's break it down by reviewing the common "posts" and "tags" relationship. A one-to-one or one-to-many relationship isn't quite right here. A post will never own a tag. It can be associated with one, sure, but it doesn't own the tag. The same is true in reverse. When we encounter situations such as this, a "many-to-many" relationship is exactly what we need.
Categories: Laravel

One to Many

Thu, 08/23/2018 - 21:17
Now that we have "one-to-one" relationships locked and loaded, let's move on to our next Eloquent relationship: "one-to-many." What might be an example of something a user would have many of? What about posts, or projects, or tasks? You'll reach for this relationship constantly in your daily workflow.
Categories: Laravel

That's a Wrap

Tue, 08/21/2018 - 14:59
Take a moment to think how much we've covered in this series. These techniques can be applied to any new component or feature that you're working on. I hope you've found a technique or two to throw into your toolbelt. Thanks for coming along!
Categories: Laravel

One to One

Mon, 08/20/2018 - 16:13
First up, we have "one to one" relationships. This is an easy one to picture in your head. What is one thing that a user might be associated with? What about a profile, or an address, or an avatar?
Categories: Laravel

Custom Collection Sorting With Lookup Tables

Fri, 08/17/2018 - 10:37
I'd like to sort all achievements from beginner to advanced. It sounds like we'll need custom sorting logic. Let's tackle that in this lesson by building a lookup table to translate each skill level to a respective number. Finally, we'll finish the lesson by discussing object responsibility and where logic like this should live.
Categories: Laravel