laracoft

Member Since 2 Years Ago

Experience Points
83,810
Total
Experience

1,190 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
3
Lessons
Completed
Best Reply Awards
114
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

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

  • Community Pillar

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

Level 17
83,810 XP
Jan
05
2 weeks ago
Activity icon

Started a new Conversation BelongsTo/associate For A Given Criteria

Referring to https://laravel.com/docs/8.x/eloquent-relationships#updating-belongs-to-relationships

Some of my tables use uuid while others use id, is there some way to associate models by criteria without needing to use ->id? e.g.

// SQL that i'm trying to execute
UPDATE books SET author_id = {$author->id} WHERE books.name like "%special%"

// equivalent I'm looking for
Books::where('name', 'like', '%special%')->associate($author)

Thank you.

Jan
02
3 weeks ago
Activity icon

Replied to Database Schema For Chat

@tippin

Mine is a side project I want to finish off but at the same time, gain some learning value. My thought was, if WhatsApp was able to do it (read timestamp per contact per message), there should be an efficient way to do it.

Anyway, thank you. :)

Activity icon

Replied to Database Schema For Chat

@tippin

  1. Are you able to have a read timestamp per contact per message?
  2. Supposed in my case, I have a contact and message ID and want to mark it as read, do you know what is the "Laravel way" to code it? $status->markAsRead($contact_id, $message_id)? Is there a better way?

Thank you.

Activity icon

Replied to Database Schema For Chat

@tippin

Thanks! Your project is impressive!

Activity icon

Started a new Conversation Database Schema For Chat

Hi,

I'm stuck trying to create a suitable database schema for a group chat platform using Eloquent and pivot tables.

Specifically:

  • Muting per Contact per Conversation
  • Read timestamp per Contact per Message (Think WhatsApp double blue ticks)

This is what I have at the moment

// An organization can have many conversations
Organization -< Conversation

// contact and Conversation has a many-to-many relation through member
Contact >- Member -< Organization

// contact and Conversation has a many-to-many relation through participant to store `is_mute`
Contact >- Participant -< Conversation

// a Conversation has many messages
Conversation -< Message

// contact and message has a many-to-many relation through status to store `read_at`
Contact >- Status -< Message

// but every message was also written by one contact (author)
message hasOne contact

To show a list of statuses for each message, I'm thinking of looping through $message->statuses

  1. Does Status have to be defined as a relation in the Contact and Message?
  2. What's the "Laravel way" of muting a Conversation as a Contact? (Statuses was easier, but this caught me in a bind)
  3. Anything I ought to change about the schema above?

Thank you.

Dec
31
3 weeks ago
Activity icon

Replied to Where Should I Store My .env File?

@martinzeltin

I think what you are actually asking is, how do I backup my .env?

  1. Git is meant for versioning/tracking changes, backup is kind of a side-effect of tracking
  2. Most docker images are configured to map/mount files to its host. This allows image updating without overwriting existing data. Which image are you using?
  3. My simple answer would be to perform a proper backup of the server/dev machine
  4. To be more detailed, bitwarden, the password manager, actually allows one to store all kinds of notes and data, you could technically paste the whole .env into 1 of its entries

Hope that helps.

Dec
30
3 weeks ago
Activity icon

Replied to A4 Page To Print In Laravel With Dynamic Content?

@faeza97

Dompdf will do the job. The idea ia to create an A4 PDF and let the user print the PDF

Activity icon

Replied to Laravel Middleware

@smashing

Can example/define what is "client in separate application" ?

Activity icon

Replied to Options For Package Resources Discovery

@imrodrigoalves

Actually i had half the solution, using app()->paths, but isset(...) did not work. Eventually, i found a way to check if it was set, but don't have the code on hand right now. Thanks anyway.

Dec
24
4 weeks ago
Activity icon

Replied to I Want To Add The "Buy Now", "Add To Cart" Buttons On The Product Page.

@martinbean any reason why not? My interpretation is that it will load a checkout page with 1 quantity of the item with a Pay button. This makes the URL sharable and helpful from the business POV when it comes to sales.

Activity icon

Replied to I Want To Add The "Buy Now", "Add To Cart" Buttons On The Product Page.

@ramikatz

Buy now can just be a GET, i.e. <a href....

Because of the dynamic quantity, it is easier to use POST for Add To cart, however that implies you need the csrf token.

If you must use POST for both, use 2 forms instead of 1. Using 1 form can complicate your code with unnecessary if-then-else which makes code maintenance more challenging.

Activity icon

Started a new Conversation Options For Package Resources Discovery

Hi,

Just wondering if anyone has a solution to this:

My Laravel apps usually require a number of my own packages, which contains their own resources. Even the app itself comes in the form of a package.

  1. Instead of hardcoding the path, is there an elegant way to locate a resource in 1 of the packages?
  2. Is there a way to scan multiple paths and loading the first matching file without being too resource intensive?

Thank you.

Activity icon

Replied to Laravel/Jetstream : Can't Run Npm Run Dev

@martzer

Is your error extracted from the FIRST time you run npm run dev? My errors are different on subsequent runs and only the error on FIRST run was helpful. Remove the entire node_modules to recreate the first run.

I would suggest trying yarn first, just replace all npm with yarn, if you still encounter problems, perhaps I can help.

Activity icon

Replied to Laravel/Jetstream : Can't Run Npm Run Dev

@martzer

npm run dev has never worked for me as my filesystem is a mounted off a samba share. I used yarn run dev instead, but today, yarn run dev also failed on me. I'm trying to figure it out. Let you know again if I make any progress.

Nov
22
2 months ago
Activity icon

Replied to Livewire Unhides Hidden Button

@nakov

Ok, thanks for your help. It moved me forward.

Activity icon

Replied to Livewire Unhides Hidden Button

@nakov

I need to toggle the visibility based on the brower's API support. So I plan to use Bulma's is-hidden class.

My Chrome shows the button for this

<button style="display:block" hidden>

Isn't this overriding hidden? It is just very odd that this did not happen while I was using a normal blade component.

Activity icon

Replied to Livewire Unhides Hidden Button

@nakov

What's a better way to debug? I'm pretty sure I took out all my scripts already and working off the minimal example.

It seems to be the way Chrome handles display: block and hidden attribute. It chooses to show it. Can help confirm? Thanks.

Activity icon

Replied to Livewire Unhides Hidden Button

@nakov

I identified the culprit, class="button" from Bulma CSS that I'm using. This is odd.

Activity icon

Replied to Livewire Unhides Hidden Button

@nakov

My versions

Chrome Version 86.0.4240.198 (Official Build) (64-bit)	
livewire/livewire v2.3.2   
laravel/framework v8.15.0       

Same as yours?

Activity icon

Replied to Livewire Unhides Hidden Button

@nakov

Can help test this? And explain what might be causing it? fa fa-share is from fontawesome, but I doubt it matters.

<div wire:poll.5s>
    <h1>{{ now() }}</h1>
    <button hidden>Test</button>
    <button id="butShare" class="button" hidden>
        <span class="icon"><i class="fa fa-share" aria-hidden="true"></i></span><span>Does not hide</span>
    </button>
</div>
Activity icon

Replied to Livewire Unhides Hidden Button

@nakov

Just to clarify, hidden attribute is still there in my HTML when I browse it using Dev tools, it just has no effect.

Let me try your code. Thanks.

Activity icon

Replied to Livewire Unhides Hidden Button

@nakov

I just found out the unhiding is caused by having wire:poll.5s in part of my Livewire component. Do you know why a line like this will cause unhiding?

Activity icon

Replied to Livewire Unhides Hidden Button

@nakov

Quite sure it is not my javascript. I tested by taking out my javascript after your reply.

It worked in a normal blade component. And started becoming visible after I placed them into a Livewire component.

Before I started the discussion, I was trying to manipulate the display: none CSS in my developer tools and it gets deleted once I entered it. I'm not sure if Livewire is the culprit, but all things point to it.

Activity icon

Replied to Laravel 8 IDGenerator [update]

@neomuckel

It is never a good idea to prefix, suffix or midfix dashes in invoices or inventory numbers.

  1. In your C-2020-01, what happens when you reach C-2020-99?
  2. If you go onto C-2020-100, why not just use a sequential number in the first place?
  3. Prefixing with alphabets forces your database to use strings instead of the more efficient integers.

Hope my explanation makes sense.

Activity icon

Started a new Conversation Livewire Unhides Hidden Button

<button id="butShare" class="button" hidden>

I have a normally hidden button that becomes visible if the browser supports a certain API, however the button is always visible when inside a Livewire component.

  1. Anyone knows if this unhiding is by design of Livewire?
  2. In normal blade, I check for if (navigator.share) {... to unhide the button, how do we integrate this into Livewire?
Nov
21
2 months ago
Activity icon

Replied to Changing The Style In Component

@sarahs74

public function __construct($type)
{
    $this->type = $type;	// what is the value of $type? do a dd($type)
}
Nov
20
2 months ago
Activity icon

Replied to Changing The Style In Component

@sarahs74

What is $type in PHP? Could it be $type->type in your component's switch?

Nov
14
2 months ago
Activity icon

Replied to Laravel 8 - CSRF Mismatch With Axios

@laravolt

Are both your token values the same?

Nov
11
2 months ago
Activity icon

Awarded Best Reply on How To Remove Jetstream Login,registeration From Laravel 8

@ddsameera

composer remove laravel/jetstream doesn't fully remove all the files it inserted. You need to manually remove at least the following:

Edit away
    app/Http/Kernel.php - \Laravel\Jetstream\Http\Middleware\AuthenticateSession::class,
    config/app.php - App\Providers\FortifyServiceProvider::class,
    config/app.php - App\Providers\JetstreamServiceProvider::class,
    routes/web.php - routes with auth:sanctum

Delete
    app/Providers/FortifyServiceProvider.php
    app/Providers/JetstreamServiceProvider.php
    app/View/Components/AppLayout.php
    app/View/Components/GuestLayout.php
    app/Actions/Fortify/
    app/Actions/Jetstream/

    config/fortify.php
    config/jetstream.php
    config/sanctum.php
    config/fortify.php

I also advise using git to track changes, that's how I'm able to list the above. :)

Activity icon

Replied to How To Remove Jetstream Login,registeration From Laravel 8

@ddsameera

Generally composer takes care of its removal. You most likely have another package relying on it. Run 'composer update' and see if it goes away. Btw, you have to run composer remove laravel/jetstream.

Activity icon

Replied to Curious About How Hash Works

@lukegalea16

Are you just curious about hashing or is there a bigger question to all these?

  1. Salting is meant to prevent patterns being discovered in the hashes.
  2. Salting is not applicable before sending for authentication.
  3. And NO, you don't want to be hashing before sending, this is literally breaking the protection provided by the hash. Once a hacker gets your hashes, they can login directly your system.

Please state your bigger question or read up on hash and salt so that we can have a more productive conversation about the idea you have in mind.

And if I may add, these concepts are developed by rigorous mathematicians over the decades. It is very unlikely for non-researchers to find better ideas.

Activity icon

Replied to Service Layer

@lazos99

Glancing through your code, I see processed, but that tells me very little about what the code is doing, i.e. low readability.

At this point you may think there are no other alternatives apart from writing this long method, but do have a look at the video cruddy by design. It provides quite a fresh perspective on code design.

Fluent styled code also makes reading much easier.

Activity icon

Replied to Service Layer

@lazos99

Looking deeper into your code, it seems you are trying to build a generic data table handler?

In my experience, when building such tools, I pretty much had to throw out most rules about SOLID etc and instead rely on good and clear documentation to achieve my 3 aims.

The reason is probably because such tools have little business logic to begin with and instead, acts more like a coordinator to transform/translate information.

Activity icon

Replied to Service Layer

@lazos99

Ok, let's step back. At the end of the day, code needs to be changed after some time. Question is:

  1. Do you know where it is located? (Searchability)
  2. Can you quickly refresh and understand it? (Readability)
  3. Is it easy to change? (Scalability)

If it is 3 yes for you, I think you are good. I just find that service isn't necessary for pluck, find and all.

Activity icon

Replied to Laravel Get Visitor's IP, Location, And City

@obink

  1. You don't need use Stevebauman\Location\Location;
  2. $poisiton2 is spelt wrongly. It should be $position2
  3. $position2 = FacadesLocation::get($whoIsIp); dd($position2); will work
// use Stevebauman\Location\Location;
use Stevebauman\Location\Facades\Location;

$position = Location::get($whoIsIp);
dd($position);
Activity icon

Replied to Service Layer

@lazos99

Let's explore a bit.

  1. What is the impact if you access the field model directly from your controller?
  2. Referring to the service's find(), pluck() and all(), does this conform to the DRY principle? (It's message passing and just bloats up the code for no good reason)
Activity icon

Replied to Service Layer

@lazos99

Consider having cruddy controllers, they usually make business logic simpler and get you more scalability.

https://www.youtube.com/watch?v=MF0jFKvS4SI

Activity icon

Replied to Service Layer

@lazos99

Why do you need a service when it is just mirroring the field model? I'm not sure which articles you are reading but perhaps they have a different context.

Activity icon

Replied to Laravel Get Visitor's IP, Location, And City

@obink

Add use Stevebauman\Location\Facades\Location; at the top of the code after namespace

Nov
10
2 months ago
Activity icon

Replied to Insertion Of Image Using Tinker

@nikhillvl

tinker is meant as a playground. Where is your image path?

file_get_contents(storage_path('image.png'));
Activity icon

Replied to How To Remove Jetstream Login,registeration From Laravel 8

@ddsameera

composer remove laravel/jetstream doesn't fully remove all the files it inserted. You need to manually remove at least the following:

Edit away
    app/Http/Kernel.php - \Laravel\Jetstream\Http\Middleware\AuthenticateSession::class,
    config/app.php - App\Providers\FortifyServiceProvider::class,
    config/app.php - App\Providers\JetstreamServiceProvider::class,
    routes/web.php - routes with auth:sanctum

Delete
    app/Providers/FortifyServiceProvider.php
    app/Providers/JetstreamServiceProvider.php
    app/View/Components/AppLayout.php
    app/View/Components/GuestLayout.php
    app/Actions/Fortify/
    app/Actions/Jetstream/

    config/fortify.php
    config/jetstream.php
    config/sanctum.php
    config/fortify.php

I also advise using git to track changes, that's how I'm able to list the above. :)

Activity icon

Replied to Insertion Of Image Using Tinker

@nikhillvl

Where is your image? On the internet?

file_get_contents($url);
Activity icon

Awarded Best Reply on Is It Possible To Use The Laravel Task Scheduler To Execute A Python Script?

@scottsuhy

Yes, what I'm saying is that an auction is an event driven (bids) process, not a time driven one, so cron doesn't fit the bill here.

  1. I assume you are familiar with how controller methods are triggered in Laravel
  2. When a bidder places a bid, e.g. /bid/{item_id}, the controller checks starts_at/ends_at and response accordingly, i.e. is the bid allowed or not
  3. If it is allowed, the new price is recorded and also placed onto a queue which gets pushed out by the queue:work task to the other bidders (see link)
  4. Other bidders get updated and they can trigger /bid/{item_id} with new prices and it will trigger #3
  5. By changing the ID, you can have as many auctions as you need

https://laravel.com/docs/8.x/queues#connections-vs-queues

Perhaps you should consider using just Laravel or python, not both.

Activity icon

Replied to Is It Possible To Use The Laravel Task Scheduler To Execute A Python Script?

@scottsuhy

Yes, what I'm saying is that an auction is an event driven (bids) process, not a time driven one, so cron doesn't fit the bill here.

  1. I assume you are familiar with how controller methods are triggered in Laravel
  2. When a bidder places a bid, e.g. /bid/{item_id}, the controller checks starts_at/ends_at and response accordingly, i.e. is the bid allowed or not
  3. If it is allowed, the new price is recorded and also placed onto a queue which gets pushed out by the queue:work task to the other bidders (see link)
  4. Other bidders get updated and they can trigger /bid/{item_id} with new prices and it will trigger #3
  5. By changing the ID, you can have as many auctions as you need

https://laravel.com/docs/8.x/queues#connections-vs-queues

Perhaps you should consider using just Laravel or python, not both.

Activity icon

Replied to Is It Possible To Use The Laravel Task Scheduler To Execute A Python Script?

@scottsuhy

Ok, I'm not familiar with python, but what is a ring?

  1. From my perspective, "starts auction x..." can be represented by a starts_at datetime field
  2. We could have a ends_at datetime which corresponds to countdown = 0
  3. Interaction is only allowed between starts_at and ends_at
  4. Once an auction is over, queue a job to pick the winner and inform them and flag that auction as is_processed

I still don't see why a cronjob is required for #1 to #3. After all, having a running task for each auction consumes resources even if nobody is bidding.

And cronjob only have the resolution of 1 minute not to mention random delays due to Laravel taking sometime to start up. Depending on the price range of your auctions, I would be unhappy if someone out bid me after closing time. (Using starts_at and ends_at prevents this).

Activity icon

Replied to How To Query By Row's Column Value?

@zyberg

Glad your issue is solved!

Activity icon

Awarded Best Reply on How To Query By Row's Column Value?

@zyberg

DB::table('completed')
->join('currentTable', function ($join) use ($user) {
    $join->on('currentTable.group', 'completed.group')
        ->on('currentTable.user_id', 'completed.user_id);
})->count();