senrab

senrab

Member Since 7 Months Ago

Experience Points
740
Total
Experience

4,260 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
0
Lessons
Completed
Best Reply Awards
0
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.

Level 1
740 XP
Oct
06
2 weeks ago
Activity icon

Replied to I Can't Catch A HTTP Client Exception

4 - Here - https://laravel.com/docs/8.x/http-client#error-handling 5 - I am thinking about doing the same, I'm more familiar with it.

Activity icon

Replied to I Can't Catch A HTTP Client Exception

I was hoping to get $response->status() at least so I can log that in the database as a failed attempt.

The docs also promise $response->serverError() or $response->clientError(), but I don't seem to have access to them after the exception.

Pretty sure guzzle would give me the status code after an exception.

Activity icon

Replied to I Can't Catch A HTTP Client Exception

Thanks @laracoft, that got me a little further.

Where would I use $response->throw() in that catch() as I won't have access to $response there?

Activity icon

Replied to I Can't Catch A HTTP Client Exception

I did, however I will try again :)

Activity icon

Started a new Conversation I Can't Catch A HTTP Client Exception

Hi all,

I am using the new(-ish) HTTP Client, something like this $response = Http::get($listToCheck->url);

I've actually stripped it back from $response = Http::retry(3, 500)->timeout(10)->get($listToCheck->url);

I am trying to catch the exception and store it in the DB. So if I run my code with $response = Http::get($listToCheck->url);to an URL that doesn't exist, I am getting a Illuminate\Http\Client\ConnectionException error thrown and the console command exits with this exception

cURL error 6: Could not resolve host: this.is.a.forced.fail.com

however I can't seem to catch that error and continue the code to insert the error into the DB The docs say $response->throw();

Here's the code

foreach ($listsToCheck->get() as $listToCheck) {
               $response = Http::get($listToCheck->url);
               $response->throw();
               dd('here');
...

All I see is the exception, I don't get the dd.

What am I missing?

Sep
25
3 weeks ago
Activity icon

Replied to Scheduler Not Working After Moving Servers

Thanks for all the replies ladies and gents. All very much appreciated.

@miguellima

Did you add a cronjob on your server to run the schedule?

Yes, that copied across with the account. However your comment prompted me to double check it. The cron is wrapped in dogwrap (Part of DataDog) that we use to monitor scheduled tasks (among other things), it was failing.

Cron

* * * * * /usr/local/bin/dogwrap -n "php artisan schedule:run" -k <snip> --submit_mode all "cd /home/<snip>; /usr/local/bin/php artisan schedule:run" > /dev/null 2>&1

DogWrap moved. :(

 which dogwrap
/usr/bin/dogwrap

So there was an issue with the cron. Also DataDog wasn't alerting us that the cron wasn't running so I assumed it was running. Some kind of perfect storm scenario.

I think your comment may have resolved my issue. Onto DataDog now...

Sep
24
3 weeks ago
Activity icon

Started a new Conversation Scheduler Not Working After Moving Servers

Hi all,

I've moved a Laravel app to a new server. Previously the scheduler was working fine and running the jobs set in Kernel.php at their correct intervals.

The cron is running as expected, however since the move, the task scheduler is reporting No scheduled commands are ready to run. when I run it manually.

There are jobs that are scheduled ->everyFifteenMinutes() and haven't run for days, yet artisan tells me there is nothing to run.

An example job that isn't running in Kernel.php

        $schedule->command('Subscription:Notify')
                 ->everyThirtyMinutes()
                 ->withoutOverlapping()
                 ->between('7:00', '22:00')
                 ->environments(['staging', 'production']);

Is there some kind of internal job log / cache that I could have messed up during the migration? Laravel must keep some kind of track so that ->withoutOverlapping() will work.

Sep
10
1 month ago
Activity icon

Started a new Conversation Login After A Cashier SCA Event

I'm trying to use Cashier to take a subscription from users. If I use a standard Stripe test card, I can create the user and log them in. All is well.

If the card requires SCA, we get redirected the SCA/Stripe page. I'm using the default Cashier page to handle the SCA request. Like this https://imgur.com/opViHAz, after completing this I get presented with the Cashier page showing one button "Go Back". When I go back, I am redirected back to the registration page with an empty form, no subscription and no user in the database.

I'm using the example3 from the Cashier examples and the snippet from the main Cashier docs about failed payments

 public function register(Request $request)
    {
        ...
        $this->validator($request->all())->validate();

        DB::beginTransaction();

        event(new Registered($user = $this->create($request->all(), $userType)));

        try {
            $newSubscription = $user->newSubscription('subscription', $stripePlan)->create($request->payment_method, ['email' => $user->email]);
        } catch (IncompletePayment $exception) {
            return redirect()->route(
                'cashier.payment',
                [$exception->payment->id, 'redirect' => route('register')]
            );
        }

        DB::commit();

        $this->guard()->login($user);

        return $this->registered($request, $user)
            ?: redirect($this->redirectPath());

    }

I'm clearly doing something wrong handling the SCA event, but I can't figure out what!

Sep
04
1 month ago
Activity icon

Replied to Double When() In Eloquent Builder?

first param in the when caluse is just looking for something that evaluates to true

I didn't realise that. Makes sense now.

I agree, I might not even need the when check, I think I got too deep into the rabbit hole!

Activity icon

Started a new Conversation Double When() In Eloquent Builder?

I'm coding a report interface that takes a to and from date.

I'm using validation to confirm they both exist before running the Eloquent query, however it feels odd to use just one request variable in the where clause like this


        $Contracts = Contracts::when($request->date_from, function($query) use ($request){
            $dateFrom = Carbon::createFromFormat('d/m/Y', $request->date_from )->format('Y-m-d');
            $dateTo   = Carbon::createFromFormat('d/m/Y', $request->date_to )->format('Y-m-d');

            $query->whereBetween('order_date', [$dateFrom, $dateTo]);
        })

The validator looks like this,

'date_from'  =>  [
                'required',
                'date_format:d/m/Y'
            ],
            'date_to'  =>  [
                'required',
                'date_format:d/m/Y'
            ],

So we can be sure $request->date_from and $request->date_to are valid, however should I worry that I am only testing for one of them - when($request->date_from ?

Am I worrying too much?

Aug
27
1 month ago
Activity icon

Replied to Struggling With Unique Validation

@ravish @tykus I did something similar, however, $request is undefined in the required() function

 private function required()
    {
        return [
            'name'  =>  ['required', 'max:255'],
            'email' =>  [
                'bail',
                'email',
                'required',
                'max:255',
                Rule::unique('users')->ignore($request->route('user'))
                //'unique:users'
             //   Rule::unique('users', 'email')->ignore(request('email')),
             //   '//unique:users,email,'.request('email').',id'
            ]
        ];

    }

I got to that point and decided I must be doing it wrong

Activity icon

Started a new Conversation Struggling With Unique Validation

In my controller I have the following

    private function required()
    {
         return [
            'name'  =>  [
                'required', 
                'max:255'
            ],
            'email' =>  [
                'bail',
                'email',
                'required',
                'max:255',
                'unique:users'
            ]
        ];
    }

I call this in the store() and update() methods.

validator = Validator::make($request->all(), $this->required(), $this->messages());

        if ( $validator->fails() ) {
            return back()->withErrors($validator)->withInput();
        }
...

Calling this in store() method works great, however I am having trouble getting the validator to ignore the unique email rule if I am updating the record

During update() validation fails on the unique rule the same way store() does, so I can't update any of the user fields.

The docs, report doing something like this, unique:table,column,except,idColumn so I tried 'unique:users,email,'.request('email').',id' which still fails the validation

I've also tried the other way, using Rule- Rule::unique('users')->ignore($user->id), however I don't have the $user variable in the required() function, I'm passing in $request->all() so I thought I could do something like this Rule::unique('users')->ignore(request('email')),, however that doesn't work either.

Also, the validation messages are doubled up - I must be doing it wrong, but where am I going wrong?

Jul
28
2 months ago
Activity icon

Replied to Best Way To Convert HTML Entities

Works :) It was that sneaky , ENT_QUOTES

Activity icon

Replied to Best Way To Convert HTML Entities

I tried that and got the same. Is that because {{}} is converting the html_entity_decode again?

Jul
27
2 months ago
Activity icon

Started a new Conversation Best Way To Convert HTML Entities

We have some sharing code that grabs oEmbed data from a URL. Occasionally we are getting sites with an apostrophe in such as BBC Gardeners' World Magazine. We are storing this data in a json column and it is being saved as BBC Gardeners&#039; World Magazine

This is showing up in the UI. Considering we can't trust the URL and the data, I can't just do {!! $Post->oembed['providerName'] !!}

What would be the most standard way to convert the &#039; back into an apostrophe without sacrificing security?

May
20
5 months ago
Activity icon

Started a new Conversation Getting Cashier's Prorata Amount For A Subscription Swap

Hi all,

I am doing an "upgrade subscription" feature using Cashier's swapAndInvoice feature. All works great, however I am trying to get the pro-rata amount to display to the customer before they upgrade.

For example "Upgrade today for £X" where X is the prorata amount.

I tried to do this myself like this (overly expanded for clarity)

$createdDate    = Auth::user()->hasSubscription()->created_at;
$endDate        = Auth::user()->hasSubscription()->created_at->addYear();
$daysLeft       = $createdDate->diffInDays($endDate);
$daysInYear     = $endDate->isLeapYear() ? 366 : 365;

$proRataValue   = round((config('app.stripe_plan_p_cost') / $daysInYear) * $daysLeft, 2);
$upgradeCharge  = config('app.stripe_plan_d_cost') - $proRataValue;

All my calcs differ to what Cashier is calculating.

For example, I was suggesting to the customer the cost is £24, Cashier calculates it as £23.99

How can I get the actual amount Cashier is going to charge the customer before the customer upgrades rather than trying to work it out myself?