[03/10] Laravel Travel API: Public Endpoint for Tours with Tests

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

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

  • @FarazSamapoor
    @FarazSamapoor Год назад +4

    Thank you Povilas! These videos are great. Grateful for your invaluable contributions!

  • @damdam1925
    @damdam1925 Год назад +1

    I dont comment much but I really like to listen you. Im learning more 🎉

  • @yungifez
    @yungifez Год назад +3

    I'm a test first guy now
    Definitely harder in crud style applications 😊

  • @Blue-xi8gu
    @Blue-xi8gu Год назад +3

    awesome. just curious, is `is_public` check for the parent table `travel` not needed here?

    • @LaravelDaily
      @LaravelDaily  Год назад +1

      Good point, probably should add it.

  • @АртурЗарипов-ю9п

    Thank you very much!

  • @thehonestabe
    @thehonestabe Год назад +1

    Thanks for these great videos! I was reading some people's very good suggestions in the comment section, I think we could have a great video of you addressing these suggestions?

    • @LaravelDaily
      @LaravelDaily  Год назад +1

      Yes it's in plans, later, with improvements

  • @techfuture-code-tv
    @techfuture-code-tv Год назад

    Awesome, am now getting testing unit test and feature test concept now great mentor.
    Thank you sir.
    Please help us do tutorial on saving and retrieving files to S3 bucket of aws while the application hosted on normal shared server

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

      I don't work with shared servers, to me they are not normal, sorry. I use mostly digital ocean or aws.

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

    Should we keep unit test code in industry projects?

  • @binuraernest3988
    @binuraernest3988 Год назад +1

    Hi, A big thanks for this series. one question though. if we were to test the price saved in database, could we just add a assertDatabaseHas inside the test_tours_price_is_shown_correctly test, or since its related to database, should it be done in a different test class?

    • @LaravelDaily
      @LaravelDaily  Год назад +1

      In my case, I wanted to test whether it's *returned* correctly. Whether it's saved in the database correctly - it's a good point to add such assertion, and I would probably add it in the same method, as just another "by the way" assertion.
      Though, to be honest, it's totally your personal preference how to structure test files/methods/assertions, I've seen a lot of different structures from different people.

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

    great job

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

    Great
    How did you inser the record in Tour Model in the database ? I get the empty respoonse when i send thhe request

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

    Great Course! Thanks for sharing!
    What do you think of having a specific controller `TravelToursController`? Since the cruddy by design suggests that kind of approach

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

      Yeah I would agree with that as alternative approach, but then I would implement full nested resource controllers

  • @xenaio
    @xenaio Год назад +1

    I think your first test is incorrect: you should probably create 2 travel objects with tours for them, so test could check if your code select exactly tours of specified travel (not both of them).
    Additionally I would test what your code will do with:
    - 2 travel with same names (probably with selecting the second one, to avoid auto selected first one by insert order)
    - URL like '/api/v1/some-travel-%/tours/' (and other potential injections)

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

    Nice Tutorial, but you must doing a lot of stuff in background. You need the relationships in model, constrains in migration. If you have a little bit experience in Laravel, so its cool. But not sooo beginner friendly.

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

      Yes, I'm not shooting my tutorials for total beginners, sorry.

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

    I want to create a system with Laravel containing modules each module can work alone and copy to another project with the same core structure without causing any problems the system in the future will be able to manage companies with many branches like gyms, schools, spas...
    And I have those modules
    subscription
    invoices
    coupons
    notifications
    permissions
    Payment gateways
    how can I make a MySQL table for invoices to fit this variant

    • @LaravelDaily
      @LaravelDaily  Год назад +1

      I would make those as packages not modules, each with their own DB tables and configurable settings. Unfortunately can't comment more as it's not a short question so can't answer in a RUclips comment

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

      ​@@LaravelDaily thanks a lot for your reply if you can call me I want to discuss many things with you I am working on laravel for 7 years
      We will come up with better solutions for many issues

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

      Sorry I don't have time available for personal consultations.

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

      @@LaravelDaily no problem, and thanks again
      maybe we will meet someday

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

    My mini code review for you Povilas
    First use method query when using where to add type hinting to query methods like this Travel::query()->where
    Second, if you use phpstorm configure on save cleanup code which simplifies class namespaces in code when you write new routes

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

      Thanks for the review! For query() I use it when it makes sense.
      For phpstorm, I have a bad habit of still doing some things manually instead of thinking "what was that shortcut..". Need to get better.

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

    FAILED Tests\Feature\TourListTest > tours list by travel slug return correct to…
    Unable to find JSON fragment:
    [{"id":"996aee6f-ab39-4121-bad0-93e4794a4be2"}]
    within

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

      Sorry I can't debug it for you just from that error message. I created the record with a factory, in the beginning of the same method.

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

    Thanks Povilas for these contents.
    I was trying to do the test tours by travel slug list differently
    ```
    $travel = Travel::factory()->create();
    $tour = Tour::factory(2)->create(['travel_id' => $travel->id]);
    $response = $this->get('/api/v1/travels/' . $travel->slug . '/tours');
    $response->assertStatus(200);
    $response->assertJsonCount(2, 'data');
    // $response->assertJsonFragment(['id' => $tour->id]);
    ```
    how do i get $response->assertJsonFragment to work, since more than one data is returned?

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

      Ok I just did $response->assertJsonFragment(['id' => $tour[0]->id]); to essentially pass the test for the first element. Hope there is a better way to test

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

      It's the case of "whatever works for you", in my opinion :)