For eager loading a nested relationship you always have to include the primary key or the foreign key to the field list.
$posts = Posts::with(['comments:id,title', 'comments.author:id,email']);| Here is a quick way to add authentication logging to Laravel. | |
| 1. Modify app/Providers/EventServiceProvider.php and add lines 16 through 32 of the example file in this GIST. | |
| 2. Create a new file app/Listeners/LogActivity.php and copy the contents of the file below into that file. | |
| 3. Enjoy logging. |
| <?php | |
| // Attributes (AKA Annotations). | |
| #[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_FUNCTION)] | |
| class CharDecoratorAttribute | |
| { | |
| public function __construct(protected string $char) // Constructor Property Promotion | |
| { | |
| } | |
| public function decorate(Closure $fn): Closure |