vendredi 27 octobre 2017

Laravel calling a controller function from a model factory

I am building some tests in my Laravel 5.5 project.

In my GalleryFactory I need to generate a 'link', I have written this code inside a function in my GalleriesController like so;

private function generateUrlLink()
{
    $generatedLink = str_random(8);

    $existingGalleryWithGeneratedLink = Gallery::where('link', $generatedLink)->first();

    while (!is_null($existingGalleryWithGeneratedLink)) {
        $generatedLink = str_random(8);
        $existingGalleryWithGeneratedLink = Gallery::where('link', $generatedLink)->first();
    }

    return $generatedLink;
}

I don't want to write this code twice in the controller and also the factory as i might want to modify it someday, so im wondering what the best way of going about this would be?

Any help would be fantastic.

Thanks.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2ibQvwL
via IFTTT

Aucun commentaire:

Enregistrer un commentaire