Charrua

Charrua

Owner at Charrua

Member Since 2 Years Ago

A Coruña

Experience Points
8,310
Total
Experience

1,690 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
42
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 2
8,310 XP
Nov
15
2 days ago
Activity icon

Started a new Conversation Sending SMS Notification To Multiple User Phone Numbers

Hello, each of my User model have two phone numbers on the users table, phone_num and secondary_phone_num. For SMS I'm using Twilio notifications channel

On my model I have included the method

/**
 * Route notifications for the Twilio channel.
 *
 * @return string
 */
 public function routeNotificationForTwilio(){ 

    return $this->phone_num;

}

Each time I send a notification, this sends it without any problem. But what about if I wanted to send the notification to both phone numbers?

The same applies to emails, I send also an email notification, but what if the user has more than an email and wanted to be sent the notification to both emails?

Any ideas on how to solve this issue? Thank you.

Nov
12
5 days ago
Activity icon

Awarded Best Reply on Broadcasting Collection To Pusher

Hello, I'm sorry if I missed explanation.

I wanted to send some users as a collection but limit (select) fields on each user, not send all user data on the collection.

Solved it bu using another solution from other member on this forum:


public function broadcastWith()
    {
        return [
            'pending_invoices' => $this->prepareData(),
        ];
    }

protected function prepareData()
    {
        $invoices = array();

        foreach($this->pending_invoices as $invoice){
            $invoices[] = [
                'id'   => $invoice->id,
                'company'  => $invoice->client->company,
                'date'    => $invoice->date,
            ];
        }

        return $invoices;
    }
Activity icon

Replied to Broadcasting Collection To Pusher

Hello, I'm sorry if I missed explanation.

I wanted to send some users as a collection but limit (select) fields on each user, not send all user data on the collection.

Solved it bu using another solution from other member on this forum:


public function broadcastWith()
    {
        return [
            'pending_invoices' => $this->prepareData(),
        ];
    }

protected function prepareData()
    {
        $invoices = array();

        foreach($this->pending_invoices as $invoice){
            $invoices[] = [
                'id'   => $invoice->id,
                'company'  => $invoice->client->company,
                'date'    => $invoice->date,
            ];
        }

        return $invoices;
    }
Nov
10
1 week ago
Activity icon

Started a new Conversation Broadcasting Collection To Pusher

I'm trying to broadcast a collection of "pending invoices" to pusher. Following Laravel docs I have setup my event and is broadcasting all collection fields. But I wanted to broadcast some piece of information, so I'm using broadcastWith()method.

On Laravel docs this method is used for only one User but let's say I wanted to broadcast a collection of users, what would be the best way to achieve this?

For broadcasting one user and manipulate data:

public $user;


public function __construct(User $user)
{
    $this->user = $user;
}

public function broadcastWith()
{
    return ['id' => $this->user->id];
}
Oct
25
3 weeks ago
Activity icon

Replied to Nested Grouping 5 Levels 🤯

Great idea, I was able to create a custom SQL query with the results I wanted. The main issue about this path at the beginning was that I have many relations on the testing_candidate but I figured it!

Thank you for your help!

Oct
23
3 weeks ago
Activity icon

Started a new Conversation Nested Grouping 5 Levels 🤯

Well, I have some martial arts members from a school, and need to send a belt order to the belt provider.

The issue is, each belt has different details, Belt Type, Belt Size, Belt Color, Special stripe

The idea is to generate this output

Belt type: Classic
Size => 5   Color => Blue   Special stripe => Gold      Quantity => 5
Size => 3   Color => Red    Special stripe => Black     Quantity => 2

Belt type: Black Belt
Size => 5   Color => Black  Special stripe => Gold      Quantity => 5
Size => 3   Color => Black  Special stripe => Gold      Quantity => 2

Belt type: Tiger
Size => 2   Color => Blue   Special stripe => No        Quantity => 5
Size => 1   Color => Green  Special stripe => No        Quantity => 2

If I query members, I can have information for belt type, size, color and stripe. But to generate the output, the way I'm doing it now is grouping the collection by multiple levels. This adds some difficulty because it creates a nested collection with 5 levels and is difficult for me to handle so many levels.

The actual query I'm using for grouping those members

$grouped = $members->groupBy(['belt.type', 'belt.size', '.belt.color', 'belt.stripe']);

The output I get

Collection {#864 ▼
  #items: array:2 [▼
    "Classic" => Collection {#870 ▼
      #items: array:2 [▼
        5 => Collection {#992 ▼
          #items: array:1 [▼
            "Orange" => Collection {#991 ▼
              #items: array:2 [▼
                "Black stripe" => Collection {#958 ▼
                  #items: array:1 [▼
                    0 => TestingCandidate {#953 ▶}
                  ]
                }
                "Plain" => Collection {#990 ▼
                  #items: array:1 [▼
                    0 => TestingCandidate {#956 ▶}
                  ]
                }
              ]
            }
          ]
        }
        3 => Collection {#960 ▼
          #items: array:1 [▼
            "Orange" => Collection {#963 ▼
              #items: array:1 [▼
                "Plain" => Collection {#993 ▼
                  #items: array:1 [▼
                    0 => TestingCandidate {#955 ▶}
                  ]
                }
              ]
            }
          ]
        }
      ]
    }
    "Black Belt" => Collection {#866 ▼
      #items: array:1 [▼
        3 => Collection {#994 ▼
          #items: array:1 [▼
            "Black" => Collection {#1001 ▼
              #items: array:1 [▼
                "Black stripe" => Collection {#951 ▼
                  #items: array:1 [▼
                    0 => TestingCandidate {#954 ▶}
                  ]
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

On the frontend I use something like

@foreach ()
    @foreach()
        @foreach()
            @foreach()
            ...
            @endforeach
        @endforeach
    @endforeach
@endforeach

This makes any sense to you? What do you think?

Oct
02
1 month ago
Activity icon

Replied to Storing JSON On Database As Array Or As Object

Great, thank you for your help, I'll keep storing them like I used to.

Sep
29
1 month ago
Activity icon

Started a new Conversation Storing JSON On Database As Array Or As Object

Hello, I have a question for storing some JSON values on my invoices database.

On my taxes column on the invoices table I wanted to store e.g. 2 taxes, each one with some info as name, total, percentage and the id of the tax.

Those taxes are created on a Vue component and then rendered with PHP to create a PDF. So both, Vue and PHP will work with the values stored.

The way I'm using now, is sending data from Vue to PHP. Vue data is:

[{"id":1,"name":"TAX1","percentage":21,"total":210000},
{"id":2,"name":"TAX2","percentage":15,"total":150000}]

And on the PHP side I use json_encode($invoice_taxes) to store them on the db.

My question is how would be the best way to store taxes on the database

Option 1 as array (this is the actual way I'm doing it)

[{"id": 1, "name": "IVA", "total": 630, "percentage": 21}, 
{"id": 2, "name": "IRPF", "total": 210, "percentage": 7}]

Option 2 as object

{"0":{"id":1,"name":"IVA","total":630,"percentage":21},
"1":{"id":2,"name":"IRPF","total":210,"percentage":7}}
Aug
19
2 months ago
Activity icon

Replied to Are Event Listeners Cached In Some Way?

Seems that restarting the queue and the worker fixed the issue. Thank you for your help!

Aug
15
3 months ago
Activity icon

Replied to Are Event Listeners Cached In Some Way?

Great, that's what I understand form docs. Thank you for sharing your thoughts.

Aug
14
3 months ago
Activity icon

Replied to Are Event Listeners Cached In Some Way?

Yes I have a queue running, I'll restart the queue and come back here. I upload files using a git repository. Thank you

Activity icon

Replied to Are Event Listeners Cached In Some Way?

@braunson @click

As I understand from the docs:

Event Discovery is available for Laravel 5.8.9 or later.

And under Event Discovery is what you quote:

... during your deployment process, you should run the event:cache Artisan command to cache a manifest of all of your application's events and listeners

But I think this is only for Event Discovery (automatic event discovery) and not for manually registered events (as I use)

BTW I'm using v5.7

Activity icon

Started a new Conversation Are Event Listeners Cached In Some Way?

Hello, I'm using a simple event listener to detect when a notification is sent using a particular channel. In my case is NotificationChannels\Twilio\TwilioChannel.

Sometimes when I update this file, and upload to server, it seems that the update is not working... So I'm thinking if this is some cache in play... Any ideas?

Do you flush cache when updating Event Listeners?

Thank you.

Aug
04
3 months ago
Activity icon

Started a new Conversation Queued Jobs Rate Limiting Without Redis

Hello, on a previous discussion I was looking to use rate limiting when dispatching jobs to an external API. I know that the Laravel solution to this scenario is to use Redis, as the documentation exposes:

Redis::throttle('key')->allow(100)->every(60)->then(function () {
    // Job logic...
}, function () {
    // Could not obtain lock...

    return $this->release(10);
});

My app creates notifications to some users that are scheduled on some weekdays, each notification creates a job to send emails and SMS. So when the scheduler runs, it creates 3000 jobs (1500 for email and 1500 for SMS). With my actual setup, all jobs are dispatched immediately, so each API's will get those 1500 requests on the same minute, hitting rate limiting errors.

Looking for a solution using the database driver (as I do on my app) I have found one I wanted to share and see your thoughts.

Every time the scheduler runs, I query those 1500 members to notify and create chunks of 100, each chunk sends a notification with some delay. So when the worker starts to dispatch jobs it will find that they are not available to send all in the same minute, instead they will be available with the delay.

This is the code inside the handle method of the artisan command.

//query members to send notifications
$members = \App\Member::whereNull('expiration_date')->get();

$delay = 0;

//create chunks
$chunks = $members->chunk(100);

foreach ($chunks as $chunk){

    //send notification to chunk
    Notification::send($chunk, 
        (new AppIntroNewNoDate())->delay($delay));
            
    //add 60 seconds
    $delay += 60;

}
Jul
31
3 months ago
Activity icon

Replied to Is There A Way To Delay Queue Worker?

I have created an artisan command, that runs every Monday at 10 AM. The command queries let's say 1000 appointments, and one notification reminder is fired to each client.

As I use supervisor, when the notifications and jobs are created, they are all fired at the same time, let's say 20 seconds. So in this case Twilio, that is in charge of sending the SMS gets 1000 requests in 20 seconds. I need to downgrade the speed of the jobs being dispatched, that's why I need this approach.

The solution provided in the last post does that, gets the 1000 appointments and queues them but instead of sending all at the same time, they become available for every 60 seconds, sending 100 appointments every 60 seconds. Only running one day per week.

In this scenario, Twilio will get 100 requests per minute. (In this case is Twilio, but this can be applied to any other API with rate limiting)

Activity icon

Replied to Is There A Way To Delay Queue Worker?

I think I get to a easy solution, I'm using the chunk solution with delay on each chunk, this means that every 100 records we send a notification, and inside the loop, we sum seconds to delay.

public function handle()
{
    $calendar_appts = \App\Appointment::whereNull('date')
                    ->where('stop', 0)
                    ->get();

    $chunks = $calendar_appts->chunk(100);

    $delay = 0;

    foreach ($chunks as $chunk){

        //send notification to chunk
        Notification::send($chunk, 
                (new AppIntroNewNoDate())->delay($delay));
        
        //add 1 minute delay per 100 records
        $delay += 60;

    }        
}

I have checked on the jobs table and each chunk has 60 seconds difference on the available_at column.

What do you think?

Activity icon

Replied to Is There A Way To Delay Queue Worker?

But how do I remember what chunk it was processed? The scheduler runs an artisan command to fetch all the users to notify and sends the notification job to the queue, then the worker runs all jobs at once.

I do understand that I have to limit the notifications I send per time unit (one minute, 30 seconds...) but I don't understand how to implement your solution :(

Can you please explain a little bit more?

Thank you.

(at this time I'm investigating the other solution, the one that involves using Redis and rate limiting but is far more difficult to implement)

Jul
30
3 months ago
Activity icon

Replied to Is There A Way To Delay Queue Worker?

The jobs are queued as a result of querying a table, from an artisan custom command using the scheduler.

At the end of the command I have:

Notification::send($appointments_to_notify, new AppIntroNewNoDate());

I can chunk the $appointments_to_notify with some sort of delay, maybe using usleep?

The handle()method looks like this:

public function handle()
{
        
    $calendar_appts = \App\Appointment::whereNull('date')
                    ->where('stop', 0)
                    ->get();
        
    //send notification to appointments
    Notification::send($appointments_to_notify, new AppIntroNewNoDate());      

}

Maybe using this??

public function handle()
{
        
    $calendar_appts = \App\Appointment::whereNull('date')
                    ->where('stop', 0)
                    ->get();

    $chunks = $collection->chunk(100);

    foreach ($chunks as $chunk){

        //send notification to chunk
        Notification::send($chunk, new AppIntroNewNoDate());
        
        //sleep 1 minute
        usleep(1000000);

    }        

}
Activity icon

Replied to Is There A Way To Delay Queue Worker?

I'm realizing now that the solution I've found will delay the notifications, lets say 1 second, but I think that when it starts to dispatch the jobs, they will all be dispatched the same way as not using a delay here. Am I right?

Let me try to explain: as I'm using

Notification::send($appointments_to_notify, new AppIntroNewNoDate());

they will be queued at the same time but delayed one second. The delay (1 second) is not going to be on each notification but to the whole group.

So maybe this will not have the solution I'm looking... :(

I wanted to delay each notification being fired from the job queue.

Activity icon

Replied to Is There A Way To Delay Queue Worker?

@tykus I'm sorry I didn't told you I was using database driver for the queue. As I'm using Laravel notification system, the jobs are dispatching from Illuminate\Notifications\NotificationSender.

Reading this article How Laravel's Notification System Works I have found maybe a solution:

1 - Setting parameter on Notification class:

class PolicyUpdateNotification extends Notification implements ShouldQueue
{
    public $delay = 60;
}

2 - Or use the methods of the Illuminate\Bus\Queueable trait if you use that trait inside your notification.

Notification::send($users, 
    (new TestNotification())->onConnection(...)->onQueue(...)->delay(...)
);

What do you think?

Activity icon

Started a new Conversation Is There A Way To Delay Queue Worker?

Hello, I have my app sending some notifications through SMS using Twilio.

I have realized that some scheduled notifications by SMS are never delivered. I have read Twilio's rate limits and I think I'm stuck here.

You can send messages to Twilio at a rapid rate as long as the requests do not reach Twilio's API concurrency limit which is at 100.

Some of my scheduled notifications are sending more than 100 SMS at the same time, suppose 10 AM.

Is there a way to slow down the processing of the queue and check if this could be the problem happening?

Jul
22
3 months ago
Activity icon

Replied to Weird Error On Passing Laravel Collection To Vue

Oh man, I have forgot to add the quotes. Thank you so much.

Jul
21
3 months ago
Activity icon

Started a new Conversation Weird Error On Passing Laravel Collection To Vue

Hello, I'm passing a collection to Vue by a property on the blade template:

//blade template with Vue component

<appointment-new :reasons = {{ $reasons }} :schools = {{ $schools }}></appointment-new>

If I dd($schools) the result is a normal laravel collection. But when the data is passing trough, those names with spaces on the middle get quotes and an equal sign ""= see: {&quot;id&quot;:8,&quot;name&quot;:&quot;south="" park&quot;},

//school controller query

$schools = \App\School::get(['id', 'name']);

The issue is on passing the data onto Vue, I get an error on those schools names that have spaces, for example, if the school name is WORD there is no problem, but if is WORD WORD we have issues. Those values are strings on DB and on collection.

[Vue warn]: Error compiling template:

invalid expression: Invalid or unexpected token in

    [{"id":2,"name":"Huntersville"},{"id":3,"name":"Concord"},{"id":4,"name":"Ballantyne"},{"id":6,"name":"Mooresville"},{"id":7,"name":"Concord

  Raw expression: :schools="[{"id":2,"name":"Huntersville"},{"id":3,"name":"Concord"},{"id":4,"name":"Ballantyne"},{"id":6,"name":"Mooresville"},{"id":7,"name":"Concord"


146|                  <div id="createAppointment">
147|                    <div class="card-body ">
148|                        <appointment-new :appt_reasons="[{&quot;id&quot;:1,&quot;name&quot;:&quot;intro&quot;},{&quot;id&quot;:2,&quot;name&quot;:&quot;cash-out&quot;},{&quot;id&quot;:3,&quot;name&quot;:&quot;renewal&quot;},{&quot;id&quot;:4,&quot;name&quot;:&quot;upgrade&quot;},{&quot;id&quot;:5,&quot;name&quot;:&quot;pending&quot;},{&quot;id&quot;:6,&quot;name&quot;:&quot;private-class&quot;},{&quot;id&quot;:7,&quot;name&quot;:&quot;testing&quot;},{&quot;id&quot;:8,&quot;name&quot;:&quot;tournament&quot;},{&quot;id&quot;:9,&quot;name&quot;:&quot;special-activity&quot;},{&quot;id&quot;:10,&quot;name&quot;:&quot;pre-paid-test&quot;},{&quot;id&quot;:11,&quot;name&quot;:&quot;merchandise&quot;},{&quot;id&quot;:12,&quot;name&quot;:&quot;other&quot;},{&quot;id&quot;:13,&quot;name&quot;:&quot;after-school&quot;},{&quot;id&quot;:14,&quot;name&quot;:&quot;vip&quot;},{&quot;id&quot;:15,&quot;name&quot;:&quot;30DayFree&quot;}]" :schools="[{&quot;id&quot;:2,&quot;name&quot;:&quot;Huntersville&quot;},{&quot;id&quot;:3,&quot;name&quot;:&quot;Concord&quot;},{&quot;id&quot;:4,&quot;name&quot;:&quot;Ballantyne&quot;},{&quot;id&quot;:6,&quot;name&quot;:&quot;Mooresville&quot;},{&quot;id&quot;:7,&quot;name&quot;:&quot;Concord" mills&quot;},{&quot;id&quot;:8,&quot;name&quot;:&quot;south="" park&quot;},{&quot;id&quot;:9,&quot;name&quot;:&quot;matthews&quot;},{&quot;id&quot;:10,&quot;name&quot;:&quot;highland="" creek&quot;},{&quot;id&quot;:11,&quot;name&quot;:&quot;south="" park="" krav="" maga&quot;}]="">
   |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
149|                        </appointment-new>
150|  

(found in <Root>)

Any ideas??

Jul
09
4 months ago
Activity icon

Replied to Query Failing On Prod Server But Not Local

oh my... I was using the wrong case, my class is SmsLog and not SMSLog

The weird thing is that on local this runs and on prod no.

Thank you for your help!

Activity icon

Started a new Conversation Query Failing On Prod Server But Not Local

Hello, I having some trouble with some relation query on prod server. Database and files are the same.

On my model Communication I have a polymorphic relationship to the SMSLog model.

/**
* Get delivered SMS's associated with the communication.
* One To Many (Polymorphic)
*/
public function delivered_sms(){

    return $this->morphMany('App\SMSLog', 'model')->where('status', 'delivered');

}

On the communication controller I have:

public function index(){
        
    $communications = \App\Communication::orderBy('created_at', 'desc')
        ->paginate(20);
   
    return view('communication/index', compact('communications'));
}

Then on my blade view I'm using {{ $communication->delivered_sms()->count() }} to count how many delivered messages I have. This works on local but on prod It throws the error:

[2019-07-09 03:40:04] production.ERROR: Class 'App\SMSLog' not found (View: /var/www/vhosts/***/laravel/resources/views/communication/index.blade.php) {"userId":1,"email":"***","exception":"[object] (ErrorException(code: 0): Class 'App\SMSLog' not found (View: /var/www/vhosts/***/laravel/resources/views/communication/index.blade.php) at /var/www/vhosts/***/laravel/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php:656, Symfony\Component\Debug\Exception\FatalThrowableError(code: 0): Class 'App\SMSLog' not found at /var/www/vhosts/***/laravel/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php:656)
Jun
28
4 months ago
Activity icon

Replied to Set A Unsubscribe Link On Emails Using Maligun And Mailable

You can use this reference: https://documentation.mailgun.com/en/latest/user_manual.html#tracking-unsubscribes

And directly on your markdown blade templates use variables like:

%unsubscribe_url%
%tag_unsubscribe_url%

Now I can customize each mail notification with a different unsubscribe tag (or channel)

Jun
25
4 months ago
Activity icon

Replied to Set A Unsubscribe Link On Emails Using Maligun And Mailable

@AURAWINDSURFING - Thank you for your help, the Mailgun way is to activate an option inside Mailgun dashboard and that'll include the unsubscribe link automatically on each mail that I send trough Laravel using markdown.

I have placed a support ticket on Mailgun, let's see what they answer... I'll post it here.

Jun
21
4 months ago
Activity icon

Started a new Conversation Many To Many Relationships Attach/sync The Same Model

Hello, I'm working on an invoicing app. I have my Invoice and Product models.

In my DB I have a salables table that holds the relationship between Invoices and Products, in this case I'm using many to many polymorphic relationship, as I have also other models, like Budgets, etc.

So in that table I would save the products that are in the invoice or in the budget, as other data, as quantity, price, etc....

The problem is that when I save the invoice and attach products to the salables table, they do not appear to be saved.

Example, if I send product ID 1,2,3,4, each with internal data as quantity, there is no problem. To save I'm using $invoice->products()->attach($items);

The main issue, is when in the same invoice, I have for example the same product two times, ID 1 and ID 1, but with different quantities or prices... The problem is that it only saves one copy of the product.

That is because to save the related models, Laravel uses ID as key inside the array I'm passing to the attach() method. Is there other way to achieve this? any ideas?

Jun
20
4 months ago
Activity icon

Replied to Set A Unsubscribe Link On Emails Using Maligun And Mailable

@AURAWINDSURFING - Hello! I'm already using that, if you saw my code I'm using ->markdown('emails.group-a-noshow') the problem is how to include a Mailgun unsubscribe link on it.

Thank you anyway ;)

Jun
18
4 months ago
Activity icon

Started a new Conversation Set A Unsubscribe Link On Emails Using Maligun And Mailable

I'm sending emails trough Mailgun in my Laravel app. At this moment I manage maligun unsubscribes with an automatic feature on maligun website (track unsubscribes). This adds a link on each email at the bottom.

The problem is that I wanted to manage unsubscribes from Laravel, and mark recipients with a STOP field on database. This is to unsubscribe users from transactional emails but not for important emails.

Is there a way to include the unsubscribe link for maligun in a programmatically way?

This is my mailable

/**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {   
        
        $this->replyTo($this->email)
                ->markdown('emails.group-a-noshow');

        $this->subject('Sorry we missed you!');

    }
Jun
12
5 months ago
Activity icon

Replied to Let Public Vue SPA To Store Data On Laravel API (authenticated In Some Way)

@AUDUNRU - Great idea! Thank you for your help! I will try that :)

Jun
08
5 months ago
Activity icon

Started a new Conversation Let Public Vue SPA To Store Data On Laravel API (authenticated In Some Way)

Hi, I have a Laravel app that manages a school calendar, multiple manager users can add appointments to calendar.

When an appointment doesn't show up, we will be firing some automated email to the member for re-schedule a new appointment. The email will contain a button for re-chedule, when clicked, members will be redirected to SPA made on Vue.

The SPA will have a form, and get the ID from the button link of the appointment. After user sets a new date, a POST request will be made to the API to store the information.

I will want to secure this in some way, the basic ideas that come to me are:

  • Securing the API: maybe some sort of authentication between the SPA and the API or maybe the API will only let this SPA's domain to call an API route (some sort of whitelist domain to call API route) At first I was thinking on using Laravel Passport but I couldn't find a use case that fits.

  • Securing the SPA: only members that are sent the email will have access to the SPA

What will be your recommendations/ideas?

Jun
07
5 months ago
Activity icon

Replied to Firing An Event And Access To An $event->notification

@JOHNBRAUN - John, was returning an error on trying to access a private property. You were in the right path, making the prop public $communication on the notification file fixed the issue. I can access it now :)

Thank you.

Activity icon

Replied to Firing An Event And Access To An $event->notification

This is the log output, maybe I can't access to communication object because is private...

[notification] => App\Notifications\Communications\CommSMS Object
        (
            [communication:App\Notifications\Communications\CommSMS:private] => App\Communication Object
                (
                    [dates:protected] => Array
                        (
                            [0] => deleted_at
                        )

                    [connection:protected] => mysql
                    [table:protected] => 
                    [primaryKey:protected] => id
                    [keyType:protected] => int
                    [incrementing] => 1
                    [with:protected] => Array
                        (
                        )

                    [withCount:protected] => Array
                        (
                        )

                    [perPage:protected] => 15
                    [exists] => 1
                    [wasRecentlyCreated] => 
                    [attributes:protected] => Array
                        (
                            [id] => 67
                            [title] => test message
                            [message] => This is a test message. Hola!
                            [type] => sms
                            [communication_type_id] => 6
                            [groups] => 
                            [programs] => 
                            [school_id] => 2
                            [authorized_by] => dp
                            [button_text] => 
                            [button_url] => 
                            [image] => 
                            [image_url] => 
                            [sent] => 1
                            [sent_on] => 2019-06-07 05:11:55
                            [deleted_at] => 
                            [created_at] => 2019-06-06 14:14:43
                            [updated_at] => 2019-06-07 05:11:55
                        )

                    [original:protected] => Array
                        (
                            [id] => 67
                            [title] => test message
                            [message] => This is a test message. Hola!
                            [type] => sms
                            [communication_type_id] => 6
                            [groups] => 
                            [programs] => 
                            [school_id] => 2
                            [authorized_by] => dp
                            [button_text] => 
                            [button_url] => 
                            [image] => 
                            [image_url] => 
                            [sent] => 1
                            [sent_on] => 2019-06-07 05:11:55
                            [deleted_at] => 
                            [created_at] => 2019-06-06 14:14:43
                            [updated_at] => 2019-06-07 05:11:55
                        )

                    [changes:protected] => Array
                        (
                        )

                    [casts:protected] => Array
                        (
                        )

                    [dateFormat:protected] => 
                    [appends:protected] => Array
                        (
                        )

                    [dispatchesEvents:protected] => Array
                        (
                        )

                    [observables:protected] => Array
                        (
                        )

                    [touches:protected] => Array
                        (
                        )

                    [timestamps] => 1
                    [hidden:protected] => Array
                        (
                        )

                    [visible:protected] => Array
                        (
                        )

                    [fillable:protected] => Array
                        (
                        )

                    [guarded:protected] => Array
                        (
                            [0] => *
                        )

                    [forceDeleting:protected] => 
                )

            [id] => 3c0b7b0b-235e-4c74-86ec-539e82cfaafb
            [connection] => 
            [queue] => 
            [chainConnection] => 
            [chainQueue] => 
            [delay] => 
            [chained] => Array
                (
                )

        )

Activity icon

Replied to Firing An Event And Access To An $event->notification

@JOHNBRAUN - Hey John, running that dd() gives me nothing... I have already tried that...

dd($event->notification->communication) 
//or
dd($event->notification->communication->id)

I can access to dd($event->notification->id) or the other props like:

  +connection: null
  +queue: null
  +chainConnection: null
  +chainQueue: null
  +delay: null
  +chained: []

But not for the communication object...

Activity icon

Started a new Conversation Firing An Event And Access To An $event->notification

Hello, I have set an event listener to some SMS notifications.

The data I would like to get is the ID of the notification causer, for example I'm sending a group sms to some members, that message has the id 67 and is a Communication model. The problem is that I'cant access the object, this is my output.

Remember I wanted to access the id of the communication object. In the output is object 893

I have tried $event->notification->communication->id but nothing happens...

The output posted is from dd($event->notification)

App\Notifications\Communications\CommSMS
App\Notifications\Communications\CommSMS {#878
  -communication: App\Communication {#893
    #dates: array:1 [
      0 => "deleted_at"
    ]
    #connection: "mysql"
    #table: null
    #primaryKey: "id"
    #keyType: "int"
    +incrementing: true
    #with: []
    #withCount: []
    #perPage: 15
    +exists: true
    +wasRecentlyCreated: false
    #attributes: array:18 [
      "id" => 67
      "title" => "test message"
      "message" => "This is a test message. Hola!"
      "type" => "sms"
      "communication_type_id" => 6
      "groups" => null
      "programs" => null
      "school_id" => 2
      "authorized_by" => "dp"
      "button_text" => null
      "button_url" => null
      "image" => null
      "image_url" => null
      "sent" => 1
      "sent_on" => "2019-06-07 05:24:04"
      "deleted_at" => null
      "created_at" => "2019-06-06 14:14:43"
      "updated_at" => "2019-06-07 05:24:04"
    ]
    #original: array:18 [
      "id" => 67
      "title" => "test message"
      "message" => "This is a test message. Hola!"
      "type" => "sms"
      "communication_type_id" => 6
      "groups" => null
      "programs" => null
      "school_id" => 2
      "authorized_by" => "dp"
      "button_text" => null
      "button_url" => null
      "image" => null
      "image_url" => null
      "sent" => 1
      "sent_on" => "2019-06-07 05:24:04"
      "deleted_at" => null
      "created_at" => "2019-06-06 14:14:43"
      "updated_at" => "2019-06-07 05:24:04"
    ]
    #changes: []
    #casts: []
    #dateFormat: null
    #appends: []
    #dispatchesEvents: []
    #observables: []
    #touches: []
    +timestamps: true
    #hidden: []
    #visible: []
    #fillable: []
    #guarded: array:1 [
      0 => "*"
    ]
    #forceDeleting: false
  }
  +id: "bbc7390f-9faf-4457-808f-906a337a493d"
  +connection: null
  +queue: null
  +chainConnection: null
  +chainQueue: null
  +delay: null
  +chained: []
}
May
31
5 months ago
May
30
5 months ago
Activity icon

Started a new Conversation Looking For A Vue Wrapper For Using PayPal

Hello, we wanted to use PayPal for payments on a website that let users pay for some workshops. Our backend would be written using laravel and our frontend using Vue.js.

The ideal way would be using Stripe, but in the country that the website is going to run (Uruguay), Stripe does not exist. And PayPal would be a solution...

Do you know/use any npm package that works with PayPal? Any experience? I've found https://www.npmjs.com/package/vue-paypal-checkout but I have no references.

Thank you.

May
27
5 months ago
Activity icon

Replied to Need Help To Think Over A 3 Model Related Query

@DAVIDPETROV - Hi, the idea of using a time_notified column or similar, is not a bad idea, but there are many emails sent to the member, so that would not be a good idea. That's why we have an email log, to log the emails sent to the members.

My main issue here is how to test this query and not send the same email in the same week.

May
25
5 months ago
Activity icon

Started a new Conversation Need Help To Think Over A 3 Model Related Query

This is a school Laravel app, using 3 models Member for school members, Attendance for registering school attendance and EmailLog to see emails sent to members.

The main objective is to send "miss you" emails to inactive members on 4 ranges: one week inactive members, two week, one month and two month.

Let's only review the first case, one week inactive members. To select those members I created a local scope on the Member model:

public function scopeOneWeekInactiveRange($query) {
    
    $query->whereDoesntHave('attendance', function ($query) {
        $query->where('scan_date', '>', now()->subDays(7));
    })
    ->whereHas('attendance', function ($query) {
        $query->where('scan_date', '>', now()->subDays(14));
    });

}

This will select all members that have previous activity but doesn't have activity on the last week, I think we are on the way...

Once we have the selection, I will fire through php artisan member:send-inactive-oneweek a notification. Once the notification email is delivered or opened, it will create a new row on email_logs table with the member and the email type sent, in this particular case email_type_id is 16.

My command looks like this:

public function handle(){

    $members_to_notify = \App\Member::OneWeekInactiveRange()->get();

    Notification::send($members_to_notify, new InactiveOneWNoti());

}

If I run this command on a daily basis, my school members that are on that range will get the notification all days. That is not what we wanted.

So I've created another local scope on our Member model. The main purpose for this scope is to select only members that doesn't have an email_type_id equal to 16 on the last week. If it does, this means that an email was already fired to this member.

public function scopeOneWeekInactiveRangeEmail($query) {
        
    $query->whereDoesntHave('emailLog', function ($query) {
        $query->where('created_at', '>', now()->subDays(7))
            ->where('email_type_id', 16);
    });

}

So now, I have modified the artisan command php artisan member:send-inactive-oneweek to:

public function handle(){

    $members_to_notify = \App\Member::OneWeekInactiveRange()
        ->OneWeekInactiveRangeEmail()
        ->get();
    
    Notification::send($members_to_notify, new InactiveOneWNoti());

}

Here is the MAIN ISSUE:

My mind says to me that this query is good to go, but I need a way to test it, I have make many drawings with possibilities but I can't find a way to really test this, I don't want an email sent two times on the same week. I wanted to only send this email again if the member has the one week inactive condition again in the future. Any ideas?

May
21
5 months ago
Activity icon

Replied to Laravel Js Bundle Size Is Too Heavy, Using PDFmake And Data Tables

Sadly the whole bundle pdfmake/build parsed size is 1.79Mb running nom run prod

Activity icon

Started a new Conversation Laravel Js Bundle Size Is Too Heavy, Using PDFmake And Data Tables

Hello, I'm using datatables.net plugin to order and export data to PDF. The issue is that the "pdfmake": "^0.1.56", package is about 2Mb of my app.js file, any ideas on reducing this? Thank you.

Activity icon

Replied to Where To Place Logic To Check And Compare Model On Request

I have managed to create a new method on the model to check and return true/false. Seems to do the job.

Activity icon

Started a new Conversation Where To Place Logic To Check And Compare Model On Request

Hi, I wanted to compare and check every Transaction model when is requested.

Our problem is that some people of our sales team is selling products with a lower price. So we wanted to detect and "flag" visually those transactions for future review. This flag would be a simple red & bold on the transaction total. We list transactions on a table.

So I need something that checks against a collection, array or db every Transaction model. At first I think of global scopes, local scopes, mutators and assessors, but none of them seems to solve the problem.

Where do you think I can place the logic to check on every model and create the flag?