In this guide I will show you how to use a factory to create a model with a related record. This includes making migrations, models, factories and the seeder.
Welcome to Laracoding
Recent Posts
Route to Controller with Optional Parameter(s) Using Laravel
In this article, you'll learn how to create a route to a controller with optional parameter(s) and make a demo app which browses products based on parameters.
How to Add a Where Clause to a Relationship Query in Laravel
In this article, we'll explore techniques to add a where clause to Eloquent relationships. I'll explain using methods as with(), withCount() and doesntHave()
This guide will show you how to clone models, with or without relationship data. I'll also include a practical example of cloning a "Project" and "Task" model.
Using Foreach Loops in Laravel Blade (Plus Common Questions)
This article shows how to list users with a @foreach loop and addresses FAQs about empty collections, counters, loop exits, key/value pairs, and odd/even rows.
This article will explore several methods to get the last insert ID in Laravel, by using Eloquent models, the DB facade, or by accessing the PDO instance.