9 Tips for Shorter Laravel Code

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 พ.ย. 2024

ความคิดเห็น •

  • @pramod9200
    @pramod9200 3 ปีที่แล้ว +106

    Day by day this channel becoming gold mine for laravel developer.

  • @mabdullahsari
    @mabdullahsari 3 ปีที่แล้ว +25

    00:20 - Shorter @if auth()->check()
    01:15 - Shorter Auth user in Blade
    02:37 - Shorter @foreach
    03:31 - Shorter Carbon::now()
    04:31 - Shorter Log::info() and dd()
    06:01 - Shorter abort()
    07:07 - Shorter CSRF and Method
    08:05 - Shorter Hash::make()
    09:11 - Shorter redirect()->back()

    • @LaravelDaily
      @LaravelDaily  3 ปีที่แล้ว +3

      I think I've made this list, see the description of this video, or it didn't work for you?

    • @mabdullahsari
      @mabdullahsari 3 ปีที่แล้ว +3

      @@LaravelDaily Mobile :)

    • @MohAliii
      @MohAliii 3 ปีที่แล้ว

      Works for me on mobile 👌

    • @warrenarnold
      @warrenarnold 3 ปีที่แล้ว

      @@LaravelDaily prolly just he's used to doing that, dont think harm was intended

  • @KatieGeorgieva
    @KatieGeorgieva 3 ปีที่แล้ว +9

    info() can be seen directly in the debugbar, so no need to look into the Log file :)

  • @180695
    @180695 3 ปีที่แล้ว +1

    This videos is really helpful about shorten written functionality of famous laravel development tool thank so much and really appreciated!

  • @rdvr
    @rdvr 3 ปีที่แล้ว +7

    The @if with a @foreach still makes sense for when your results are in a table with headings and you don’t want to show the table unless there are results.

  • @x-drake4153
    @x-drake4153 2 ปีที่แล้ว

    I cant believe how much knowledge you share. It s inredibcle

  • @zHqqrdz
    @zHqqrdz 3 ปีที่แล้ว +1

    Simple, straight to the point, effective. Amazing video, thanks.

  • @kangzoel8717
    @kangzoel8717 3 ปีที่แล้ว +15

    If you're flashing a session whenever user interracts with a model, you can use observer instead of flashing the session manually in every crud methods.

    • @deastortion
      @deastortion 3 ปีที่แล้ว +1

      dude, that's a really good idea

  • @Fraps224
    @Fraps224 2 ปีที่แล้ว

    best laravel channel ever. thank you man

  • @aregsarkissian2686
    @aregsarkissian2686 3 ปีที่แล้ว +3

    Thanks for another excellent tutorial. Been a fan of your Laravel contributions for a while. I do want to mention one thing though when you said that sometimes junior developers pass the User from the controller to the view. I actually think it is the opposite. Senior developers understand that you want to remove logic as much as possible from your views and just pass dumb data into views. This makes all your logic testable by checking the data being passed into the view in your tests. In fact I would even go further and say you shouldn't pass the User into the view and instead just pass a user_is_authenticated bit into the view that the view can check. Now in this specific case I don't think doing the auth check using the Laravel helper in the view is bad, because Laravel is a well tested framework. I only want to make sure that the junior developer statement does not make developers think, that pulling logic out of the view and then passing in the resulting data into views, makes them a junior dev.

    • @SergeyNeskhodovskiy
      @SergeyNeskhodovskiy 2 ปีที่แล้ว

      You make a good point. Overall, I find the entire blade somewhat archaic in front of the JAMStack approach in general.

  • @eleazarfederio1718
    @eleazarfederio1718 3 ปีที่แล้ว

    the best laravel channel

  • @JenuelDevTutors
    @JenuelDevTutors 3 ปีที่แล้ว

    laravel daily is the best!

  • @MuhammadArnaldo
    @MuhammadArnaldo ปีที่แล้ว

    Thank you, I love this kind of content.

  • @cardboarddignity
    @cardboarddignity 3 ปีที่แล้ว +2

    In order to dump some data in the view, not in the log file while keeping the other code executing, simply use dump() instead of dd()

  • @sportsandstudy6985
    @sportsandstudy6985 2 ปีที่แล้ว +1

    Sir you learned these tips in 5 years of experience. And i uses these tips from first day of laravel😂😂🥰 By the thank you sir for these tips

  • @rahulg8872
    @rahulg8872 3 ปีที่แล้ว +3

    8:55 -- you can set mutator in model to make it more clean.

  • @raamonmaia
    @raamonmaia 2 ปีที่แล้ว

    Great video! I d like more videos like this.
    Thanx!!!

  • @j.oliveira
    @j.oliveira 3 ปีที่แล้ว +8

    Some of those helpers remove the `use` but they also hide that dependency. When you open the file to read it, you won't know all the dependencies that file has because they are hidden in those helpers.

    • @Jurigag
      @Jurigag 3 ปีที่แล้ว +2

      Exactly this, i hate this about laravel community - that they try to use those helpers everywhere. In our projects we use laravel but we try to avoid those helpers as much is possible.

    • @bubblesort6368
      @bubblesort6368 3 ปีที่แล้ว

      Yeah) This is rails thinking, write less code at any cost. Laravel inherits that philosophy, but allow write better code with DI)

  • @chang112x
    @chang112x 3 ปีที่แล้ว

    This video is gold

  • @kreaweb-be
    @kreaweb-be 3 ปีที่แล้ว

    Very nice tips. Thanks.

  • @TheRetroHome
    @TheRetroHome ปีที่แล้ว

    You are the best. Thank you!

  • @JouvaMoufette
    @JouvaMoufette 3 ปีที่แล้ว +6

    I like most of these, since they're just a shorter way of doing specific things and a shorter syntax.
    The only one I can't recommend is the bcrypt one, since if you DO later decide to change that method of hashing, now you've got more than a config to change and have to find any references to bcrypt in the code.
    Everything else is great

    • @splasher2119
      @splasher2119 3 ปีที่แล้ว

      How often do you change encryption methods?

    • @renatofrota
      @renatofrota 2 หลายเดือนก่อน

      @@splasher2119 not often, but it can happen. why having to change if you can write future-proof code with 10 additional characters? you will certainly spend most time doing the change when the time comes than you need to write those 10 extra characters.

  • @itsmill3rtime
    @itsmill3rtime ปีที่แล้ว +1

    I like making a User::current(); and then depending on the project i'll also have Company::current(); or Team::current(); so i'll have the same syntax for any model that represents the user

  • @programming_tips_bd
    @programming_tips_bd 2 ปีที่แล้ว

    Thank you, it helps lots

  • @alzy101
    @alzy101 3 ปีที่แล้ว

    I love these series! I feel though that I prefer some amount of verbosity in some of the methods you mentioned. Shorter isn't always better in my opinion.

  • @Amit-018r
    @Amit-018r ปีที่แล้ว

    Very useful tips. Kindly make a video on laravel security tips please.

    • @LaravelDaily
      @LaravelDaily  ปีที่แล้ว

      I did already, search on the channel for "security"

  • @marchinton
    @marchinton 3 ปีที่แล้ว

    I love these videos

  • @Alejandro5577
    @Alejandro5577 2 ปีที่แล้ว

    Thanks!! Very useful

  • @webjaved
    @webjaved 3 ปีที่แล้ว

    Awesome video!

  • @khizer3528
    @khizer3528 3 ปีที่แล้ว

    Excellent stuff ❤️

  • @aomo5293
    @aomo5293 3 ปีที่แล้ว

    Great tutorial

  • @seyidtakele8158
    @seyidtakele8158 3 ปีที่แล้ว

    I am Happy to be the first viewer of this video .

  • @digitzero3613
    @digitzero3613 2 ปีที่แล้ว

    Maybe its just me but I'd still prefer writing the helper functions with their classes attached because it makes so much more sense while reading through the code.

  • @danielcastillo7133
    @danielcastillo7133 3 ปีที่แล้ว +1

    Cool, i knew all tips

  • @rubenramirez2710
    @rubenramirez2710 3 ปีที่แล้ว

    Awesome video

  • @noushedakib1658
    @noushedakib1658 27 วันที่ผ่านมา

    thank you sir

  • @Rohitkumar-vq1yk
    @Rohitkumar-vq1yk 3 ปีที่แล้ว

    Thank you sir .. 🙏

  • @ivan.silicin
    @ivan.silicin 3 ปีที่แล้ว

    Good information, thanks

  • @AkhileshYadav-lv3kh
    @AkhileshYadav-lv3kh 2 ปีที่แล้ว

    Great sir

  • @mithudas6873
    @mithudas6873 3 ปีที่แล้ว

    Love this ❤️
    Just awesome.

  • @raminsadeghnasab9310
    @raminsadeghnasab9310 2 ปีที่แล้ว

    Good tips,

  • @travholt
    @travholt 3 ปีที่แล้ว

    Love these videos!

  • @muhammadmuneeb4122
    @muhammadmuneeb4122 3 ปีที่แล้ว

    Quality stuff ❤ thanks man

  • @llBestBoyll
    @llBestBoyll 2 ปีที่แล้ว

    cool video 👌🏼

  • @justinphilip4235
    @justinphilip4235 3 ปีที่แล้ว

    Thank you ♥️

  • @hemantbhardwaj17
    @hemantbhardwaj17 3 ปีที่แล้ว +1

    First time i am feeling good that i already using every helper by my self from this list because of my laziness 🤣
    Thanks one question auth()->user() does it hit model Or query every time Or just once? It's better to call it one in the public var?

  • @minhviet2023
    @minhviet2023 3 ปีที่แล้ว

    your video is so good, it will be better if you add english subtitle

  • @dominikjezik303
    @dominikjezik303 3 ปีที่แล้ว +4

    There is also an alternative to dd(), which prints a nicer code - ddd() Dump Die Debug

    • @J-wd2cx
      @J-wd2cx 3 ปีที่แล้ว

      Or just dump() :)

    • @michaelkhoussid7673
      @michaelkhoussid7673 3 ปีที่แล้ว

      @@J-wd2cx That's one extra character, too lazy.

  • @mallesbixie
    @mallesbixie 3 ปีที่แล้ว

    Question: Carbon\Carbon or Illimunate\Support\Carbon? Which one and why? Or use the \Date facade?

  • @АйдарЖусупов-ь9э
    @АйдарЖусупов-ь9э 3 ปีที่แล้ว

    Thanks a lot!

  • @GBOfficialVlog
    @GBOfficialVlog 3 ปีที่แล้ว +1

    have you use docker for local dev?

  • @ekwiz
    @ekwiz 2 ปีที่แล้ว

    Great 👌

  • @a-ezzat5677
    @a-ezzat5677 3 ปีที่แล้ว

    I have a problem with websocket after upgrading to laravel 8, everything is fine except echo which is not listening,
    in blade, window.Echo.channel("mychannel").listen("eventname",(e)=>{
    consile.log(e); #not showing anything although pusher is receiving message and I am seeing event triggered in websocket dashboard page either
    }
    would you please help

  • @nikolaimoiseev8637
    @nikolaimoiseev8637 3 ปีที่แล้ว

    Hi Author!
    First of wish to really thank you for what you are doing. In my project every there weren’t any issue, solution to which I couldn’t find on your channel :)
    Wanted to ask a little bit complex question. I am new to laravel. How do you think, if my goal is to make a simple social network with profiles, news feed and status program , will laravel framework be enough for me, or Laravel is only for more simple CRUD projects?

    • @LaravelDaily
      @LaravelDaily  3 ปีที่แล้ว +1

      Laravel can handle any large projects, but it's not the framework that writes the code, so no one can guarantee that your written Laravel code will be optimized

  • @alicenNorwood
    @alicenNorwood 3 ปีที่แล้ว

    yay new tips

  • @offilawNoone
    @offilawNoone หลายเดือนก่อน

    What could be more readable than a plain conditional expression?

  • @KokilThapa
    @KokilThapa 3 ปีที่แล้ว +1

    Sir please make a video about subdomain in laravel

  • @GergelyCsermely
    @GergelyCsermely 3 ปีที่แล้ว

    Thx.

  • @bumblebity2902
    @bumblebity2902 3 ปีที่แล้ว

    Sir, is auth() helper works with custom coulmns, such as is_admin?

  • @hatsushiroyuki8697
    @hatsushiroyuki8697 3 ปีที่แล้ว

    Great content as always, didn't knew Hash::make() could be simplified using bcrypt().

    • @daleryanaldover6545
      @daleryanaldover6545 3 ปีที่แล้ว

      I was using bcrypt() when laravel was still on version 6 and didn't know there was Hash::make.

  • @pesovatech6899
    @pesovatech6899 3 ปีที่แล้ว

    Please which extension do u use that shows the highlight of a function or class when u hover on it..

    • @LaravelDaily
      @LaravelDaily  3 ปีที่แล้ว

      I use phpstorm without any extensions.

  • @qskyisover8153
    @qskyisover8153 3 ปีที่แล้ว

    Thanks you a lot for your videos, very helpful!

  • @muhammadfarhanahmed9280
    @muhammadfarhanahmed9280 3 ปีที่แล้ว

    good content

  • @windigo000
    @windigo000 3 ปีที่แล้ว

    just the tips 😁👍

  • @jannusdomingo5681
    @jannusdomingo5681 3 ปีที่แล้ว

    I wonder where the Auth::user() came from? Is it automatically select the logged in users id and do I need to use the auth command to be able to use it? Thanks and godbless

    • @LaravelDaily
      @LaravelDaily  3 ปีที่แล้ว +1

      Yes it automatically returns the logged in user, full object, not only ID.
      Another way is auth()->user() returns the same thing
      If you need only ID, then auth()->id()

    • @jannusdomingo5681
      @jannusdomingo5681 3 ปีที่แล้ว

      @@LaravelDaily basically laravel knows the table users column, because of their default User, UserModel etc. when installing a fresh laravel app. I also wonder if I can make a custom Authentication to access other column? Ex: Auth::anothertable()->get_columns

  • @JonibekJ
    @JonibekJ 3 ปีที่แล้ว

    awesome tutorial!. Hey Corp how do u scrolling in phpstorm to 4 directions?

    • @Watchdog8388
      @Watchdog8388 3 ปีที่แล้ว

      Press Shift key while scrolling

  • @limhorsimhorn4151
    @limhorsimhorn4151 3 ปีที่แล้ว

    Can you do laravel lumen microservices

  • @zineddine_haddad
    @zineddine_haddad 3 ปีที่แล้ว

    Great Content 3>

  •  3 ปีที่แล้ว

    3:34 Carbon::setTestNow( any carbon date) and now() never work for me when I am phpunit testing. now() always returns the actual system date.

  • @samuelliam473
    @samuelliam473 2 ปีที่แล้ว

    im getting some issu can you help me to fix?

  • @JaiShreeRamSitaRamJi
    @JaiShreeRamSitaRamJi 11 หลายเดือนก่อน

  • @ilyasayusuf5447
    @ilyasayusuf5447 3 ปีที่แล้ว

    thx you for the tips,
    can you do a backend tips for laravel, like creating apis.
    maybe shorter way to make
    if($request->has("name");){
    array_push($data,$request->name);
    }
    ....
    model::create($data);
    or maybe the best way to handle the error to the frontend
    instead of catch then $th->getMessage();
    i also notice that in the api routing i can't use resource for all basic controller function or it just me

    • @LaravelDaily
      @LaravelDaily  3 ปีที่แล้ว

      Please watch my playlist of Code Reviews on this channel, I touched CRUDs and APIs in a few of them.

  • @neEs6624
    @neEs6624 ปีที่แล้ว

    ❤❤

  • @yuliarahma1300
    @yuliarahma1300 3 ปีที่แล้ว

    how to i redirect to login page after page expired without refreshing the page?

  • @ruslankandiba
    @ruslankandiba 2 ปีที่แล้ว

    💣

  • @tamimikbal28
    @tamimikbal28 3 ปีที่แล้ว

    Hello sir, We want a video about" how to cofigure a laravel project on shared hosting " I have research and saw some video, They told that move index file from public to root. But l think its not a good idea. And I believe yoi will tell us a best way to configure/upload laravel project on shared hosting. Please give this video as a next daily video.😍..
    Please sir.

    • @LaravelDaily
      @LaravelDaily  3 ปีที่แล้ว

      I strongly advice AGAINST shared hosting for any Laravel project, if possible.

    • @tamimikbal28
      @tamimikbal28 3 ปีที่แล้ว

      @@LaravelDaily Yeah, its not good sir, But I have nothing to do, I am not eligible (financial problem) to purchase a VPS. 😓
      IF you can make a video then it will be really appreciate. If you haven’t shared hosting, you can use my hosting. For Videos..
      Thanks for the reply sir.😍

  • @Pkw4js
    @Pkw4js 3 ปีที่แล้ว

    👏👏

  • @Fraps224
    @Fraps224 2 ปีที่แล้ว

    02:37 Sadly this doesn't work with NULL. Or maybe someone can correct me

  • @TheXambitoGames
    @TheXambitoGames 3 ปีที่แล้ว

    Auth::id() 😎

  • @shocchosolutions6275
    @shocchosolutions6275 3 ปีที่แล้ว

    sir eloquent relationship shortcode video, please please

    • @LaravelDaily
      @LaravelDaily  3 ปีที่แล้ว

      What do you mean by "relationship shortcode"?

    • @shocchosolutions6275
      @shocchosolutions6275 3 ปีที่แล้ว

      @@LaravelDaily like sir easy and short ways to do any relationship with 2 or multiple models

    • @LaravelDaily
      @LaravelDaily  3 ปีที่แล้ว +1

      @@shocchosolutions6275 I guess it's all in Laravel documentation, I can't make it easier or shorter than this :)

  • @thatsenam9183
    @thatsenam9183 3 ปีที่แล้ว

    TailwindCSS, Thousan of line repeated messed up - No Problem
    Php (inside blade) 2 line of if else - Its time to Fixed up things. 😁

    • @j.oliveira
      @j.oliveira 3 ปีที่แล้ว

      You only repeat the css if you want. Use components. It's easier to use and manage. ;)

  • @object_name
    @object_name 3 ปีที่แล้ว

    Am i the only one that thinks, some of these helpers should not be used.
    For me they sometimes make it harder to work on the code, because you can just access them anywhere.
    For example the "auth()" - helper.
    It could be used in some blade component deep inside the navigation for example to link to the user profile without you knowing that the component requires the user to be authenticated.
    Breaking the code in a not authenticated environment.
    Also :
    abort_if, throw_if
    and alikes never felt natural to me especially since the IDE does not seem to support the control flow form for syntax highlighting and deduction of variable types.
    I in general prefer a few characters more to achieve some expressiveness where necessary.

  • @rahulji6565
    @rahulji6565 3 ปีที่แล้ว

    Local Taylor Otwell

  • @tim.bogdanov
    @tim.bogdanov 2 ปีที่แล้ว

    shorter does not always mean better.

  • @Jurigag
    @Jurigag 3 ปีที่แล้ว +9

    I will be honest - most of the time shorter doesn't mean better. Especially using helpers is kind of bad for better quality of code.

  • @kirayamato6128
    @kirayamato6128 2 ปีที่แล้ว

    Php are so bad at logging at command line. At my point i use laravel and logging some variables are stored in storage folder which in my case i don't want to. That's why i use symfony package "console output" so that it will output the variables in command line/cmd. But in most cases i doesn't accept arrays which is bullshit for me.
    In other programming languages like java, you can just use *println* in any variables you want to output in command line and it accepts string, obejcts or arrays. Simple as that.
    I don't know why PHP is like that lol