We now understand how to fetch and display records from a linking table. Let's next learn how to perform inserts. We can leverage the attach()
and detach()
methods to insert one or many records at once. However, we should also perform the necessary validation to ensure that a malicious user doesn't sneak an invalid id.
app/Models
directory. This means an App\Post
namespace should now be App\Models\Post
.