Do not speak Portuguese? Translate this site with Google or Bing Translator
Eloquent Fill and Insert Method in Laravel 12.6

Posted on: April 07, 2025 03:25 PM

Posted by: Renato

Categories: Laravel

Views: 38

Eloquent Fill and Insert Method in Laravel 12.6

Eloquent Fill and Insert Method in Laravel 12.6 image

The Laravel team released v12.6.0, which includes an Eloquent fillAndInsert() method, a URI path segments helper, a Password appliedRules() method, and more.

Allow Merging Model Attributes Before Insert

Luke Kuzmish contributed a fillAndInsert() method to "manually cast values to primitives, set timestamps, or set UUIDs":

ModelWithUniqueStringIds::fillAndInsert([
[
'name' => 'Taylor', 'role' => IntBackedRole::Admin, 'role_string' => StringBackedRole::Admin,
],
[
'name' => 'Nuno', 'role' => 3, 'role_string' => 'admin',
],
[
'name' => 'Dries', 'uuid' => 'bbbb0000-0000-7000-0000-000000000000',
],
[
'name' => 'Chris',
],
]);

See Pull Request #55038 for details.

Add HTTP Request Exception

Luke Kuzmish contributed a requestException() method to use when you manually need to stub out an exception for the HTTP client:

// Before
$exception = new RequestException(
new Response(
Http::response(['code' => 'not_found', 404)->wait()
)
);
 
// After
$exception = Http::requestException(['code' => 'not_found'], 404);

See Pull Request #55241 for details.

URI Path Segments Helper Method

Chester Sykes contributed a new pathSegments() method to the Uri class that returns each part of the URI path as a collection of elements:

$uri = Uri::of('https://laravel.com/one/two/three');
 
// Manually
$firstSegment = collect(explode('/', $uri->path()))->first(); // 'one'
 
// Using the pathSegments() method
$firstSegment = $uri->pathSegments()->first();

Password appliedRules Method

@devajmeireles contributed an appliedRules() method to the Password fluent rule builder. The appliedRules() method returns an array of password validation rules and their usage statuses.

Given the following code to define your app's password rules:

Password::defaults(function () {
return Password::min(8)
->mixedCase()
->numbers();
});
 
// In a view
return view('livewire.profile', [
'appliedRules' => Password::default()->appliedRules(),
]);
<div>
<form wire:submit="save">
<div>
<x-input label="Password" />
 
<span>{{ __('The password must be at least :min characters long.', ['min' => $appliedRules['min']]) }}</span>
 
@if ($appliedRules['mixedCase'] === true)
<span>{{ __('The password must contain at least one uppercase and one lowercase letter.') }}</span>
@endif
 
@if ($appliedRules['numbers'] === true)
<span>{{ __('The password must contain at least one number.') }}</span>
@endif
</div>
<x-button type="submit">
Save
</x-button>
</form>
</div>

See Pull Request #55206 for implementation details.

Make the db:seed Command Prohibitable

Benedikt Franke contributed the ability to make the SeedCommand prohibitable in certain environments. The SeedCommand is not prohibited when calling prohibitDestructiveCommands(), however, after Pull Request #55238 you can call the following to prohibit the db:seed command:

DB::prohibitDestructiveCommands();
SeedCommand::prohibit();

Do Not Stop Pruning if One Model Fails

Günther Debrauwer contributed an update to the model:prune command that continues running after an exception:

When you run model:prune command and an exception occurs during the pruning process of a single model, than the entire command will fail. I had this issue recently in a project. That meant no models were being pruned until I fixed the bug that prevented the pruning of a single model.

This PR fixes that. The model:prune command will skip the models that could not be pruned and report the exceptions that occurred when pruning those models.

See Pull Request #55237 for details.

Release notes

You can see the complete list of new features and updates below and the diff between 12.5.0 and 12.6.0 on GitHub. The following release notes are directly from the changelog:

v12.6.0

# Fonte: - https://laravel-news.com/laravel-12-6-0

3

Share

Donate to Site


About Author

Renato

Developer

Add a Comment
Comments 0 Comments

No comments yet! Be the first to comment

Blog Search


Categories

100DaysOfCode (9) adb (1) agi (1) akitando (1) algoritimo (1) altadisponibilidade (1) android (2) angular (3) angularjs (4) apache (4) api (5) API_KEY_GOOGLE_MAPS (1) aplicativo (1) apple (1) AppSec (1) Architecture (4) ArchLinux (1) arquitetura (3) artigo (2) athena (1) autenticacao (2) auth (1) auth (1) authentication (4) authorization (3) autorizacao (2) aws (14) Axios (1) backend (13) backup (1) banco (1) bancodedados (2) bash (3) BigLinux (2) binaural (1) biologia (1) Black Hat (3) blade (3) bolsonaro (1) boot (1) brain (1) Brasil (1) bug (1) c4 (1) c4-models (1) cache (1) cavalotroia (1) certbot (1) chatgpt (1) ciencia (6) cinnamon (1) ckeditor (1) CMS (2) collections (1) colors (2) combustivel (2) community (1) compactar (1) composer (1) compression (1) containers (3) controllers (0) cor (1) covid19 (1) cqrs (1) cron (2) csv (1) Curisidades (1) data (1) database (42) db (3) dba (18) ddd (3) debian (12) Deepin (1) dev (12) developer (37) devops (25) DevSecOps (4) Diagramas (1) Dicas (45) Docker (28) documentation (1) dracula (1) dropbox (1) ec2 (1) ecommerce (1) economia (1) educacao (1) Elasticsearch (1) ElonMusk (2) eloquent (14) Error (1) escopos (1) eventdrive (1) faceapp (1) federal (1) fedora (2) Fetch (1) ffaa (1) ffmpeg (2) Fibonacci (1) Filament (1) firefox (1) flow (1) flutter (1) forcas armadas (1) front-end (29) gasolina (1) git (9) github (5) gitlab (3) GitOps (1) gnome (2) google (4) gource (2) governancadedados (1) gpt (1) Grunt (1) guard (1) hardware (3) haru (1) historia (1) homeOffice (2) host (1) hotfix (1) htm (1) html (2) http (1) ia (1) ibm (1) idiomas (1) imagick (2) intel (3) inteligencia-artificial (3) inteligenciadedados (4) iode (1) iot (1) JasperReports (1) java (1) javascript (7) jenkins (4) jobs (3) JQuery (1) js (1) json (2) jwt (5) k8s (1) kali-linux (1) kitematic (1) kube (2) KubeCon (1) Kubernetes (3) l2tp (1) laptop (2) Laravel (175) LaravelFilament (1) laraveloctane (1) laravelphp (10) lets-encrypt (3) LETSENCRYPT (1) lider (1) linkedin (1) linux (118) linux-tools (6) liquid (1) livros (2) llama (1) log (1) lucena (1) lumen (1) mac (2) macos (2) macox (4) magento (2) Manjaro (1) maps (1) mariadb (4) markdown (1) matematica (1) MeioAmbiente (1) memcached (1) messaging (1) microg (1) microservice (1) microservices (2) Migration (1) militar (1) modelagemdedados (1) models (1) mongodb (4) Monitor (1) monitoring (2) Monolith (1) Mozilla (1) multiple_authen (2) mysql (31) mysqli (3) networking (1) nginx (9) NoCookies (1) node (7) nodejs (5) nosql (1) noticias (2) npm (3) nuance (1) nuxt (1) nvidia (1) nvm (1) Oauth2 (2) Observability (1) octane (1) October (1) odd (1) Oh My Zsh (1) OOD (0) openai (3) opensource (3) optimization (1) oracle (1) orm (1) OUTROS (17) Padrao de design (4) Passport (2) Passwordless (1) payment (1) paypal (1) pendrive (1) performance (3) PHP (133) PHP Swoole (5) phpfpm (1) phpjasper (1) phpswoole (1) phpunit (2) piada (1) picpay (1) pipelines (1) PKCE (1) podcast (1) policia (2) politica (2) POO (2) postgresql (42) presenter (1) prf (1) privacidade (1) programming (22) Python (1) pytorch (1) query (4) queue (1) RabbitMQ (3) rancher (1) Raspberry (4) react (7) reactjs (8) reactnative (5) redis (2) replication (1) repmgr (1) rest (5) restfull (1) rpi (1) ruby (1) rust (1) RustLang (1) s3 (4) sail (3) Samurai (1) saude (1) scheduling (1) script (3) security (2) seguranca (2) servers (4) services (1) shell (4) smartphones (1) soap (1) Solid (2) sonarqube (1) spaceship (1) sql (41) sqlite (1) ssh (3) storage (1) Structurizr (1) sw (1) Swoole (1) Swoole (1) symfony (1) tailwind (1) tecnologia (14) telefonia (1) tensorflow (1) terminal (3) traefik (1) transaction (1) Transcribe (2) transcription (1) transformers (1) translate (1) TypeScript (1) ubuntu (57) unix (2) usb (1) vala (1) Variados (109) vicuna (1) vim (4) vpn (1) vscode (3) vue (4) web (2) webdev (24) webhook (1) webservice (6) websocket (2) windows (6) wine (1) wsl (4) wsl2 (1) yarn (0) zend (1) zorin-os (1) zsh (2)

New Articles



Get Latest Updates by Email