jcalonso

jcalonso

Member Since 5 Years Ago

Experience Points
19,415
Total
Experience

585 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
281
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 4
19,415 XP
Nov
30
1 week ago
Activity icon

Replied to Laravel-medialibrary - Serialization Of 'Closure' Is Not Allowed

Hello @rodrigo.pedra! yes, specifically the mediaCollections array inside the model, I can see that it contains an array of MediaCollection which contains a mediaConversionsRegistrations property with a closure (which I believe is the culprit).

I didn't save the model just to make the reproduction of the bug simpler. Same thing happens if its a model from the DB.

I am no expecting to return anything, just an empty string. but it is just for reproduction purposes. Actually something I did't mention is that this error only happens when the model doesn't have any media saved for that collection.

I agree with you assumption, thing is, it was working fine prior Laravel 6.

My actual use case is to save the model (this is no the User model btw) to the session once the user logged in, and then display an avatar from the session like : <img src="{{ session('employee')->picture ?? "some-default.jpg" }}" class="profile-picture">

Nov
29
1 week ago
Activity icon

Replied to Laravel-medialibrary - Serialization Of 'Closure' Is Not Allowed

Hey @snapey sorry for the late reply, got busy with some other stuff. I have uploaded my repo to Github and added a test to show the failure:

https://github.com/jcalonso/laravel-closure-serialization-bug/commit/3e76ad911041dd5b0b4abd210de3962f764080ae/checks?check_suite_id=335337372#step:7:32

Let me know if you see something wrong with my setup.

Thanks!

Nov
27
2 weeks ago
Activity icon

Replied to Laravel-medialibrary - Serialization Of 'Closure' Is Not Allowed

Could add the definition of the media collection to your model and try again?

public function registerMediaCollections()
    {
        $this->addMediaCollection('full')
            ->singleFile();
    }
Activity icon

Replied to Laravel-medialibrary - Serialization Of 'Closure' Is Not Allowed

Hey @snapey yeah, same behaviour here, I think the issue happens after the view is returned, so if you dd() gives you that empty string, but let the Framework terminate the request normally and you will have the Serialization of 'Closure' exception.

Let me know if you get the same, I think I am going to open an issue on medialibrary repo.

Nov
26
2 weeks ago
Activity icon

Replied to Laravel-medialibrary - Serialization Of 'Closure' Is Not Allowed

Yes I agree, it doesn't show anything related to the medialibrary, but commenting out the linesession('user')->getFirstMediaUrl('avatar'); stops the exception to be thrown.

Activity icon

Replied to Laravel-medialibrary - Serialization Of 'Closure' Is Not Allowed

Hi @tykus ,

No route caching, I get the same behaviour if I move the code into a controller.

Activity icon

Started a new Conversation Laravel-medialibrary - Serialization Of 'Closure' Is Not Allowed

I have a clean Laravel 6 app where I only have installed laravel-medialibrary, then I have the following route:

Route::get('/', function () {

    $user = new \App\User();
    $user->name = 'User';
    $user->email = '[email protected]';
    $user->password = Hash::make('pass');

    session(['user'=> $user]);
    session('user')->getFirstMediaUrl('avatar'); // Commenting this line fixes the problem. But why?

    return view('welcome');
});

And the User model looks like this:

<?php

namespace App;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Spatie\MediaLibrary\HasMedia\HasMedia;
use Spatie\MediaLibrary\HasMedia\HasMediaTrait;

class User extends Authenticatable implements HasMedia
{
    use HasMediaTrait;
    use Notifiable;

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

    /**
     * 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',
    ];

    public function registerMediaCollections()
    {
        $this->addMediaCollection('avatar')
            ->singleFile();
    }
}

When vising that route I get a Serialization of 'Closure' is not allowed exception.

Flareapp link: https://flareapp.io/share/W7zl1Amw#F31

Could someone see any reasons why this is happening?

Is this a bug on the library?

Oct
10
2 months ago
Activity icon

Replied to Macros In Lumen

Moving the $this->registerMacros(); to the public function register(){} fixes the problem.

Activity icon

Started a new Conversation Macros In Lumen

Is it possible to use Macros in Lumen?

I want to extend the \Illuminate\Console\Scheduling\Event class to allow something like:

  protected function schedule(Schedule $schedule)
    {
        $schedule->command('myapp:mycommand')
            ->everyMinute()
            ->thenReportUptimeMetric('xxxxx');
    }

Using a service provider like:

class ScheduledTaskMetricReporter extends ServiceProvider
{
    public function boot()
    {
        $this->registerMacros();
    }

    private function registerMacros()
    {
        Event::macro('thenReportUptimeMetric', function ($id) {
            return $this->then(function () use ($id) {
                app(MetricsClient::class)->increment($id);
            });
        });
    }
}

I am registering the service provider in bootrap/app.php but when running artisan I get:

  Method Illuminate\Console\Scheduling\Event::thenReportUptimeMetric does not exist.