Zini

Zini

Member Since 3 Years Ago

Experience Points 675
Experience
Level
Lessons Completed 0
Lessons
Completed
Best Reply Awards 0
Best Answer
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

12 Jul
5 months ago

Zini left a reply on Fake A File Upload With Defined Mimetype

Thank you lostdreamer_nl, you are correct, it actually works to that point. I don't know how I missed that, I was looking in the wrong place.

Actually my problem happens after the upload, when I control the input file in a custom rule.

The uploaded file seems ok:

\Log::debug(print_r($file, true));

testing.DEBUG: Illuminate\Http\Testing\File Object
(
    [name] => esse.pdf
    [tempFile] => Resource id #645
    [sizeToReport] => 0
    [test:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 1
    [originalName:Symfony\Component\HttpFoundation\File\UploadedFile:private] => esse.pdf
    [mimeType:Symfony\Component\HttpFoundation\File\UploadedFile:private] => application/pdf
    [error:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 0
    [hashName:protected] => 
    [mimeType] => application/pdf
    [pathName:SplFileInfo:private] => /tmp/phpFe5R0e
    [fileName:SplFileInfo:private] => phpFe5R0e
)

But when I try to get its mimetype, it returns an unrelated value:

$mimetype = \File::mimeType($file);
\Log::debug($mimetype);
// testing.DEBUG: filemimetyperule = inode/x-empty

In the case of a JPG image I even get png/image.

Is it wrong to use \File::mimeType() to control the an uploaded file?

11 Jul
5 months ago

Zini started a new conversation Fake A File Upload With Defined Mimetype

Hi,

I want to fake the upload of multiple types. It works for images, but I have a hard time finding out how to simulate other types of files.

Any not-image file gets inode/x-empty for mimetype, where I would like to see application/pdf.

// Mimetype ok
$file = \Illuminate\Http\UploadedFile::fake()->image('test.jpg');

// Mimetype issue: inode/x-empty
$file = \Illuminate\Http\UploadedFile::fake()->create('test.pdf');

// also tried this
$file->mimeType = 'application/pdf';

I did not find yet any solution in the Illuminate doc, or the Symfony doc.

21 Jun
5 months ago

Zini left a reply on Custom Validation Class: Parameters Support

It is actually pretty straightforward using the constructor:

// parameter for validation rule extending a service provider
$request->validate([
    'field' => ['foo:parameter'],
]);

// parameter for custom class rule
$request->validate([
    'field' => [new foo($parameter)],
]);

@bobbybouwmann I don't know why but I was looking for some custom Laravel way to do that...

20 Jun
5 months ago

Zini left a reply on Phpunit File Upload: Size 0 (zero)

@rin4ik ok, I tried using the call() method as explained the stack answer, but it does not impact the result: thhe file's size remains 0.

Zini started a new conversation Custom Validation Class: Parameters Support

Laravel 5.5 introduced custom validation classes: https://laravel.com/docs/5.6/validation#using-rule-objects

Extension rules allow input parameters:

    Validator::extend('foo', function ($attribute, $value, $parameters, $validator) {
        return $value == 'foo';
    });

How do we achieve the same support of parameters with a validation class?

Zini left a reply on Phpunit File Upload: Size 0 (zero)

@rin4ik I already found this post, but it dates back to 2015 when - I suppose - there was no UploadedFile::fake().

I thought that there is now another approach.

Zini started a new conversation Phpunit File Upload Fails

My test makes a post request:

// FileUploadTest.php

$this->post(
    'uri',
    ['file' => \Illuminate\Http\UploadedFile::fake()->image('file.jpg')->size(200)]
);

The controller detects the filesize:

// FileUploadController.php

if ($request->hasFile('file')) {
    \Log::debug('bytes: ' . \File::size($request->file));
}

When I upload a file manually, the correct size of the file would be logged. When I run a phpunit test, the size is always 0.

Any idea what is going on?

20 Mar
8 months ago

Zini left a reply on Validate A URL Parameter With Model Binding

@ahmeddabak good guess, looking at my routes I think you are right, it is what is happening. However it isn't the behaviour I would expect.

@Cronix I agree, the issue with with() is probably related to Dingo package.

But, is there a way in Laravel to validate URL parametersusing custom validation rules instead of the above simple regular expressions?

Zini left a reply on Validate A URL Parameter With Model Binding

I send the same request each time. It works fine until I add the where() clause, at which point I get this error.

Zini left a reply on Validate A URL Parameter With Model Binding

@ahmeddabak thanks, but I use dingo/api and it doesn't like the where():

"message": "405 Method Not Allowed",
"status_code": 405,
"debug": {
    "line": 255,
    "file": "/var/www/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php",
    "class": "Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException"
}

Besides, isn't there any way to use validation rules on url parameters instead of simple regular expression constraints?

Zini started a new conversation Validate A URL Parameter With Model Binding

My route parameter:

$api->get('projects/{project}', 'App\Http\Controllers\[email protected]');

has a model binding:

public function show(Project $project) { }

The projectparameter is an uuid, and the SQL query crashes when a wrong format is given. Therefore how can I check this this parameter with my custom validation rule before the binding is applied?

    Validator::extend('uuid', function ($attribute, $value, $parameters, $validator) {
        return preg_match('/[a-f0-9]{8}\-[a-f0-9]{4}\-4[a-f0-9]{3}\-(8|9|a|b)[a-f0-9]{3‌​}\-[a-f0-9]{12}/', $value);
    });
30 Jan
10 months ago

Zini left a reply on Forge And Digital Ocean - Meltdown And Spectre Vulnerabilities

Of course you should update your servers. Forge is not a server, it is a tool pretty much limited to deploying your code on a server.

Digital Ocean published a guide on how to mitigate (not fix) the issue: https://www.digitalocean.com/community/tutorials/how-to-protect-your-server-against-the-meltdown-and-spectre-vulnerabilities

You can compare your kernel to their list, uname -r.

14 Nov
1 year ago

Zini left a reply on How To Use Database Engine's UUIDs With Eloquent?

@martinbean Nice, it is more readable than the $cast syntax, but in the case of a database with the ability to generate uuids you shouldn't disable incrementing.

10 Nov
1 year ago

Zini left a reply on How To Use Database Engine's UUIDs With Eloquent?

I think I got what was going wrong:

Eloquent was designed with only incremental ids in mind. To replace a model's incremental id by a uuid, you will find a lot of people on the internet telling you to disable incrementing on your model. This is wrong, uuids are not incremental, but for Eloquent "incremental" doesn't actually mean incremental, it means "being generated by a database trigger" (source) and our uuids should be database-generated.

To use uuids auto-generated on the database level define the model as follows:

class MyModel extends Model
{
    // rename the id column, not mandatory
    protected $primaryKey = 'uuid';

    // tell Eloquent that uuid is a string, not an integer
    protected $casts = [
        'uuid' => 'string'
    ];
}

(in my first tests it seems to work fine)

Zini left a reply on How To Use Database Engine's UUIDs With Eloquent?

This is the object just after save():

App\User Object ( [primaryKey:protected] => uuid [incrementing] => [casts:protected] => Array ( [uuid] => string )

    [connection:protected] => pgsql
    [table:protected] => 
    [keyType:protected] => int
    [with:protected] => Array
        (
        )

    [withCount:protected] => Array
        (
        )

    [perPage:protected] => 15
    [exists] => 1
    [wasRecentlyCreated] => 1
    [attributes:protected] => Array
        (
            [name] => Bill
            [updated_at] => 2017-11-10 11:53:39
            [created_at] => 2017-11-10 11:53:39
        )

    [original:protected] => Array
        (
        )

    [changes:protected] => Array
        (
        )

    [dates:protected] => Array
        (
        )

    [dateFormat:protected] => 
    [appends:protected] => Array
        (
        )

    [dispatchesEvents:protected] => Array
        (
        )

    [observables:protected] => Array
        (
        )

    [relations:protected] => Array
        (
        )

    [touches:protected] => Array
        (
        )

    [timestamps] => 1
    [visible:protected] => Array
        (
        )

    [guarded:protected] => Array
        (
            [0] => *
        )

    [rememberTokenName:protected] => remember_token
)

Zini left a reply on How To Use Database Engine's UUIDs With Eloquent?

Yes, my model already declares $primaryKey and $incrementing, adding the $casts array doesn't change anything.

The action of creating a new User works, a user is indeed created with its uuid, the problem is that $user->uuidcannot be directly accessed after saving this new user. It can only be accessed after an Eloquent get User::last()->uuid.

09 Nov
1 year ago

Zini started a new conversation How To Use Database Engine's UUIDs With Eloquent?

Hello,

I want to use UUIDs generated by PostgreSQL to avoid relying on a Laravel package for the functionality that is provided directly by the database.

The UUIDs work and can be retrieved afterwards, but Eloquent has a problem doing so directly after saving objects.

The migration defines the PostgreSQL UUID generation:

    Schema::create('users', function (Blueprint $table) {
        $table->uuid('uuid')->primary()->default(DB::raw('uuid_generate_v4()'));
        $table->string('name')->unique();
    });

But when I create a user, I cannot directly access its uuid:

$user = new User;
$user->name = 'test';
$user->save();
$user->uuid     // here it is null, this property doesn't even exist

How can I get my uuid generated by PostgreSQL directly after save()? How does Eloquent proceed in the case of classic ids?

21 Mar
3 years ago

Zini left a reply on How To Access Translation Values From Other Locales

Thanks @usman, it is exactly what I was looking for. You are right @bestmomo, it will be useful the next time.

20 Mar
3 years ago

Zini started a new conversation How To Access Translation Values

Hello, The function trans() allows the access to the values inside the current locale files. I need to do the same, but for any locale. Is this possible with Laravel, or do I have to insert the file manualy Any idea?

17 Feb
3 years ago

Zini started a new conversation GrahamCampbell/Laravel-Markdown Render Inline

I use GrahamCampbell/Laravel-Markdown, a CommonMark wrapper, to render my blocks:

Markdown::convertToHtml($text);

But is there a dedicated method to render an inline block ?

I would like to render Markdown inside blocks where the render should not put block tags, such as <p></p>, around.

Zini left a reply on Laravel 5 Creates A New Session After Each Request

I installed Laravel again and moved my application inside: now the sessions work how they should. Unfortunately I have no clue where the problem came from.

@blackbird Homestead can be interesting for prototyping, but it is always better to have a local environment as close as possible to the production one.

16 Feb
3 years ago

Zini left a reply on Laravel 5 Creates A New Session After Each Request

@sitesense Yes I have deleted the cookies and even used another browser, but the problem lasts: everytime I reload the auth page, a new session is created.

Zini left a reply on Laravel 5 Creates A New Session After Each Request

@sitesense You are probably right, also I am moving my app to a new Laravel insallation. I hope it will fix this issue.

In the meantime: this is the configuration of my sessions: 'lifetime' => 120,' expire_on_close' => false,

Zini left a reply on Laravel 5 Creates A New Session After Each Request

I have the same problem using the last Laravel 5.0: Sessions are created- I can see the files appear in /storage/framework/session - but a new session is created at each request.

With this bug Laravel's sessions are useless, but also all components relying on them, such as the authentication or the flash messages. I did some research, and it seems I am not the only one with this issue.