Junior Code Review: 13 Tips from Cryptocracy Project

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

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

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

    Thanks as always Povilas. You are almost at 75k, what a milestone!! Don't stop now, keep pushing!

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

    Also scopes is a good practice. I'd replace all those 'where's to scopes, since they are used many times

  • @Shez-dc3fn
    @Shez-dc3fn 3 ปีที่แล้ว +4

    ternary operators are good if you have just one conditional, in this case you had two and if, if statement is quite intensive, then i would leave it as the long version if couple of variables depend on it.
    but in this example they could initialise the two variables as null and then use if to do what they do so no else..

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

    Good review bro :3 I learn so much

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

    7:41 using array_values() instead of Collection's values() method for some reason.
    8:45 I disagree, but it would look nicer if the non-relationship related methods were in a trait, or at least were all grouped (first all accessor/mutators, then relationships, then the "game methods").

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

    I would create a scope function inside the model for those long queries in the controller

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

    7:11 There is a N+1 issue from that map

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

    Hello everything is fine? I'm from Brazil and I love your content! congratulations. A doubt that I didn't understand much in the video. when we need to create a certain function, but this function will not be called in the route, but it will be a function that has only a random logic, so the ideal is to take this function from the controller and play it to a service? thank you in advance and if you answer me it would be very grateful :)

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

    I'm actually not agree with grouping routes by middleware. Usualy different routes may have different combinations off middleware pipes, so in case you change it, you will need to change the whole structure of your route groups. The correct way to group is by their meaning which usualy separated by route prefix. For example admin routes, auth routes, resources etc. In this case there may be general middlewares which you can add to the whole group or to a single routes in this group. This is also gives you a tree-like vision of all routes from a whole route file.

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

      Well yeah, I agree, what I mostly meant is to group by *something* instead of repeating middlewares and putting it all in one bigger routes file.

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

    Did I just heard 20 years. After working 2 years on PHP I got bored and looking for job change with other domains/languages and this man. This will take some time to sink in. Big salute sir.

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

      Well yeah, I created my first website at 16. Now I'm 36.

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

    Still a newbie to Laravel, where would you suggest I start from?

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

      You can follow my roadmap: github.com/LaravelDaily/Laravel-Roadmap-Learning-Path

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

    5:21 I mostly use in_array method instead of preg_match if I have fewer values like this case is 3 only.

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

    Using global functions in Laravel should be avoided. This is secretly façade noise. I see nothing wrong with this developer using Config::get() as it doesn't attach the codebase to the framework.
    You can see this pattern be reused such as Shortlink::get() elsewhere. This keeps convention.
    Overall, solid review! It's nice to see these. Lots of good reminders.

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

    In what cases should we use the "fillable" configuration in our models?

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

      I advise to use them all the time.

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

      @@LaravelDaily OMG 😱 Thank you so much, you are a total hero.

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

    5:04 the person is using env(). Env() should be avoided, and create a config file or use any other config file. In the moment you cache your config (that you should do in production) env gonna return null.

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

    First well done Angad Singh and keep up the learning process.
    Second I actually like how you have structured and might "borrow" that idea :)
    Lastly, where are you hosting it and you find it difficult to deploy?

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

    Wow Povilas, I'm starting with Laravel and now I'm learning how to make my API, well, in another comment I saw your repository, I'll read it to support myself with the path. Thanks for sharing your knowledge. Now can you suggest any article or video to help me with the API update? I can't (yet) update the image from the postman, thank you very much! Sorry for so much text :(

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

      What do you mean by "API update"? Can you give more details, what is the "image" - is it a file, or text field, and what do you want to happen on that update?

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

      Uploading files only work with POST method. Make sure you are using POST method. You can not use methods other than POST method to upload a file. Unfortunately.

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

      @@LaravelDaily from postman I try to update the image (which is a file) of a 'book' and if I do it by sending everything from a form it tells me that the first field cannot be empty, but it is not, so I tried to update by sending it a JSON and If I update correctly, but my question is, how do I update the image if I cannot send it from postman?

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

      @@AlanD20 but that's how I asked Povilas, so how do we update the postman image? I just can not? And then how do I save it when I send it from a front?

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

      First, make a route for POST method, then you can validate the file for example:
      _$request->validate([_
      _'profile_image'=> ['file','image','mimetypes:image/jpeg,image/png',_
      _'mimes:jpg,png'],_
      _]);_
      after validation, you can get the file with file method as following:
      _$file = $request->file('profile_image');_
      then you can save the file with store method, first argument is the location of your image to be saved, second is what driver you want to save into. public driver means it will be saved in public folder in your *storage/app/public* .
      _$file->store('images', 'public');_
      You can find your image in your laravel project, *storage/app/public/images/my_image.jpg*
      You can find more information in laravel documentation: *laravel.com/docs/8.x/requests#files*
      Regarding, how you can use postman to send a file, create a new request in Postman then put your URL, after that, make sure in headers section you set the *accept* to *application/json* if you cant find that one you can just add it manually by defining the key to *accept* and the value should be *application/json.* After that, You can only send file in *form-data only,* so make sure set *form-data* in your body, then define the key which we set *profile_image* and change the Text to file, then you can upload a file through postman.
      *Remember,* form-data sends data only in string format, so if you are sending other data types along with your image, for example, you may want to send price of a book along with the image of the book, when you get both request from your backend, you get both of them in string data type, so if you have validation for price that should be numeric, you might encounter errors, so, there are many ways to do it. first method is, I would suggest to make specific route only to upload images. Second method is, you can create middleware to convert the requests to their original data type then send it for validation. *Remember Middleware works before validation.* Third method is, if you are using form request validation you can define *prepareForValidation()* method in your form request. there are many work around to get it done. more information regarding in Laravel documentation:
      *middleware: **laravel.com/docs/8.x/middleware*
      *prepareForValidation Method: **laravel.com/docs/8.x/validation#preparing-input-for-validation*
      *Additional steps to upload a file through postman*
      -sometimes, you may not be able to upload file through postman, to fix the issue all you have to do, go to your postman settings at the top right of your menu bar, then go to General, after that, scroll down and make sure to enable *Allow reading files outside working directory* .
      -Another issue is, sometimes after enabling that option you may also not be able to upload, again if the first solution doesnt work, try to make *Postman* folder in your *C:\Users\%USERPROFILE%* then a new folder inside your Postman folder by *files* . The final location would be an empty folder at *C:\Users\%USERPROFILE%\Postman\files*
      I believe both should work fine. Let me know if you encouter any errors

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

    Thanks :) What keyboard you use?

  • @AneesKhan-uz4mz
    @AneesKhan-uz4mz 3 ปีที่แล้ว +1

    all hail dq

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

    This is gold mine. Who wants some gold?

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

    That unnecessary variable is just a trust issue i dont know why it happens to me a lot too😂

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

    You hide the developer, but we can see him in his Github

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

      Yes later I noticed that there was no point in hiding

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

    Fun fact
    Uncle Bob would tell you to not do things the laravel way😂😂😂😂