Skip to content

Instantly share code, notes, and snippets.

@matog
Last active June 3, 2019 23:28
Show Gist options
  • Save matog/2733c906e1765a0fe2b41ca3814ae512 to your computer and use it in GitHub Desktop.
Save matog/2733c906e1765a0fe2b41ca3814ae512 to your computer and use it in GitHub Desktop.
Base de datos con FK en Laravel y Eloquent

Migramos, y minamos la base

php artisan migrate
php artisan db:seed

Suponemos dos tablas, exams y questions. exams tiene la FK de questions.

php artisan tinker

En tinker:

\App\Exam::get()

Buscamos question_id que se repita en los diferentes exams. Por ejemplo, question_id = 3

$question= \App\Question::find(3)

Deberia listar los exams donde question_id = 3 está incluida:

$question->exams

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment