Laravel Excel: Import with Relationships

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

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

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

    Using lazycollection in the constructor by rewriting the query as User::select('id', 'name', 'email')->cursor()->remember() could save you some memory. Considering imports can be often pretty large, a good idea is to use chunk reading in laravel excel (even if you don't need it at first) to prevent scaling issues.

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

      i dont find in the laravel docs about how much time this cache will be stored, since the data can be dynamic, i think this approach is not the best idea

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

    We've been struggled on understanding the eloquent query I mean the Joins. I had the idea of you making a tuts on what the left joins & inner joins means in Eloquent, I mean you show us the old way and then convert it in eloquent way. Btw all your tuts help us a lot! 🍻

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

      Added to the to-do list, will come up with some useful angle about joins

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

      @@LaravelDaily Thank you so much my fav tutor here! We're excited! 🍻😊

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

      joins don't work differently in eloquent. Unless you mean relationships, but those are not joins at all most of the time. You can dump the query to inspect the generated sql.

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

      @@intipontt7490 yeah but we do not know where to start on how to convert our joins in to eloquent

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

      Can you email me povilas@laraveldaily.com a few examples of such joins? Then I may try to convert them in the video, would be the most practically useful for everyone. @Jannus Domingo

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

    Very thanks for your video.
    hellow from Ukraine

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

    Great sir,
    At a time It will insert to Two different DB's

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

    Please provide an example if we need to import to multiple database tables from one CSV file.

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

    Very useful for me, thank you!!!

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

    Have you compared the speed of the database selects with the speed of the collection search? If there are many users, the collection search should be longer. The second question: it might be more optimal to translate the collection of users into an array, where the key is an email. Then the substitution of user IDs would occur instantly

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

      Valid points, maybe it would speed up even more, haven't tried.

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

    Awesome, thank you👏

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

    The best tutorial as always!

  • @Gosa-li1ei
    @Gosa-li1ei ปีที่แล้ว

    Thanks so much Dear Sir.

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

    Hi, your channel is helping me a lot to understand laravel better. Regarding to import from csv file, is it possible to import sheet into multiple tables? Thanks so much

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

    I have for example a user table and role table. The relation is hasMany with a pivote table between them. there is no actual column between the two tables. can we import users from csv witht the role id?

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

    Is there any way to validate unique email when emails are stored in database as encrypted data and display error message row wise in blade file.

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

    Nice Video, How to export two or more queries to excel?

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

    Sir do you have a video of multi sheet excel import in database in different tables?

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

    Thanks a lot. It is really helpful.

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

    why im running local 'error undefined index: amount' ? please help solving

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

    how about importing one excel file into 2 tables in database?

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

      What would be an example use case for such a feature ?

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

    while i am doing the same as you are but it is giving me error that undefined index title, title is present in my role class which is actually in relation with the user class one user has one role how can i fix that?

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

    Thankyoy can make how get separate array like laravel relationship with inner joins .

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

    hi bro thanks really too it is helpful but i am getting this error bro
    Trying to get property 'id' of non-object

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

    hi.. can i get simple import with multiple start and end date per id? example; one id have many start and end date.

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

    What about pivot tables?

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

    The file needs to be in csv is mandatory or it can also work with xlsx extension type?

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

      Should work with xlsx too, but try it out.

  • @fabrizziomorenor.6495
    @fabrizziomorenor.6495 2 ปีที่แล้ว

    Exist a way i can read the heading row and import in every row imported. Example CARS column..import and set in a column name category...put the CARS string.???
    :P

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

    Great example!!

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

    how to configure header columns with column names having space between like fist name

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

    What about if the `user_id` is a non-nullable foreign key?
    I realise that we could do `firstOrCreate`, but how do you then update the `users` in the constructor?

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

      You can add then to users collection, using prepend() or push() method

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

    Can you show us how to import images from excel file?

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

    Thanks for your video!
    How should I use a trait if i'm workng with multiple sheets.
    In my app i have multiple sheets, most of them have a manufacturer. Right now I use a trait that fetches the manufacturer based on its name, but everytime i switch sheet, the trait's constructor gets called, how can I limit database interractions with such layout?

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

    and it would be great if you add a button under your course like send offer (someone can offer you a buy price for every single course).

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

    What if there were no similar column names, and the only relatable column was user_id? :/

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

    good timing ! thank you sir

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

    greate like always

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

    А что если отношения Many to Many через pivot таблицу?!

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

    Hello Povilas. I'm your student :) I have bought your Laravel Excel course. What if I'm importing file for example with books, and I have some authors which are not present in database? How to add those missing authors in one import and sync them to books via pivot table :) ?

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

      It's been a while since I worked with Excel import, so I don't really remember. Googled a bit, found a few resources:
      laracasts.com/discuss/channels/laravel/laravel-excel-import-csv-data-relationed-to-another-table
      github.com/SpartnerNL/Laravel-Excel/issues/1966

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

    Thanks

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

    Hey Povilas
    What are your thoughts about inertia with vue and laravel backend? I haven't seen a video about inertia on your channel.
    So currently I'm thinking about learning livewire, but looking at performance, idk if it's any better than intertia + vue.

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

      Planning inertia content a bit later on the channel, not sure why

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

    Sir, How to use laravel Log with slack in localhost.

  • @tech.business-agencedigita4820
    @tech.business-agencedigita4820 10 หลายเดือนก่อน

    I have this error : Failed to open stream: Permission denied

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

    how to register in your course? there is no register button in your website

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

      You need to purchase that course, there's no "register" button, there's "buy" button.

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

      @@LaravelDaily okey have done

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

      how to import db3 file into database in laravel, Sir?

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

    just a big wow!

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

    How to validate that excel file for each row before saving into database?

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

      I have a video about it: th-cam.com/video/pshvWCCyCGw/w-d-xo.html

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

    what if we need to export 500000 rows?

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

      with DB already includes a tons of users... with User::all() your memory say: "OK, I'm out" ?

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

      @@PsyHooZ Just download more memory, ez
      /j

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

      Chunks?!

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

      It's a good point but if you check the premium course he provides, or the documentation for laravel excel it should be all you need to know.

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

    Can you make a video where you explain how to write a method in the test that creates (Jetstream) a user via Factory and logs in with that. At Laracasts I only got "it's so simple" answer and thus not helpful. 🙏🏻🙏🏻🙏🏻

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

      $user = User::create()
      auth()->login($user);
      Or do you really need a video about it?

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

      ​@@LaravelDaily
      $user = User::factory()->create();
      auth()->login($user);
      $response = $this->get('/clients');
      $response->assertStatus(200);
      Not working, because is not so simple. :(

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

      Then it's something with the logic of your application and why it doesn't return 200. Maybe it returns 403 because of some permissions? Not sure, needs debugging.

  • @Roy-xd5mw
    @Roy-xd5mw 3 ปีที่แล้ว

    How to export image in excel with other data

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

      Why would you want to export images into excel? Excel is not typically used for storing images.

    • @Roy-xd5mw
      @Roy-xd5mw 3 ปีที่แล้ว

      @@LaravelDaily if we use js script we can easy export images So, why not with laravel sir ?

    • @Roy-xd5mw
      @Roy-xd5mw 3 ปีที่แล้ว

      Please guide or make some video in which we can easily export images with other data from table

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

      Sorry I don't have any examples of images, I just personally haven't encountered excel files that would contain images, in my opinion Excel files are for calculations and data, not for images. Please read the official docs of Laravel Excel package, maybe they will have something.

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

      Maybe this will help you.
      th-cam.com/video/VUet2wq22-o/w-d-xo.html

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

    i'm sorry but your prices are too high 29$,99$ in pakistan 99$ equals to 17,127.49 Pakistani Rupee. 17 thousand no one wants to pay please consider this point. we want to learn quality code but not in this price we can't afford thanks!

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

      Visit coupons.laraveldaily.com

  • @adiputra-og9qt
    @adiputra-og9qt 2 ปีที่แล้ว

    why i can't run composer require maatwebsite/excel in my computer?
    this is my error:
    Your requirements could not be resolved to an installable set of packages.
    Problem 1
    - maatwebsite/excel[3.1.36, ..., 3.1.x-dev] require phpoffice/phpspreadsheet ^1.18 -> satisfiable by phpoffice/phpspreadsheet[1.18.0, ..., 1.24.1].
    - maatwebsite/excel[3.1.0, ..., 3.1.25] require php ^7.0 -> your php version (8.1.6) does not satisfy that requirement.
    - maatwebsite/excel[3.1.26, ..., 3.1.35] require illuminate/support 5.8.*|^6.0|^7.0|^8.0 -> found illuminate/support[v5.8.0, ..., 5.8.x-dev, v6.0.0, ..., 6.x-dev, v7.0.0, ..., 7.x-dev, v8.0.0, ..., 8.x-dev] but these were not loaded, likely because it conflicts with another require.
    - phpoffice/phpspreadsheet[1.18.0, ..., 1.24.1] require ext-gd * -> it is missing from your system. Install or enable PHP's gd extension. - Root composer.json requires maatwebsite/excel ^3.1 -> satisfiable by maatwebsite/excel[3.1.0, ..., 3.1.x-dev].
    To enable extensions, verify that they are enabled in your .ini files:
    You can also run `php --ini` in a terminal to see which files are used by PHP in CLI mode.
    Alternatively, you can run Composer with `--ignore-platform-req=ext-gd` to temporarily ignore these required extensions.
    You can also try re-running composer require with an explicit version constraint, e.g. "composer require maatwebsite/excel:*" to figure out if any version is installable, or "composer require maatwebsite/excel:^2.1" if you know which you need.