Skip to content

Instantly share code, notes, and snippets.

@emjayess
Last active November 23, 2020 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emjayess/3c1e14826b7a182a58ea752faa25e8e7 to your computer and use it in GitHub Desktop.
Save emjayess/3c1e14826b7a182a58ea752faa25e8e7 to your computer and use it in GitHub Desktop.
<?php
// short syntax available in php 7.4 and up
Project::with('user')
// regular anonymous php function expression
->whereHas('user', function($query) {
$query->where('role', 'admin');
})
// short anonymous php function expression ("fat arrow" fn)
->whereHas('user', fn($query) => $query->where('role', 'admin'))
->get()
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment