9 Tips for Shorter Laravel Code

Поделиться
HTML-код
  • Опубликовано: 12 дек 2024

Комментарии • 119

  • @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 :)

  • @rahulg8872
    @rahulg8872 3 года назад +3

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

  • @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.

  • @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

  • @180695
    @180695 3 года назад +1

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

  • @zHqqrdz
    @zHqqrdz 3 года назад +1

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

  • @x-drake4153
    @x-drake4153 2 года назад

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

  • @Fraps224
    @Fraps224 2 года назад

    best laravel channel ever. thank you man

  • @eleazarfederio1718
    @eleazarfederio1718 3 года назад

    the best laravel channel

  • @JenuelDevTutors
    @JenuelDevTutors 3 года назад

    laravel daily is the best!

  • @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()

  • @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.

  • @MuhammadArnaldo
    @MuhammadArnaldo Год назад

    Thank you, I love this kind of content.

  • @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)

  • @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

  • @raamonmaia
    @raamonmaia 2 года назад

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

  • @chang112x
    @chang112x 3 года назад

    This video is gold

  • @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 3 месяца назад

      @@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.

  • @kreaweb-be
    @kreaweb-be 3 года назад

    Very nice tips. Thanks.

  • @programming_tips_bd
    @programming_tips_bd 2 года назад

    Thank you, it helps lots

  • @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

  • @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"

  • @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.

  • @Alejandro5577
    @Alejandro5577 2 года назад

    Thanks!! Very useful

  • @marchinton
    @marchinton 3 года назад

    I love these videos

  • @webjaved
    @webjaved 3 года назад

    Awesome video!

  • @aomo5293
    @aomo5293 3 года назад

    Great tutorial

  • @khizer3528
    @khizer3528 3 года назад

    Excellent stuff ❤️

  • @seyidtakele8158
    @seyidtakele8158 3 года назад

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

  • @danielcastillo7133
    @danielcastillo7133 3 года назад +1

    Cool, i knew all tips

  • @ivan.silicin
    @ivan.silicin 3 года назад

    Good information, thanks

  • @Rohitkumar-vq1yk
    @Rohitkumar-vq1yk 3 года назад

    Thank you sir .. 🙏

  • @travholt
    @travholt 3 года назад

    Love these videos!

  • @rubenramirez2710
    @rubenramirez2710 3 года назад

    Awesome video

  • @mithudas6873
    @mithudas6873 3 года назад

    Love this ❤️
    Just awesome.

  • @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.

  • @muhammadmuneeb4122
    @muhammadmuneeb4122 3 года назад

    Quality stuff ❤ thanks man

  • @noushedakib1658
    @noushedakib1658 Месяц назад

    thank you sir

  • @AkhileshYadav-lv3kh
    @AkhileshYadav-lv3kh 2 года назад

    Great sir

  • @justinphilip4235
    @justinphilip4235 3 года назад

    Thank you ♥️

  • @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.

  • @АйдарЖусупов-ь9э
    @АйдарЖусупов-ь9э 3 года назад

    Thanks a lot!

  • @raminsadeghnasab9310
    @raminsadeghnasab9310 2 года назад

    Good tips,

  • @llBestBoyll
    @llBestBoyll 2 года назад

    cool video 👌🏼

  • @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.

  • @qskyisover8153
    @qskyisover8153 3 года назад

    Thanks you a lot for your videos, very helpful!

  • @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?

  • @KokilThapa
    @KokilThapa 3 года назад +1

    Sir please make a video about subdomain in laravel

  • @minhviet2023
    @minhviet2023 3 года назад

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

  • @ekwiz
    @ekwiz 2 года назад

    Great 👌

  • @zineddine_haddad
    @zineddine_haddad 3 года назад

    Great Content 3>

  • @alicenNorwood
    @alicenNorwood 3 года назад

    yay new tips

  • @GBOfficialVlog
    @GBOfficialVlog 3 года назад +1

    have you use docker for local dev?

  • @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

  • @windigo000
    @windigo000 3 года назад

    just the tips 😁👍

  •  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.

  • @GergelyCsermely
    @GergelyCsermely 3 года назад

    Thx.

  • @mallesbixie
    @mallesbixie 3 года назад

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

  • @muhammadfarhanahmed9280
    @muhammadfarhanahmed9280 3 года назад

    good content

  • @limhorsimhorn4151
    @limhorsimhorn4151 3 года назад

    Can you do laravel lumen microservices

  • @offilawNoone
    @offilawNoone 2 месяца назад

    What could be more readable than a plain conditional expression?

  • @JonibekJ
    @JonibekJ 3 года назад

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

    • @Watchdog8388
      @Watchdog8388 3 года назад

      Press Shift key while scrolling

  • @Fraps224
    @Fraps224 2 года назад

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

  • @bumblebity2902
    @bumblebity2902 3 года назад

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

  • @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

  • @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.😍

  • @yuliarahma1300
    @yuliarahma1300 3 года назад

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

  • @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.

  • @neEs6624
    @neEs6624 Год назад

    ❤❤

  • @samuelliam473
    @samuelliam473 2 года назад

    im getting some issu can you help me to fix?

  • @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.

  • @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

  • @JaiShreeRamSitaRamJi
    @JaiShreeRamSitaRamJi 11 месяцев назад

  • @Pkw4js
    @Pkw4js 3 года назад

    👏👏

  • @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 :)

  • @ruslankandiba
    @ruslankandiba 2 года назад

    💣

  • @TheXambitoGames
    @TheXambitoGames 3 года назад

    Auth::id() 😎

  • @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.

  • @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.

  • @rahulji6565
    @rahulji6565 3 года назад

    Local Taylor Otwell

  • @kirayamato6128
    @kirayamato6128 3 года назад

    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