9 Tips for Shorter Laravel Code

Поділитися
Вставка
  • Опубліковано 20 сер 2024

КОМЕНТАРІ • 117

  • @pramod9200
    @pramod9200 3 роки тому +105

    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

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

  • @salman-804
    @salman-804 2 роки тому +1

    Every time i watch your video, i learn something new. Keep up the good work.

  • @KatieGeorgieva
    @KatieGeorgieva 3 роки тому +9

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

  • @180695
    @180695 2 роки тому +1

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

  • @DevTutorPro
    @DevTutorPro 2 роки тому

    laravel daily is the best!

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

  • @x-drake4153
    @x-drake4153 Рік тому

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

  • @zHqqrdz
    @zHqqrdz 3 роки тому +1

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

  • @rahulg8872
    @rahulg8872 3 роки тому +3

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

  • @Fraps224
    @Fraps224 2 роки тому

    best laravel channel ever. thank you man

  • @cardboarddignity
    @cardboarddignity 2 роки тому +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()

  • @chang112x
    @chang112x 3 роки тому

    This video is gold

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

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

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

  • @TheRetroHome
    @TheRetroHome Рік тому

    You are the best. Thank you!

  • @JouvaMoufette
    @JouvaMoufette 3 роки тому +5

    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?

  • @eleazarfederio1718
    @eleazarfederio1718 3 роки тому

    the best laravel channel

  • @kreaweb-be
    @kreaweb-be 2 роки тому

    Very nice tips. Thanks.

  • @programming_tips_bd
    @programming_tips_bd 2 роки тому

    Thank you, it helps lots

  • @danielcastillo7133
    @danielcastillo7133 2 роки тому +1

    Cool, i knew all tips

  • @marchinton
    @marchinton 3 роки тому

    I love these videos

  • @MuhammadArnaldo
    @MuhammadArnaldo Рік тому

    Thank you, I love this kind of content.

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

  • @Alejandro5577
    @Alejandro5577 2 роки тому

    Thanks!! Very useful

  • @raamonmaia
    @raamonmaia 2 роки тому

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

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

  • @rubenramirez2710
    @rubenramirez2710 3 роки тому

    Awesome video

  • @AkhileshYadav-lv3kh
    @AkhileshYadav-lv3kh 2 роки тому

    Great sir

  • @raminsadeghnasab9310
    @raminsadeghnasab9310 2 роки тому

    Good tips,

  • @khizer3528
    @khizer3528 2 роки тому

    Excellent stuff ❤️

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

  • @aomo5293
    @aomo5293 3 роки тому

    Great tutorial

  • @ivan.silicin
    @ivan.silicin 3 роки тому

    Good information, thanks

  • @webjaved
    @webjaved 3 роки тому

    Awesome video!

  • @llBestBoyll
    @llBestBoyll 2 роки тому

    cool video 👌🏼

  • @Rohitkumar-vq1yk
    @Rohitkumar-vq1yk 3 роки тому

    Thank you sir .. 🙏

  • @seyidtakele8158
    @seyidtakele8158 3 роки тому

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

  • @travholt
    @travholt 3 роки тому

    Love these videos!

  • @mithudas6873
    @mithudas6873 3 роки тому

    Love this ❤️
    Just awesome.

  • @muhammadmuneeb4122
    @muhammadmuneeb4122 3 роки тому

    Quality stuff ❤ thanks man

  • @dominikjezik303
    @dominikjezik303 3 роки тому +4

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

  • @ekwiz
    @ekwiz Рік тому

    Great 👌

  • @KokilThapa
    @KokilThapa 3 роки тому +1

    Sir please make a video about subdomain in laravel

  • @justinphilip4235
    @justinphilip4235 3 роки тому

    Thank you ♥️

  • @user-ku4dv7ri2k
    @user-ku4dv7ri2k 3 роки тому

    Thanks a lot!

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

  • @qskyisover8153
    @qskyisover8153 3 роки тому

    Thanks you a lot for your videos, very helpful!

  • @minhviet2023
    @minhviet2023 3 роки тому

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

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

  • @alicenNorwood
    @alicenNorwood 3 роки тому

    yay new tips

  • @GergelyCsermely
    @GergelyCsermely 3 роки тому

    Thx.

  • @zineddine_haddad
    @zineddine_haddad 3 роки тому

    Great Content 3>

  • @muhammadfarhanahmed9280
    @muhammadfarhanahmed9280 3 роки тому

    good content

  • @windigo000
    @windigo000 3 роки тому

    just the tips 😁👍

  • @mallesbixie
    @mallesbixie 3 роки тому

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

  • @Fraps224
    @Fraps224 2 роки тому

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

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

  • @GBOfficialVlog
    @GBOfficialVlog 3 роки тому +1

    have you use docker for local dev?

  • @limhorsimhorn4151
    @limhorsimhorn4151 3 роки тому

    Can you do laravel lumen microservices

  • @samuelliam473
    @samuelliam473 2 роки тому

    im getting some issu can you help me to fix?

  • @yuliarahma1300
    @yuliarahma1300 3 роки тому

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

  • @emailaddress8835
    @emailaddress8835 3 роки тому

    I love it LARA croft wkwkwkwk👍 thanks sir🙏 GBU

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

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

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

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

  • @JonibekJ
    @JonibekJ 3 роки тому

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

    • @Watchdog8388
      @Watchdog8388 3 роки тому

      Press Shift key while scrolling

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

  • @bumblebity2902
    @bumblebity2902 3 роки тому

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

  • @neEs6624
    @neEs6624 11 місяців тому

    ❤❤

  • @TheXambitoGames
    @TheXambitoGames 3 роки тому

    Auth::id() 😎

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

  • @JaiShreeRamSitaRamJi
    @JaiShreeRamSitaRamJi 7 місяців тому

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

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

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

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

  • @Pkw4js
    @Pkw4js 3 роки тому

    👏👏

  • @ruslankandiba
    @ruslankandiba 2 роки тому

    💣

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

  • @rahulji6565
    @rahulji6565 3 роки тому

    Local Taylor Otwell

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