Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
Do you need to delete a post and a user, or a post and a link?
Deleting a post and a link
$post = Post::findOrFail($id);
$post->user()->sync([]);
$post->delete();
$post = Post::findOrFail($id);
$post->user()->delete();
$post->delete();
Schema::create('users_posts', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->unsigned()->index();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->integer('post_id')->unsigned()->index();
$table->foreign('post_id')->references('id')->on('posts')->onDelete('cascade');
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question