senrab

senrab

Member Since 3 Months Ago

Experience Points
300
Total
Experience

4,700 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
300 XP
May
20
1 week 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?

Apr
08
1 month ago
Activity icon

Replied to Bail On First Validation Error In Array

I am convinced that wasn't working when I tried it. Seems to be working again now.

Thank you for the help

Apr
07
1 month ago
Activity icon

Started a new Conversation Bail On First Validation Error In Array

I am trying to validate multi-file upload where users can upload pictures.

In my controller I have

    protected $required = [
        'title'                     => ['required', 'string', 'max:200'],
       ...
        'description'               => ['required', 'string'],
        'attachments'               => ['bail', 'required', 'array', 'max:10'],
        'attachments.*'             => ['file', 'mimetypes:image/jpeg,image/png,image/gif', 'dimensions:min_width=500,min_height=500']
    ];
    protected $messages = [
        'attachments'               => 'At least one image larger than 500x500 is required.',
        'attachments.max'           => 'You may upload a maximum of 10 images.',
        'attachments.*.file'        => 'One of the images you have uploaded is not supported.',
        'attachments.*.mimetypes'   => 'One of the images you have uploaded is not supported.',
        'attachments.*.dimensions'  => 'One of the images you have uploaded is too small. Images should be at least 500x500.'
    ];

The validation bails if there are no images. That's perfect. I would like the validation to bail if one of the attachments.* rules fails. Right now, it isn't and it is sending back all the messages in the bag.

For example if I upload a CSV, I get two errors

array:1 [▼
  "attachments.0" => array:2 [▼
    0 => "One of the images you have uploaded is not supported."
    1 => "One of the images you have uploaded is too small. Images should be at least 500x500."
  ]
]
  • I assume attachments.*.dimensions is failing on the CSV and returning 0x0.
  • I don't know why *.mimetypes isn't throwing an error)
  • Finally, *.file is throwing an error expected.

I could solve this in the blade with this, hwoever it doesn't feel right.

      @if($errors->has('attachments.*') and !$errors->has('attachments'))
                                    <strong>{{current(current($errors->get('attachments.*')))}}</strong>
                             @endif

Is there a better way?

Activity icon

Replied to Why Is My Getter Querying The Database / Not Eager Loading?

That makes sense. I am making my query first.

Changing it fixes the problem.

Thank you for your help.

Activity icon

Started a new Conversation Why Is My Getter Querying The Database / Not Eager Loading?

I have a Posts model, and Posts belongs to a User like this

    public function User()
    {
      return $this->belongsTo('App\User');
    }

All fine so far.

There is a getter attribute on Users that simply combines first_name and last_name

    public function getFullNameAttribute() {
        return $this->first_name . ' ' . $this->last_name;
    }

My Eloquent builder looks something like this

 Post::query()
                ->orderby('id', 'desc') )
                ->with('User')
...

So I was hoping Lara would eager load the User relation, however if I call $post->User->full_name is is querying the database for each user. It's causing 100s of extra queries as if it isn't eager loading.

Any ideas what I am doing wrong?

Feb
26
3 months ago
Activity icon

Replied to Carbon Object Gets Lost?

Done. Thank you.

Activity icon

Replied to Carbon Object Gets Lost?

Boom! Thank you all. That was it.

I was reading about Mutators and wasn't 100% sure if it was what I needed.

Much appreciated.

Activity icon

Replied to Carbon Object Gets Lost?

Sure, here's the full loop so far

@foreach ($users as $user)
                            <tr>
                                <td>{{ $user->name }}</td>
                                <td>{{ $user->email }}</td>
{{--                                <td>{{ dd(  $user->last_login_at->diffForHumans() ) }}</td>--}}
                                <td>{{ $user->last_login_at->diffForHumans() }}</td>
                                <td class="text-right">
                                    <i class="far fa-edit"></i>
                                    <i class="far fa-trash-alt"></i>
                                </td>
                            </tr>
                        @endforeach

The dd returns what I would expect* "xx minutes ago"*. The line just below, returns *Call to a member function diffForHumans() on null *

Activity icon

Started a new Conversation Carbon Object Gets Lost?

Hi all, I'm fairly new to Laravel - I'm still learning. (I come from CakePHP, so still lots to figure out!)

I have a date field on my User model last_login_at

In the model I have this

    protected $dates = [
        'last_login_at',
    ];

If I {{ dd($user->last_login_at ) }} the date in the view, all seems good. I get the Carbon object

Illuminate\Support\Carbon @1582723049 {#493 ▼
  date: 2020-02-26 13:17:29.0 UTC (+00:00)
}

I can successfully run a Carbon function like this {{ dd( $user->last_login_at->diffForHumans() ) }} and get "32 minutes ago"

If I just return this to the view, rather than using dd like this "32 minutes ago", I get an error Call to a member function diffForHumans()

What am I missing?