s.spaan

s.spaan

Member Since 3 Years Ago

Experience Points 111,130
Experience Level 23

3,870 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 1098
Lessons
Completed
Best Reply Awards 1
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.

12 Jul
1 week ago

s.spaan left a reply on Redirection In Laravel

It's better to make a different topic for another question.

But anyway:

 $url ="https://api.stripe.com/v1/customers?limit=3";


$ch = curl_init(); //open connection
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer sk_test_xxxxxxx',
]);

$result_count = curl_exec($ch); //execute post

echo"<pre>";
print_r($result_count);
exit;

And it's better to not show the api token in the questions on the forum, even if it's the test token.

s.spaan left a reply on Redirection In Laravel

Sorry, missed that one.

09 Jul
1 week ago

s.spaan left a reply on Redirection In Laravel

Sorry, i didn't receive any notification of the replies. But i have changed it.

s.spaan left a reply on Test Artisan Command Called

@aurawindsurfing I can test if the command is executed, but i would like to do something like this:

/** @test */
public function command_was_called() 
{

Artisan::fake();

$this->post('/run-command', ['parameter' => 2]);

Artisan::assertIsCalled(SomeCommand::class);

}

Like we can do with the Queues ..

s.spaan started a new conversation Test Artisan Command Called

Hi, i'm looking for a way to test is a artisan command was called from a controller.

I know how to test the command itself, but how to test that the command was executed.

05 Jul
2 weeks ago

s.spaan left a reply on Curl : Failed To Store Data In DB

Any routes defined in the api.php are prefixed with /api.

So i think your url should be (if http://localhost/myproject/public/index.php is actually working):

$url = 'http://localhost/myproject/public/index.php/api/postReqFromView';

But it's better to serve the project like @snapey suggested and use a URL like

$url = 'http://localhost:8080/api/postReqFromView';

s.spaan left a reply on Redirection In Laravel

You could also wrap them in a group:

Route::domain('payments.taximobility.com')->group(function () {
    Route::get('/', function () { return 'welcome'; });
    Route::get('payment/{id}', '[email protected]');
    Route::post('paymentStripe', '[email protected]_payment');
    Route::get('paymentFails', '[email protected]');
});

Route::domain('www.taximobility.com')->group(function () {
    // remaining routes declared here
});

maybe this will fix the issues?

s.spaan left a reply on How To Handle This?

If you need a collection of those values you could do:

$dataVencimento= collect($dados[0]->{'PARCELA-PAGA'})->pluck('DATA-VENCIMENTO');

dd($dataVencimento);

s.spaan left a reply on How To Handle This?

Try:

$firstRecord = collect($dados[0]->{'PARCELA-PAGA'})->firstWhere('DATA-VENCIMENTO', '20170818');

dd($firstRecord);

s.spaan left a reply on How To Handle This?

No, because ->first() would just give you the very first item in the collection.

What do you get when you dd the following:

dd(collect($dados[0]->{'PARCELA-PAGA'}));

s.spaan left a reply on How To Handle This?

$url = 'http://*.*.*.*/SomeServices.asmx?WSDL';
$idERP = 1;
$grupoEcota = new \SoapClient($url);
$paramExtrato = array(
    'sGrupo' => $request->sGrupo,
    'iCota' => $request->iCota,
    'iIdERP' => $idERP,
);
$responseExtrato = $grupoEcota->ROS_ExtratoContaCorrente($paramExtrato);
$grupoEcota = $responseExtrato->ExtratoContaCorrente;
$dados[] = $grupoEcota->{'PARCELAS-PAGAS'};

$firstRecord = collect($dados[0]->{'PARCELA-PAGA'})->firstWhere(["DATA-VENCIMENTO" => "20170818"]);

dd($firstRecord);

Should be like this.

04 Jul
2 weeks ago

s.spaan left a reply on How To Handle This?

collect($dados[0]->{'PARCELA-PAGA'})->firstWhere(["DATA-VENCIMENTO" => "20170818"]); maybe like so?

s.spaan left a reply on How To Handle This?

collect($response)->firstWhere(["DATA-VENCIMENTO" => "20170818"]); should do the trick

01 Jul
3 weeks ago

s.spaan commented on Drop Down A Level

Im wondering why you dont inline the getTeam in the controller? Any reason for that?

12 Nov
8 months ago

s.spaan left a reply on Weird Issue With UpdateOrCreate

@thomaskim Your absolutely right. Locally the create was working, now forced a update, and it's failing. That makes fixing the issue so much easier. Now i have to figure out how to add the id column to the existing database.. ...

s.spaan left a reply on Weird Issue With UpdateOrCreate

@munazzil But the ShiftUser had no (single) primary key. It is a pivot Model:

<?php

namespace App;

use Illuminate\Database\Eloquent\Relations\Pivot;

class ShiftUser extends Pivot
{
    public $timestamps = true;
    
    protected $guarded = [];
}

It's just looking at a wrongly generated SQL ? Which i don't understand.. And locally it is working, but in production (forge server) it's not..

s.spaan left a reply on Weird Issue With UpdateOrCreate

@munazzil Why should that be necessary.?

It should just translate to "update shift_user set status = confirmed, updated_at = 2018-11-11 22:11:14 where user_id = 4234 and shift_id = 36790"

Or is that not how it works?

s.spaan started a new conversation Weird Issue With UpdateOrCreate

I get the following error when i try to do an updateOrCreate on a model, but i can't find out what is wrong:

SQLSTATE[42S22]: Column not found: 1054 Unknown column '' in 'where clause' (SQL: update `shift_user` set `status` = confirmed, `updated_at` = 2018-11-11 22:11:14 where `` = 4234 and `` = 36790)

This is my code;

ShiftUser::updateOrCreate([
    'user_id'  => $user->id,
    'shift_id' => $shift->id
], [
    'salesforce_id' => $sf_hour->Id,
    'status'        => strtolower($sf_hour->GW_Volunteers__Status__c),
]);

What am I doing wrong?

22 Jun
1 year ago

s.spaan left a reply on How To Prevent Error Reporting Between Certain Hours

@martinbean The backup is done via the laravel scheduler (Artisan Command):

$sqlFile = $tmpDir . $prefix . date( 'Y_m_d_h_i_s' ) . ".sql";
$backupFilename = $prefix . date( 'Y_m_d_h_i_s' ) . ".tgz";
$backupFile = $tmpDir . $backupFilename;

$createBackup = "mysqldump --opt --ignore-table=mandrill_emails -h " . $dbHost . " -u " . $user . " --password='" . $password . "' " . $dbName . " --> " . $sqlFile;

$createZip = "tar cvzf $backupFile $sqlFile";

exec( $createBackup );
exec( $createZip );

(Total file is longer and does some more, like sending it to external location).

But i'm just using a mysqldump like you can see.

And the complete stacktrace of the error is as follows: But it is just the default Laravel database queue job process which fails.

Illuminate\Database\QueryException SQLSTATE[HY000]: General error: 1615 Prepared statement needs to be re-prepared (SQL: select * from `jobs` where `queue` = default and ((`reserved_at` is null and `available_at` <= 1529627222) or (`reserved_at` <= 1529627132)) order by `id` asc limit 1 for update) 
    vendor/laravel/framework/src/Illuminate/Database/Connection.php:770 Illuminate\Database\Connection::runQueryCallback
    vendor/laravel/framework/src/Illuminate/Database/Connection.php:726 Illuminate\Database\Connection::run
    vendor/laravel/framework/src/Illuminate/Database/Connection.php:351 Illuminate\Database\Connection::select
    vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:1648 Illuminate\Database\Query\Builder::runSelect
    vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:1634 Illuminate\Database\Query\Builder::get
    vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:1617 Illuminate\Database\Query\Builder::first
    vendor/laravel/framework/src/Illuminate/Queue/DatabaseQueue.php:206 Illuminate\Queue\DatabaseQueue::getNextAvailableJob
    vendor/laravel/framework/src/Illuminate/Queue/DatabaseQueue.php:177 Illuminate\Queue\DatabaseQueue::pop
    vendor/laravel/framework/src/Illuminate/Queue/Worker.php:175 Illuminate\Queue\Worker::getNextJob
    vendor/laravel/framework/src/Illuminate/Queue/Worker.php:146 Illuminate\Queue\Worker::runNextJob
    vendor/laravel/framework/src/Illuminate/Queue/Worker.php:75 Illuminate\Queue\Worker::daemon
    vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php:101 Illuminate\Queue\Console\WorkCommand::runWorker
    vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php:85 Illuminate\Queue\Console\WorkCommand::fire
    [internal] call_user_func_array
    vendor/laravel/framework/src/Illuminate/Container/Container.php:508 Illuminate\Container\Container::call
    vendor/laravel/framework/src/Illuminate/Console/Command.php:169 Illuminate\Console\Command::execute
    vendor/symfony/console/Command/Command.php:261 Symfony\Component\Console\Command\Command::run
    vendor/laravel/framework/src/Illuminate/Console/Command.php:155 Illuminate\Console\Command::run
    vendor/symfony/console/Application.php:817 Symfony\Component\Console\Application::doRunCommand
    vendor/symfony/console/Application.php:185 Symfony\Component\Console\Application::doRun
    vendor/symfony/console/Application.php:116 Symfony\Component\Console\Application::run
    vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:121 Illuminate\Foundation\Console\Kernel::handle
    artisan:36 [main]


Caused by: Doctrine\DBAL\Driver\PDOException SQLSTATE[HY000]: General error: 1615 Prepared statement needs to be re-prepared 
    vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:93 Doctrine\DBAL\Driver\PDOStatement::execute
    vendor/laravel/framework/src/Illuminate/Database/Connection.php:337 Illuminate\Database\Connection::Illuminate\Database\{closure}
    vendor/laravel/framework/src/Illuminate/Database/Connection.php:763 Illuminate\Database\Connection::runQueryCallback
    vendor/laravel/framework/src/Illuminate/Database/Connection.php:726 Illuminate\Database\Connection::run
    vendor/laravel/framework/src/Illuminate/Database/Connection.php:351 Illuminate\Database\Connection::select
    vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:1648 Illuminate\Database\Query\Builder::runSelect
    vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:1634 Illuminate\Database\Query\Builder::get
    vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:1617 Illuminate\Database\Query\Builder::first
    vendor/laravel/framework/src/Illuminate/Queue/DatabaseQueue.php:206 Illuminate\Queue\DatabaseQueue::getNextAvailableJob
    vendor/laravel/framework/src/Illuminate/Queue/DatabaseQueue.php:177 Illuminate\Queue\DatabaseQueue::pop
    vendor/laravel/framework/src/Illuminate/Queue/Worker.php:175 Illuminate\Queue\Worker::getNextJob
    vendor/laravel/framework/src/Illuminate/Queue/Worker.php:146 Illuminate\Queue\Worker::runNextJob
    vendor/laravel/framework/src/Illuminate/Queue/Worker.php:75 Illuminate\Queue\Worker::daemon
    vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php:101 Illuminate\Queue\Console\WorkCommand::runWorker
    vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php:85 Illuminate\Queue\Console\WorkCommand::fire
    [internal] call_user_func_array
    vendor/laravel/framework/src/Illuminate/Container/Container.php:508 Illuminate\Container\Container::call
    vendor/laravel/framework/src/Illuminate/Console/Command.php:169 Illuminate\Console\Command::execute
    vendor/symfony/console/Command/Command.php:261 Symfony\Component\Console\Command\Command::run
    vendor/laravel/framework/src/Illuminate/Console/Command.php:155 Illuminate\Console\Command::run
    vendor/symfony/console/Application.php:817 Symfony\Component\Console\Application::doRunCommand
    vendor/symfony/console/Application.php:185 Symfony\Component\Console\Application::doRun
    vendor/symfony/console/Application.php:116 Symfony\Component\Console\Application::run
    vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:121 Illuminate\Foundation\Console\Kernel::handle
    artisan:36 [main]


Caused by: PDOException SQLSTATE[HY000]: General error: 1615 Prepared statement needs to be re-prepared 
    vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:91 PDOStatement::execute
    vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:91 Doctrine\DBAL\Driver\PDOStatement::execute
    vendor/laravel/framework/src/Illuminate/Database/Connection.php:337 Illuminate\Database\Connection::Illuminate\Database\{closure}
    vendor/laravel/framework/src/Illuminate/Database/Connection.php:763 Illuminate\Database\Connection::runQueryCallback
    vendor/laravel/framework/src/Illuminate/Database/Connection.php:726 Illuminate\Database\Connection::run
    vendor/laravel/framework/src/Illuminate/Database/Connection.php:351 Illuminate\Database\Connection::select
    vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:1648 Illuminate\Database\Query\Builder::runSelect
    vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:1634 Illuminate\Database\Query\Builder::get
    vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:1617 Illuminate\Database\Query\Builder::first
    vendor/laravel/framework/src/Illuminate/Queue/DatabaseQueue.php:206 Illuminate\Queue\DatabaseQueue::getNextAvailableJob
    vendor/laravel/framework/src/Illuminate/Queue/DatabaseQueue.php:177 Illuminate\Queue\DatabaseQueue::pop
    vendor/laravel/framework/src/Illuminate/Queue/Worker.php:175 Illuminate\Queue\Worker::getNextJob
    vendor/laravel/framework/src/Illuminate/Queue/Worker.php:146 Illuminate\Queue\Worker::runNextJob
    vendor/laravel/framework/src/Illuminate/Queue/Worker.php:75 Illuminate\Queue\Worker::daemon
    vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php:101 Illuminate\Queue\Console\WorkCommand::runWorker
    vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php:85 Illuminate\Queue\Console\WorkCommand::fire
    [internal] call_user_func_array
    vendor/laravel/framework/src/Illuminate/Container/Container.php:508 Illuminate\Container\Container::call
    vendor/laravel/framework/src/Illuminate/Console/Command.php:169 Illuminate\Console\Command::execute
    vendor/symfony/console/Command/Command.php:261 Symfony\Component\Console\Command\Command::run
    vendor/laravel/framework/src/Illuminate/Console/Command.php:155 Illuminate\Console\Command::run
    vendor/symfony/console/Application.php:817 Symfony\Component\Console\Application::doRunCommand
    vendor/symfony/console/Application.php:185 Symfony\Component\Console\Application::doRun
    vendor/symfony/console/Application.php:116 Symfony\Component\Console\Application::run
    vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:121 Illuminate\Foundation\Console\Kernel::handle
    artisan:36 [main]

s.spaan left a reply on How To Prevent Error Reporting Between Certain Hours

@martinbean Like i said, i don't want to mark it as ignored in bugsnag, because i do want to get notified outside of the backup window.

And you're totally right that any issues should be fixed. But i don't know how to fix this issue. Because it is only happening while the backup of the database is running. And the backup is locking the database, so this happens.

Any ideas on how to fix the problem?

s.spaan left a reply on How To Prevent Error Reporting Between Certain Hours

@martinbean What do you mean with chucking the fetching of the jobs? It is the default database queue driver of laravel which throws the error. I can't chunck that right?

The complete error that gets thrown is:

Illuminate\Database\QueryExceptionvendor/laravel/framework/src/Illuminate/Database/Connection.php:770
SQLSTATE[HY000]: General error: 1615 Prepared statement needs to be re-prepared (SQL: select * from `jobs` where `queue` = default and ((`reserved_at` is null and `available_at` <= 1529627110) or (`reserved_at` <= 1529627020)) order by `id` asc limit 1 for update)

This happens because the database backup is running and the database is locked at the time (or something). Do you know how to fix this? The best way I know is to create a replication database and backup from that one. But we don't have to resources for that.

And it is not that i'm bothered by my phone. But that in the morning i have a lot of emails about the same error which is thrown only because the backup was running, and the which is working normally outside these hours. (I know they are there, i know the problem, but i don't know if it can be fixed at all. I this the backup is more important than any lost jobs in that timeframe).

@Yorki Thanks. I had not realised return false could prevent the error from being send. Will that in consideration. I more or less like the option more to put it in maintenance mode within the time of backup so the jobs don't get processed and we don't have the error anyway. But i only want to do that when i can make sure the application is running at a certain hour (i don't know how to realise that).

s.spaan started a new conversation How To Prevent Error Reporting Between Certain Hours

Hi,

Situation: Laravel 5.4.x Queue Driver: Database Bugs logged to Bugsnag

I have a cron job running which create a full database backup every night. When this backup is running i get a lot of (expected) QueryException errors (SQLSTATE[HY000]: General error: 1615 Prepared statement needs to be re-prepared).

This is because the queue system want to retrieve the jobs from the table. That the error occurs doesn't bother me, but i don't want to have it in bugsnag (and my email).

But i don't want to disable the error in bugsnag, because when the error occurs outside the backup window, i do want to know about it.

I have been thinking about putting the application in maintenance mode before backup, and back after. But what happens when the backup fails of stalls.

How can i make sure the application is out of maintenance mode at a certain time? Or can i prevent errors logged to bugsnag in the maintenance window?

Any ideas ?

Thanks, Sonny

19 Apr
1 year ago

s.spaan left a reply on Job Within A Job Doesn't Get Dispatched

Ok, i looks like UpdateFraudDetection was cached on the server, so my changes to the file where not reflected on the new calls. Maybe this is related to the supervisord process.

I have restarted the supervisord process and this resolved the issue.

s.spaan left a reply on Job Within A Job Doesn't Get Dispatched

Why would it not be possible? I have made it a separate job so i would be able to fire it from other positions as wel..

s.spaan started a new conversation Job Within A Job Doesn't Get Dispatched

Hi,

I have a job that runs and should dispatch another job. Locally (sync driver) it is working, but on the server it is not. The second job never get's executed, and i can't find out why.

My Code:

<?php

namespace App\Jobs\Edsn;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

class UpdateFraudDetection implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    
    public function __construct($data)
    {
        $this->data = $data;
    }

    public function handle()
    {
    // Cut out the code, not relevant for the example.......
        
        // Dispatch Detect Fraud Job
        $this->dispatch(new DetectFraud($agent_id));

    // Also tried "dispatch(new DetectFraud($agent_id));"
        
        return;
    }
}
<?php

namespace App\Jobs\Edsn;

use Bugsnag\BugsnagLaravel\Facades\Bugsnag;
use Illuminate\Bus\Queueable;
use Illuminate\Support\Facades\Mail;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

class DetectFraud implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    
    /** @var integer */
    public $agent_id;
    
    public function __construct($agent_id)
    {
        $this->agent_id = $agent_id;
    }
    
    public function handle()
    {
        // Cut out some code, not relevant for the example... 

        Bugsnag::notifyError('DetectFraudTest', 'DetectFraud has started', function ($report) {
            $report->setSeverity('info');
            $report->setMetaData([
                'agent' => $this->agent_id,
            ]);
        });
        
        
    }
}

So, UpdateFraudDetection get's dispatched and runs, but DetectFraud never runs...

Laravel version 5.4.36 PHP Version 5.6.x (on the server and locally) Queue driver: database, run with Supervisord

Do you guys have any idea why this can happen?

02 Feb
1 year ago

s.spaan started a new conversation How To Detect Multiple Errors In A Short Period Of Time

Hi,

I have a problem, and don't know what the best way is to solve this.

Background info:

We have a custom API to do some tasks, this API connects to external API to fetch some data. The external API can be in maintenance mode, when it is we fall back to default values on our own API.

The Problem:

But the external API does have some problems some this, then we get back an error. When this error occurs we can try again and hope it works now. But when the error occurs 15 times within 5 minute it could be a bigger problem on the external API and we want to place it in maintenance so it falls back to default values faster.

The maintenance mode can be 15 minutes the first time, and when done, it checks again. When it goes out of maintenance and it still has 15 error within 5 minutes, we want a maintenance period of 30 minutes.

Do you guys have any opinion on how to solve this?

Thanks!

01 Nov
1 year ago

s.spaan left a reply on Access Laravel Queued Job's Payload Data

@clin407 On your failed job event you can do the following:

$payload = json_decode( $event->job->getRawBody() );
$data = unserialize( $payload->data->command );

// Use $data .. 

Just make sure that the data you pass to the job is set to a public variable.

13 Jan
2 years ago

s.spaan left a reply on Combination Of Validation Rules

Hi,

I'm now using the following which is working:

$validator = Validator::make( $request->all(), [
                // other rules
                'no_electricity'             => 'integer'
            ]);
            
            $validator->sometimes('electricity_meter_type', 'required|in:single,double', function($input) {
                return !isset( $input->no_electricity );
            });
            
            $validator->sometimes('electricity_usage_normal', 'required_if:electricity_meter_type,single|integer|min:1', function($input) {
                return !isset( $input->no_electricity );
            });
            
            $validator->sometimes(['electricity_usage_low', 'electricity_usage_high'], 'required_if:electricity_meter_type,double|integer|min:1', function($input) {
                return !isset( $input->no_electricity );
            });
            
            $validator->validate();

But maybe there is a better way to do this?

Thanks in advance.

12 Jan
2 years ago

s.spaan started a new conversation Combination Of Validation Rules

I have a form with the following fields:

Checkbox (name: no_electricity, value: 1) Select (name: electricity_meter_type, Options: Single, Double ) Field 1 Single Usage Field 2 Double Usage High Field 3 Double Usage Low

When the checkbox is checked (so in the request & value = 1) than non of the fields are required. But when the checkbox is empty (not in de request) and the select is single, only the single usage is required, but when the select is double only the 2 double usage fields are required.

How can i do this with the Laravel Validation rules?

I now have:

$this->validate( $request, [
                'electricity_meter_type'     => 'required_unless:no_electricity,1|in:single,double',
                'electricity_usage_normal'   => 'required_without:no_electricity|required_if:electricity_meter_type,single|integer|min:1',
                'electricity_usage_low'      => 'required_without:no_electricity|required_if:electricity_meter_type,double|integer|min:1',
                'electricity_usage_high'     => 'required_without:no_electricity|required_if:electricity_meter_type,double|integer|min:1',
// Some more rules
]);

But this is not working because the high and low are now required when the checkbox is not checked.

I'm using Laravel 5.3.x

Thanks