Rafael Machado
Nov 7 · 1 min read

I agree that you should think about your database on paper first, but eventualy if your app is evolving you may need to add foreign keys after you create your “types” tables.

So you can create a new migration or even set the foreign key in the “types” tables. Like so:

Schema::create('services', function (Blueprint $table) {
$table->increments('id');
...
});
Schema::table('messages', function (Blueprint $table) {
$table->foreign('service_id')
->references('id')
->on('services')
->onDelete('cascade');
});

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade