๐Ÿ”ฅ Weekly thread #17 of 2022

๐Ÿ”ฅ This week's code tips for Laravel developers

A weekly thread ๐Ÿงต

You can define default model data for BelongsTo relationships

2

๐Ÿ”ฅ You can define default model data for BelongsTo relationships

You can define default model data for BelongsTo relationships

๐Ÿ”ฅ Laravel Tip: Default Models.

In your relationships, you can define default models.

That way if the relationship doesn't exist it will return a default model so you don't have to check if is null every time.

You can validate a field and exclude it from the validated() data

1

๐Ÿ”ฅ You can validate a field and exclude it from the validated() data

You can validate a field and exclude it from the validated() data

๐Ÿ”ฅ #Laravel Tip: When you need to validate a field, but don't actually require it for anything e.g. 'accept terms and conditions', make use of the 'exclude' rule. That way, the 'validated' method won't return it...

We're writing a book, you can get it for free here.