stesvis

stesvis

Member Since 2 Years Ago

Experience Points
1,830
Total
Experience

3,170 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
15
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 1
1,830 XP
Feb
05
3 weeks ago
Activity icon

Replied to Maximum Function Nesting Level Of '256' Reached, Aborting!

After further investigation I came to the conclusion that this method is causing the exception:

    /**
     * Returns all the related users: all the child users or siblings
     *
     * @param bool $include_me
     * @return mixed
     */
    public function relatedUsers(bool $include_me)
    {
        $related_users = $this->parent === null ? $this->children : $this->parent->children;
        if ($include_me === true) {
            $related_users = $related_users->push($this);
        }

        $related_users = $related_users->unique()->sortBy('id');

        return $related_users;
    }

and specifically this line:

$related_users = $related_users->push($this);

it turns out that if i modify it like this, it works:

$related_users = $related_users->push(User::findOrFail($this->id));

Would anyone know why i can't use $this?

Feb
03
3 weeks ago
Activity icon

Replied to Maximum Function Nesting Level Of '256' Reached, Aborting!

It's hard to test because if i comment them it throws errors in all my other controllers. The user is used everywhere..

Feb
02
3 weeks ago
Activity icon

Replied to Maximum Function Nesting Level Of '256' Reached, Aborting!

I suspect this is a nested reference issue, just for the record, i am posting the User model:

class User extends Authenticatable
{
    use Notifiable, HasApiTokens, Billable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name',
        'email',
        'password',
        'is_company',
        'user_id',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password',
        'remember_token',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
        'is_company' => 'boolean',
    ];

    public function roles()
    {
        return $this->belongsToMany(Role::class)->withTimestamps();
    }

    /**
     * @param string|array $roles
     * @return bool
     */
    public function authorizeRoles($roles)
    {
        if (is_array($roles)) {
            return $this->hasAnyOfTheseRoles($roles) ||
                abort(401, 'This action is unauthorized.');
        }

        return $this->hasRole($roles) ||
            abort(401, 'This action is unauthorized.');
    }

    /**
     * Check multiple roles
     *
     * @param array $roles
     * @return bool
     */
    public function hasAnyOfTheseRoles($roles = null)
    {
        if ($roles === null) {
            return $this->roles()->count() > 0;
        }

        return $this->roles()->whereIn('name', $roles)->first() !== null;
    }

    /**
     * Check one role
     *
     * @param string $role
     * @return bool
     */
    public function hasRole($role)
    {
        return $this->roles()->where('name', $role)->first() !== null;
    }

    /**
     * The parent user
     *
     * @return BelongsTo
     */
    public function parent()
    {
        return $this->belongsTo(User::class, 'parent_id');
    }

    /**
     * The child users
     *
     * @return HasMany
     */
    public function children()
    {
        return $this->hasMany(User::class, 'parent_id');
    }

    /**
     * The vehicles created by this user
     *
     * @return HasMany
     */
    public function vehicles()
    {
        return $this->hasMany(Vehicle::class)->orderByDesc('created_at');
    }

    public function accessibleVehicles()
    {
        $vehicles = collect();
        foreach ($this->relatedUsers(true) as $related_user) {
            $vehicles = $vehicles->concat($related_user->vehicles);
        }

        return $vehicles->sortByDesc('year');
    }

    /**
     * Returns all the vehicles that a user can access with their subscription
     *
     * @return Collection
     */
    public function accessibleVehiclesBySubscription()
    {
        if (!$this->subscribed('main')) {
            $vehicles = $this->accessibleVehicles()->sortBy('id')->take(3);

            return $vehicles->sortByDesc('year');
        }

        return $this->accessibleVehicles();
    }

    /**
     * The service types created by this user
     *
     * @return HasMany
     */
    public function serviceTypes()
    {
        return $this->hasMany(ServiceType::class);
    }

    /**
     * The services created by this user
     *
     * @return HasMany
     */
    public function services()
    {
        return $this->hasMany(Service::class)->with(['vehicle', 'serviceType']);
    }

    /**
     * Returns all the related users: all the child users or siblings
     *
     * @param bool $include_me
     * @return mixed
     */
    public function relatedUsers(bool $include_me)
    {
        $related_users = $this->parent === null ? $this->children : $this->parent->children;
        if ($include_me === true) {
            $related_users = $related_users->push($this);
        }

        $related_users = $related_users->unique()->sortBy('id');

        return $related_users;
    }

    public function taxPercentage()
    {
        return 5;
    }
}
Activity icon

Started a new Conversation Maximum Function Nesting Level Of '256' Reached, Aborting!

I really can't figure this out. I have this action in the UsersController:

    public function index()
    {
        try {
            $users = $this->request->user()->relatedUsers(true);

            return view('users.index', [
                'users' => $users,
            ]);
        } catch (\Exception $ex) {
            return back()->with('error', __($ex->getMessage()));
        }
    }

which causes this exception:

Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR) Maximum function nesting level of '256' reached, aborting!

The details are: R:\Levitica\AWDService\vendor\nesbot\carbon\src\Carbon\CarbonTimeZone.php

and it highlights this, which i am not even sure if it's relevant:

class CarbonTimeZone extends DateTimeZone
{
    public function __construct($timezone = null)
    {
        parent::__construct(static::getDateTimeZoneNameFromMixed($timezone));
    }
 
    protected static function parseNumericTimezone($timezone)
    {
        if ($timezone <= -100 || $timezone >= 100) {
            throw new InvalidArgumentException('Absolute timezone offset cannot be greater than 100.');
        }
 
        return ($timezone >= 0 ? '+' : '').$timezone.':00';
    }
 
    protected static function getDateTimeZoneNameFromMixed($timezone)
    {
        if (is_null($timezone)) {
            return date_default_timezone_get();
        }
 
        if (is_string($timezone)) {
            $timezone = preg_replace('/^\s*([+-]\d+)(\d{2})\s*$/', ':', $timezone);
        }
 
        if (is_numeric($timezone)) {
            return static::parseNumericTimezone($timezone);
        }
 
        return $timezone;
    }
 
    protected static function getDateTimeZoneFromName(&$name)
    {
        return @timezone_open($name = (string) static::getDateTimeZoneNameFromMixed($name));
    }

The confusing part is that if I do NOT pass $users the view, it doesn't throw any exception, this works perfectly fine with no errors:

    public function index()
    {
        try {
            $users = $this->request->user()->relatedUsers(true);

            return view('users.index', [
                'users' => [],
            ]);
        } catch (\Exception $ex) {
            return back()->with('error', __($ex->getMessage()));
        }
    }

What could be causing it then? What can i investigate?

NOTE: the view doesn't have anything in it, it's just a placeholder for now.

Thanks!

Activity icon

Awarded Best Reply on Api Returns "200 OK" Instead Of "401 Unauthorized"?

This is the route @mariohbrino :

Route::resource('vehicles', 'Api\VehiclesApiController')->middleware('auth:api');

And I use it from a mobile app.

I think I managed to resolve it tho, by passing this header: Accept: application/json

With it, if i try to consume the endpoint without a token it returns 401 correctly. Without it, it would return the html of my login page (where the Authenticate middleware redirects me).

Jan
14
1 month ago
Activity icon

Replied to Api Returns "200 OK" Instead Of "401 Unauthorized"?

@fylzero yes by "logged out" i mean not authenticated, no token.

Activity icon

Replied to Api Returns "200 OK" Instead Of "401 Unauthorized"?

This is the route @mariohbrino :

Route::resource('vehicles', 'Api\VehiclesApiController')->middleware('auth:api');

And I use it from a mobile app.

I think I managed to resolve it tho, by passing this header: Accept: application/json

With it, if i try to consume the endpoint without a token it returns 401 correctly. Without it, it would return the html of my login page (where the Authenticate middleware redirects me).

Activity icon

Started a new Conversation Api Returns "200 OK" Instead Of "401 Unauthorized"?

Hello,

I am using Passport to protect my APIs, and when I am logged in it's all good, but when I am logged out my API still returns a 200 code instead of 401. The response is the HTML content of my web login page.

How come??

Jan
02
1 month ago
Activity icon

Replied to Change Subscription Plan With Cashier

Oh great, then it's exactly what I needed! Thank you!

Activity icon

Replied to Change Subscription Plan With Cashier

@fylzero no what I mean is that they already paid for the year, and if they switch to "monthly" i do NOT want to bill them again (for the month) until the end of the year that they already paid.

But as of now it looks like it would bill them right away even if they are already covered for the whole year.

Does your solution prevent to bill them twice?

Jan
01
1 month ago
Activity icon

Started a new Conversation Change Subscription Plan With Cashier

I have successfully set up Laravel Cashier to implement subscriptions but i have a problem with switching plan. There are two plans, Annual and Monthly.

Let's say you subscribe with the Annual plan on Jan 1st 2020. Then on May 25th 2020 you decide you want to switch to Monthly.

The $user->subscription('main')->swap('provider-plan-id'); method works, but it starts charging the credit card immediately.

How can I make it so that the new Monthly plan will begin when the current active plan ends? So basically the Monthly plan should start charging the credit card on Jan 1st 2021.

Thanks