🧼 Clean Laravel Controllers with Actions and Form Requests

  Рет қаралды 4,670

Nuno Maduro

Nuno Maduro

Күн бұрын

Live on: / enunomaduro
💎 Learn From the Laravel Masters: laracasts.com/...
🛠️ Code with JetBrains PHPStorm for world-class PHP development: jb.gg/nuno
✨ Business Inquiries & Sponsorships: nunomaduro.com...
🎥 KZbin Membership: kzbin.info...
🎮 Twitch Subscription: / enunomaduro
🌐 Stay Connected:
All My Socials: nunomaduro.com...
Twitch: / enunomaduro
Twitter: / enunomaduro
Instagram: / enunomaduro
Discord: / discord
Pinkary: pinkary.com/@n...
LinkedIn: / nunomaduro
KZbin: / nunomaduro
GitHub: github.com/nun...
Bluesky: bsky.app/profi...
Tiktok: / enunomaduro
⚡️ Affiliate Links for Software I Personally Use:
NordVPN - The VPN I trust: go.nordvpn.net...
Hover - Domain registrar and management: hover-affiliat...
Descript - Audio/video editing software: get.descript.c...

Пікірлер: 27
@99Spyder99
@99Spyder99 8 күн бұрын
I'm using form requests as much as possible. It's helps to have a clean controller functions and you can move the validation in a separate class, in this way you'll not break the Single Reponsability.
@nunomaduro
@nunomaduro 8 күн бұрын
@@99Spyder99 agree
@fasterisq2.1m76
@fasterisq2.1m76 7 күн бұрын
What if break single responsibility bro? Don't blindly follow traditional principle, The ultimate goal of engineering principles is to improve the maintainability of codebases. Separation of concerns, when applied dogmatically as separation of file types, does not help us reach that goal in the context of some applications.
@hugo-abdou
@hugo-abdou 8 күн бұрын
more more tips like this one quick and easy thanks Nuno you are the best of the best ☺☺😎😎😋😋
@florianlutze9068
@florianlutze9068 7 күн бұрын
How do you handle errors? Would you throw an exception from within your action and handle it in your controller accordingly to represent the correct status code?
@abdallakaram5376
@abdallakaram5376 7 күн бұрын
Amazing thank you very much nuno But i have a question in some maybe action return some data like array or object created is a good practice?
@carln8640
@carln8640 8 күн бұрын
This feels like an alternative to using invokeable controllers. It would be interesting to see a more detailed use case for this along with at least a glance at the action model itself and also why you'd want to cast the CreateActivityRequest into an array instead of just passing it along?
@nunomaduro
@nunomaduro 8 күн бұрын
I don't want my actions to depend on the request layer; so, i am only providing the "array" of events, and not the form request itself.
@Dzonka1
@Dzonka1 4 күн бұрын
Is it ok for code structure for example to contain Action classes and Service classes. Service would be used for fetching data only or is this not a good practice to have both Service and Action classes?
@TheCookieMafianos
@TheCookieMafianos 7 күн бұрын
I prefer it to inject actions classes within the constructor. But also really clean with your solution. How do u handle multiple actions inside your controller? Do u use them in sequence or maybe with pipes?
@romeragomezjorge
@romeragomezjorge 7 күн бұрын
I have a question about creating actions in the constructor. Will this always create all actions and only use the ones needed by the called method? As a result, will there be actions that are never used?
@thiagomrvieira
@thiagomrvieira 7 күн бұрын
I wouldn't inject an action in the constructor if the action is used in one method only
@abdullah.alhabal
@abdullah.alhabal 5 күн бұрын
what about the error handling? what inside the action itself? and what about if we have a transaction (create order, apply discount, trigger an event) are this approach of (controller-actions) is helpful? or making a service-layer is more better?
@gazorbpazorbian
@gazorbpazorbian 8 күн бұрын
interesting video, but why this convention? I think I missed something, what if there are other methods like delete activity?
@vikilaboy
@vikilaboy 4 күн бұрын
The missing piece is the type that FormRequest is returning. It would be way better to return a DTO instead of that array. At least on my projects I did something to do that
@seyidtakele8158
@seyidtakele8158 8 күн бұрын
Thank you, how about making the action invokable?
@nunomaduro
@nunomaduro 8 күн бұрын
@@seyidtakele8158 could be an option. however, feel that “execute” or “handle” reads better .
@zakharg
@zakharg 5 күн бұрын
201 response status code requires not empty body, isn't it? I prefer return only 204 when body is empty.
@brunoggdev6305
@brunoggdev6305 3 күн бұрын
Why the controller name on the singular tho?
@nunomaduro
@nunomaduro 2 күн бұрын
@@brunoggdev6305 why not
@brunoggdev6305
@brunoggdev6305 2 күн бұрын
@@nunomaduro Oh, so it's more like a personal preference thing? It's just that the way you said made me think there was some elaborate reasoning behind it, but no problem at all! Also kudos from Brazil 😁 Keep up the great work
@drugoviic
@drugoviic 7 күн бұрын
i only create actions when i have to do more than crud operations
@sidalifetoumi
@sidalifetoumi 8 күн бұрын
why dont you return the created object ??
@nunomaduro
@nunomaduro 8 күн бұрын
@@sidalifetoumi because i dont need it to be returned ?????
@99Spyder99
@99Spyder99 8 күн бұрын
Depends by scenario, maybe he don't need to display the created object in the end, maybe he just display a success message based on the status code 200 and then refresh the list which automatically will get the last data.
@nunomaduro
@nunomaduro 8 күн бұрын
@ Exactly
Laravel Actions: The Secret Sauce
4:06
Nuno Maduro
Рет қаралды 10 М.
小丑女COCO的审判。#天使 #小丑 #超人不会飞
00:53
超人不会飞
Рет қаралды 16 МЛН
IL'HAN - Qalqam | Official Music Video
03:17
Ilhan Ihsanov
Рет қаралды 700 М.
Каха и дочка
00:28
К-Media
Рет қаралды 3,4 МЛН
Premature Optimization
12:39
CodeAesthetic
Рет қаралды 856 М.
How to OVER Engineer a Website // What is a Tech Stack?
11:20
Fireship
Рет қаралды 2,6 МЛН
4 Problems with Eloquent Soft Deletes (and Two Alternatives)
9:05
Laravel Daily
Рет қаралды 15 М.
Modern Python logging
21:32
mCoding
Рет қаралды 219 М.
🚨 AVOID This Mistake in Your Laravel DB Transactions
2:35
Nuno Maduro
Рет қаралды 4,2 М.
Laravel API Code Review: Inconsistent Code May Cost You a Job
10:47
My best CSS tips from 2024
16:55
Kevin Powell
Рет қаралды 25 М.
Laravel Octane: supercharge your Laravel applications
8:34
Aaron Francis
Рет қаралды 53 М.
小丑女COCO的审判。#天使 #小丑 #超人不会飞
00:53
超人不会飞
Рет қаралды 16 МЛН