Snippets Útiles para Trabajar en Laravel
- Publicado por Carlos Sánchez
- hace 3 años
1. Determining if the record on firstOrCreate was new or not
$product = Product::firstOrCreate(...)
if ($product->wasRecentlyCreated()) {
// New product
} else {
// Existing product
}
2. Find related IDs on a BelongsToMany Relationship
$user->roles()->allRelatedIds()->toArray();
3. abort_unless()
// Instead of
public function show($ite...