etiennedeschenes

etiennedeschenes

Member Since 1 Year Ago

Quito

Experience Points
65,460
Total
Experience

4,540 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
605
Lessons
Completed
Best Reply Awards
4
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 14
65,460 XP
May
26
1 week ago
Activity icon

Replied to I Seem Unable To Grasp Testing And I Am Frustrated

Have you imported InvitedCustomerAgreement in your test class?

Apr
15
1 month ago
Activity icon

Replied to How To Get Picture From Database And Show In Blade File

@spiral Giving yourself the best answer is not nice at all, you should have given it to @tykus who pointed you in the right direction...

Apr
11
1 month ago
Activity icon

Replied to Custom Request If Field Name Are Different?

Hello,

$request->paki;

should work in Laravel 5.2 and up, otherwise:

$request->input('paki');
Activity icon

Replied to How To Properly Validate Unique Field On Update

Hello,

Try:

'group' => "unique:groups,name,'" . $group->name . "'"

First table name, then column name then the value to ignore.

Apr
07
1 month ago
Activity icon

Replied to Can't Use Route In HREF In Output AJAX

Hello,

For @csrf


'<input type="hidden" name="_token" value="' . csrf_token() . '">'

For @method('DELETE')

'<input type="hidden" name="_method" value="DELETE">'
Activity icon

Awarded Best Reply on Can't Use Route In HREF In Output AJAX

You are not in a blade component, use normal php string concatenation:

'<td> <a href="' . route('retour.show', $retour->id) . '"><button type="button" class="btn btn-secondary btn-sm m-0">Bekijk

Activity icon

Replied to Can't Use Route In HREF In Output AJAX

You are not in a blade component, use normal php string concatenation:

'<td> <a href="' . route('retour.show', $retour->id) . '"><button type="button" class="btn btn-secondary btn-sm m-0">Bekijk

Activity icon

Replied to How To Remove Url Path From Request Paramters

Hello,

Try this:

$data = $request->only(['name', 'code', 'note']);

instead of

$data = $request->all();
Activity icon

Replied to Redirect After Login

In Laravel 7, it's in your RouteServiceProvider:

    /**
     * The path to the "home" route for your application.
     *
     * @var string
     */
    public const HOME = '/home';
Activity icon

Awarded Best Reply on Confusion About Redis And Laravel

Here is the same function using Redis facade:

function getUserById($id)
{
    // Check if user already in redis with cache key user.1 for example
    if (!Redis::exists('user.' . $id)) {
        // If the user is not in redis, fetch it from DB and add it in redis for 60 seconds before returning it
        $user = User::findOrFail($id);
        Redis::set('user.' . $user->id, $user, 60);

        return $user;
    }

    // If user is in redis, just return it without querying the database

    return Redis::get('user.' . $id);
}
Apr
06
1 month ago
Activity icon

Replied to How Can I Delete Old Image While Updating The Post With New Image

Is it working now?

The last backslash showing the string in red is just because vscode interprets it as a regular expression. For your case it shouldn't cause any problem because it's php code.

You should probably replace your backslashes with slashes so your code works on Linux or Mac (I don't know if windows would complain though).

Please, don't hard code your paths, it will cause you problems when deploying your app on servers... Also, have a look at how to publish a Laravel app and properly working with it's file structure (public folder, assets, storage folders, etc.).

I'm happy if I could help you a little bit...

Regards.

Activity icon

Replied to How Can I Delete Old Image While Updating The Post With New Image

If you want to hard code your path (for testing):

$pathToDelete = 'C:\wamp\www\tricky\uploads\posts\'.basename($post->featured);
unlink($pathToDelete);
Activity icon

Replied to How Can I Delete Old Image While Updating The Post With New Image

Hahhhh you propably have an accessor on you model!

Also, I don't understand why you don't have a public folder, publishing your laraval base app is not safe at all!

From what I see:

$pathToDelete = base_path().'/../uploads/posts/'.basename($post->featured);
unlink($pathToDelete);

or (I can't figure out what 1traveller folder is hence what base_path would return in your case...)

$pathToDelete = base_path().'/uploads/posts/'.basename($post->featured);
unlink($pathToDelete);

basename will return the filename from you url.

Your Laravel tree should look like this no matter the application and only the public folder should be published by your webserver: https://snipboard.io/zG7jE9.jpg

Activity icon

Replied to How Can I Delete Old Image While Updating The Post With New Image

Ok, first of all:

  • You are trying to delete the new file, not the old one
  • There is a laravel helper that return you base path (where you project lives, where your .env is for example), it's base_path(), with this, you don't have to hard code your paths (for example, the base path can be different on your server than on your development machine). In your case, base_path() would return c:/wamp/www/tricky.

So this code should work:

$pathToDelete = base_path().'/'.$post->featured;
unlink($pathToDelete);

Hope this helps.

Quick Laravel recommendation, you should use the storage folder (and facade for managing files). See: https://laravel.com/docs/7.x/filesystem#introduction

Activity icon

Awarded Best Reply on Using Default Factory Property Value For Other Properties Within A Factory

Hello,

You could define your factory like this:

$factory->define(MyModel::class, function (Faker $faker, $attrib) {
    $property1 = (array_key_exists('property1', $attrib)) ? $attrib['property1'] : $faker->numberBetween(1, 10);

    return ['property1' => $property1,
        'property2' => $property1 * 2];
});

Then when you call without property1:

$test = factory(MyModel::class)->make();
=> App\MyModel {#3412
     property1: 10,
     property2: 20,
   }

With property1:

$test = factory(MyModel::class)->make(['property1' => 5]);
=> App\MyModel {#3405
     property1: 5,
     property2: 10,
   }

Of course, the sample works with ->create(), not only ->make(). Hope this helps!

Activity icon

Replied to Confusion About Redis And Laravel

Here is the same function using Redis facade:

function getUserById($id)
{
    // Check if user already in redis with cache key user.1 for example
    if (!Redis::exists('user.' . $id)) {
        // If the user is not in redis, fetch it from DB and add it in redis for 60 seconds before returning it
        $user = User::findOrFail($id);
        Redis::set('user.' . $user->id, $user, 60);

        return $user;
    }

    // If user is in redis, just return it without querying the database

    return Redis::get('user.' . $id);
}
Activity icon

Replied to Confusion About Redis And Laravel

Then just set your .env like this and it will use redis!:


CACHE_DRIVER=redis

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
Activity icon

Replied to How Can I Delete Old Image While Updating The Post With New Image

You only have to figure out what is the full path of the file you want to delete in your code and pass it to the unlink PHP function. Just like you would do with rm on the command line...

Activity icon

Replied to Using Default Factory Property Value For Other Properties Within A Factory

Hello,

You could define your factory like this:

$factory->define(MyModel::class, function (Faker $faker, $attrib) {
    $property1 = (array_key_exists('property1', $attrib)) ? $attrib['property1'] : $faker->numberBetween(1, 10);

    return ['property1' => $property1,
        'property2' => $property1 * 2];
});

Then when you call without property1:

$test = factory(MyModel::class)->make();
=> App\MyModel {#3412
     property1: 10,
     property2: 20,
   }

With property1:

$test = factory(MyModel::class)->make(['property1' => 5]);
=> App\MyModel {#3405
     property1: 5,
     property2: 10,
   }

Of course, the sample works with ->create(), not only ->make(). Hope this helps!

Activity icon

Replied to How Can I Delete Old Image While Updating The Post With New Image

You have to use the full image path on the server for unlink to work (it will return true when it works). I don't know exactly where uploads/posts is on your server, you can try:

unlink(public_path() .'/'.$post->featured);

if your upload folder is located directly in your public path. If it's in the storage path, something like:

unlink(storage_path() .'/app/public/'.$post->featured);

You just have to pass the full path to the file to unlink

Activity icon

Replied to Confusion About Redis And Laravel

First of all, you have to tell Laravel that you want to use redis as a cache driver in your .env file (the CACHE_DRIVER key). Otherwise, it will use file by default. Then you could just make a small function for retrieving the user, either from database if it's not in cache or directly from cache:

function getUserById($id)
{
   // Check if user already in cache with cache key user.1 for example
   if (!Cache::has('user.' . $id)) {
       // If the user is not in the cache, fetch it from DB and add it in the cache for 60 seconds before returning it
       $user = User::findOrFail($id);
       Cache::put('user.' . $user->id, $user, 60);

       return $user;
   }

   // If user is in cache, just return it without querying the database
   return Cache::get('user.' . $id);
}

This code will work with any supported Laravel cache driver. For more details, you can see the cache documentation here: https://laravel.com/docs/7.x/cache

Activity icon

Replied to How Can I Delete Old Image While Updating The Post With New Image

Hello,

If you are not using Laravel Storage, just go for good old PHP unlink:

unlink($post->featured);

Do it just before your line:

$post->featured = 'uploads/posts/'. $featured_new_name;

Hope this helps.

Apr
02
2 months ago
Activity icon

Replied to Unable To Store Pdf File Into Storage Folder

Everything you save should go in storage/app, but storage/app/public (and all of it's content) is really public.

Activity icon

Replied to Unable To Store Pdf File Into Storage Folder

Public is public, meaning if you run php artisan storage:link, everything in storage/app/public is published to the world without restriction.

For example: storage/app/public/documents/invoices/invoice1234.pdf is freely accessible to anyone with the link http://yourdomain.com/storage/documents/invoices/invoice1234.pdf.

Apr
01
2 months ago
Activity icon

Replied to Unable To Store Pdf File Into Storage Folder

See @flightsimmer668 response, you don't save in public/storage, you save in storage with

Storage::disk('public')->put($fileLocation, $fileContents);

You should then run (once for the lifetime of your project)

php artisan storage:link

It will create a symbolic link to your public directory (from storage/app/public to public/storage). Finally, you can access your file in different ways (depending on your needs):

$contents = Storage::disk('public')->get($fileLocation);

or

return Storage::disk('public')->download($fileLocation);

or

$url = Storage::disk('public')->url($fileLocation);

Be careful, the public disk is, as it says, public, anyone with the direct link to you file (obtained by crawling your site for example) can access it. You should use another location for private files (such as storage/app/private for instance), you would then save the file like this:

Storage::disk('local')->put('private/invoices/'.$fileName, $fileContents);

I bet your invoices should not be public...

See: https://laravel.com/docs/7.x/filesystem for detailed documentation.

Mar
23
2 months ago
Activity icon

Awarded Best Reply on Laravel ACL Organizations/Groups/Users/Roles Package?

Have a look at Spatie laravel-permissions: https://docs.spatie.be/laravel-permission/v3/introduction/

You have Users-Roles-Permissions out of the box (users AND roles can have many permissions and users can have many roles, giving them the sum of all of their permissions). You will have to implement the organizations by yourself though (I don't know of any Laravel package implementing all your needs).

Spatie is probably the best Laravel package editor and it's "postcardware".

Mar
21
2 months ago
Activity icon

Replied to Laravel ACL Organizations/Groups/Users/Roles Package?

Have a look at Spatie laravel-permissions: https://docs.spatie.be/laravel-permission/v3/introduction/

You have Users-Roles-Permissions out of the box (users AND roles can have many permissions and users can have many roles, giving them the sum of all of their permissions). You will have to implement the organizations by yourself though (I don't know of any Laravel package implementing all your needs).

Spatie is probably the best Laravel package editor and it's "postcardware".

Mar
05
2 months ago
Activity icon

Commented on Reduce CSS Class Repetition With Blade Components

@JeffreyWay It would be nice to have this kind of tricks for Tailwindcss and Vue.js, I'm a little bit confused on extracting Vue components from my layout. Do I go down to extracting component for every object (input, chekboxes, etc.) just for the sake of avoiding using @apply even if these objects don't have any special behavior ?