1
0
Fork 0
mirror of https://github.com/archtechx/laravel-tips.git synced 2025-12-12 05:14:04 +00:00

Week 17/2022

This commit is contained in:
Samuel Štancl 2022-04-29 21:07:03 +02:00
parent cb1970a9bf
commit 23979938b4
7 changed files with 89 additions and 0 deletions

View file

@ -0,0 +1,15 @@
---
title: 'You can define default model data for BelongsTo relationships'
tweet_id: '1520040284783972352'
thread_slug: weekly-thread-2022-17
author_username: cosmeescobedo
images:
- 'https://pbs.twimg.com/media/FQ6XRnBVgAAHT1w.jpg'
created_at: 2022-04-29T14:00:19+00:00
slug: 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.

View file

@ -0,0 +1,13 @@
---
title: 'You can dynamically create and extend interfaces in PHP'
tweet_id: '1520040287719944192'
thread_slug: weekly-thread-2022-17
author_username: freekmurze
images:
- 'https://pbs.twimg.com/media/FRLy5UXWYAIRIet.jpg'
created_at: 2022-04-29T14:00:20+00:00
slug: you-can-dynamically-create-and-extend-interfaces-in-php
---
🔥 Did you know you can dynamically create and/or extend interfaces in #PHP?
Example from the @pestphp codebase: https://github.com/pestphp/pest/blob/1.x/src/Contracts/HasPrintableTestCaseName.php

View file

@ -0,0 +1,13 @@
---
title: 'You can make concurrent requests using the Http client''s `pool() method'
tweet_id: '1520040293952675840'
thread_slug: weekly-thread-2022-17
author_username: cosmeescobedo
images:
- 'https://pbs.twimg.com/media/FQ6aAz0VgAARieH.jpg'
created_at: 2022-04-29T14:00:21+00:00
slug: you-can-make-concurrent-requests-using-the-http-clients-pool-method
---
🔥 Laravel Tip: Concurrent Requests.
Using the HTTP client you can make concurrent requests using the pool method.

View file

@ -0,0 +1,11 @@
---
title: 'You can use Eloquent''s `exists()` method to check whether a record exists'
tweet_id: '1520040290911879168'
thread_slug: weekly-thread-2022-17
author_username: ecrmnn
images:
- 'https://pbs.twimg.com/media/FRXTNRNWUAA7JtE.jpg'
created_at: 2022-04-29T14:00:20+00:00
slug: you-can-use-eloquents-exists-method-to-check-whether-a-record-exists
---
This is old, but still a great feature. Eloquent is so smooth! Check if a record exists in Laravel with exists() and doesNotExists()

View file

@ -0,0 +1,11 @@
---
title: 'You can validate a field and exclude it from the validated() data'
tweet_id: '1520040281818550274'
thread_slug: weekly-thread-2022-17
author_username: mattkingshott
images:
- 'https://pbs.twimg.com/media/FRLzG4QXEAAOfyA.jpg'
created_at: 2022-04-29T14:00:18+00:00
slug: 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...

View file

@ -0,0 +1,15 @@
---
title: 'You can validate JSON columns at the database level'
tweet_id: '1520040296930705408'
thread_slug: weekly-thread-2022-17
author_username: tobias_petry
images:
- 'https://pbs.twimg.com/media/FRQ0DmDXsAE_gbI.jpg'
created_at: 2022-04-29T14:00:22+00:00
slug: you-can-validate-json-columns-at-the-database-level
---
⚡️ Database Tip
Extending a traditional database schema with NoSQL-like JSON columns can make the schema more understandable. But you should also ensure these JSON documents conform to an expected schema!
https://sqlfordevs.io/tips/json-schema-validation