ihorvorotnov

ihorvorotnov

Software Engineer at Nodo.Agency

Member Since 3 Years Ago

Dnipro

Experience Points
19,680
Total
Experience

320 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
196
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 4
19,680 XP
Oct
16
1 month ago
Activity icon

Replied to Same Controller Method For Both POST And GET, Why Bad?

The main argument of those who will say that's not a good idea is single responsibility principle and that makes sense. Your index method does 2 things instead of one (although you perceive it as 1 thing). That being said, it's not good from the academic point of view but quite acceptable for a real application.

However, I would recommend replacing POST with GET parameter. You can share this URL with GET param (e.g. /some/path?param=value), redirect to this URL, bookmark it etc. And you can't do it with POST.

Also, I'd try to use Conditional Clauses to simplify the code and clarify the intent:

public function index(Request $request)
{
    $ministry = $request->ministry;

    $campaigns = DB::table('campaigns')
        ->when($ministry, function ($query, $ministry) {
           return $query->where('user_id', $ministry);
        })
        ->orderBy('id', 'DESC')
        ->get();

    return view('admin', compact('campaigns'));
}

This way, even those purists who want everything "by the book" won't complain - the method now handles only GET request and now it does a single task - queries the DB for campaigns with optional param ministry. Clean, readable, 99% academic :) Also, better for users who can now share/bookmark a link with ministry filter applied.

Jul
15
4 months ago
Activity icon

Replied to Upload A File To A Model ID Subdir

@ronon Thanks, but I've studied all available docs before asking the question here and I am already utilizing customized paths (and disks) and metadata and everything works fine when updating existing resources. But when I'm creating a new resource, its ID is unavailable yet so none of these works. Thus, the question is mostly about:

  • how to overcome this "there's no ID at this moment yet" for new entries
  • and what's the best practice (if any).

Asked Taylor on Twitter and he confirmed my initial thoughts - just handle it on appropriate model events. I ended up uploading the files initially to public/media/{HASH}, then listening for saved event and renaming the {HASH} directory to model's ID, which is already available (record is stored in the DB). Intermediate sizes are generated at the same time. Then, on deleted event I just purge the dir with contents.

Jul
08
5 months ago
Activity icon

Replied to Upload A File To A Model ID Subdir

@ronon thanks for your reply but youre suggesting the Laravel-way which wont work - I need a Nova-way of doing stuff. As you said, you have never used Nova and the problem is it does things in its own way and limits you in many cases. Its a Vue.js SPA that of course uses the regular Laravel model under the hood but gives you another layer of abstraction on top of it.

Activity icon

Started a new Conversation Upload A File To A Model ID Subdir

Hi everyone! Im creating Exercises in Nova and use native File and Image fields to handle uploads. However, Id like the files to be stored in a sub directory with model ID:

- public
  - media
    - {id}
      - video.mp4
      - image.jpeg

This works fine when updating an existing model (the ID is already available), but the files are uploaded to base upload path public/media for new Exercises. This means model ID is not available during file upload yet.

Is it possible to achieve this in any other way? How would you do it, e.g.:

  • can you somehow queue uploads (which would be good to speed things up for admins too)? Queued tasks should be able to access model ID, right? Couldnt find any docs about queues in Nova though.
  • listen to created event, get the ID, create dir, move files and update database fields? Sounds doable but quite some extra work.
  • write custom store procedures for media files and handle it there? Will it run after the model is created or still before saving it to the database so no ID is available?
  • just replace the ID with some unique string that can be generated upfront and appended to a path instead? How would you store it so its accessible for subsequent edits? Get it from saved media file path every time or store as a separate field in database?

Im new to both Laravel and Nova and dont know the best practices yet (unless they are covered in one of the videos here). Would appreciate any help/advice on this.

P.S.: I will also generate intermediate sizes for the image later using Intervention package, tried couple things and the best idea Ive came up with is to handle it on saved and deleted model events. Am I doing it wrong here too?