johncarter

johncarter

Member Since 3 Years Ago

Hertfordshire / London

Experience Points
11,090
Total
Experience

3,910 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
102
Lessons
Completed
Best Reply Awards
0
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 3
11,090 XP
Jun
24
2 months ago
Activity icon

Started a new Conversation Cannot Get <details> <summary> In Laracasts Discussion

I cannot seem to get <details><summary> markdown blocks working in the Laracast's Discussion markdown. As seen here: https://gist.github.com/ericclemmons/b146fe5da72ca1f706b2ef72a20ac39d

It would be really useful to hide massive stack traces / logs / code blocks and keep the attention on the issue.

Am I doing it wrong, or is it not supported?

Activity icon

Replied to ErrorException Stream_copy_to_stream(): Read Of 8192 Bytes Failed With Errno=21 Is A Directory

I have tried uploading the file locally ( Windows 10 / PHP 7.4 / Nginx ) and it works.

Therefore it's relevant that the server this is happening on is a Laravel Forge provisioned DO droplet.

I also tried using a new random test image from unsplash and it works on the production server. So there is something about this jpg on this server.

Also, I'd suggest this is better placed in Servers discussion.

Jun
23
2 months ago
Activity icon

Replied to Fread(): Read Of 8192 Bytes Failed With Errno=21 Is A Directory

Did you fix this? I'm experiencing the same issue.

Activity icon

Replied to ErrorException Stream_copy_to_stream(): Read Of 8192 Bytes Failed With Errno=21 Is A Directory

I'm here with the same question, so I'll reply with my answers. This is actually a Statamic V3 site I am running.

  • Not sure when I last updated.
  • Here my stack trace from /storage/logs/laravel.log:
[2020-06-23 18:53:13] production.ERROR: stream_copy_to_stream(): read of 8192 bytes failed with errno=21 Is a directory {"userId":"c09ea867-24cf-4dee-854b-ad0a273d3c40","exception":"[object] (ErrorException(code: 0): stream_copy_to_stream(): read of 8192 bytes failed with errno=21 Is a directory at /home/forge/www.REDACTEDDOMAIN.com/vendor/league/flysystem/src/Adapter/Local.php:159)
[stacktrace]
#0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError()
#1 /home/forge/www.REDACTEDDOMAIN.com/vendor/league/flysystem/src/Adapter/Local.php(159): stream_copy_to_stream()
#2 /home/forge/www.REDACTEDDOMAIN.com/vendor/league/flysystem/src/Filesystem.php(122): League\Flysystem\Adapter\Local->writeStream()
#3 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemAdapter.php(224): League\Flysystem\Filesystem->putStream()
#4 /home/forge/www.REDACTEDDOMAIN.com/vendor/statamic/cms/src/Filesystem/AbstractAdapter.php(28): Illuminate\Filesystem\FilesystemAdapter->put()
#5 /home/forge/www.REDACTEDDOMAIN.com/vendor/statamic/cms/src/Assets/Asset.php(562): Statamic\Filesystem\AbstractAdapter->put()
#6 /home/forge/www.REDACTEDDOMAIN.com/vendor/statamic/cms/src/Http/Controllers/CP/Assets/AssetsController.php(78): Statamic\Assets\Asset->upload()
#7 [internal function]: Statamic\Http\Controllers\CP\Assets\AssetsController->store()
#8 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): call_user_func_array()
#9 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(45): Illuminate\Routing\Controller->callAction()
#10 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Routing/Route.php(219): Illuminate\Routing\ControllerDispatcher->dispatch()
#11 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Routing/Route.php(176): Illuminate\Routing\Route->runController()
#12 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Routing/Router.php(681): Illuminate\Routing\Route->run()
#13 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(130): Illuminate\Routing\Router->Illuminate\Routing\{closure}()
#14 /home/forge/www.REDACTEDDOMAIN.com/vendor/statamic/cms/src/Http/Middleware/CP/Localize.php(16): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#15 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Statamic\Http\Middleware\CP\Localize->handle()
#16 /home/forge/www.REDACTEDDOMAIN.com/vendor/statamic/cms/src/Http/Middleware/CP/Authorize.php(25): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#17 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Statamic\Http\Middleware\CP\Authorize->handle()
#18 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(41): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#19 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\Routing\Middleware\SubstituteBindings->handle()
#20 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(76): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#21 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle()
#22 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#23 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\View\Middleware\ShareErrorsFromSession->handle()
#24 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(56): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#25 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\Session\Middleware\StartSession->handle()
#26 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#27 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle()
#28 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(66): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#29 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\Cookie\Middleware\EncryptCookies->handle()
#30 /home/forge/www.REDACTEDDOMAIN.com/vendor/statamic/cms/src/Http/Middleware/SwapExceptionHandler.php(19): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#31 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Statamic\Http\Middleware\SwapExceptionHandler->handle()
#32 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(105): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#33 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Routing/Router.php(683): Illuminate\Pipeline\Pipeline->then()
#34 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Routing/Router.php(658): Illuminate\Routing\Router->runRouteWithinStack()
#35 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Routing/Router.php(624): Illuminate\Routing\Router->runRoute()
#36 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Routing/Router.php(613): Illuminate\Routing\Router->dispatchToRoute()
#37 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(170): Illuminate\Routing\Router->dispatch()
#38 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(130): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}()
#39 /home/forge/www.REDACTEDDOMAIN.com/vendor/statamic/cms/src/Http/Middleware/PoweredByHeader.php(19): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#40 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Statamic\Http\Middleware\PoweredByHeader->handle()
#41 /home/forge/www.REDACTEDDOMAIN.com/vendor/barryvdh/laravel-debugbar/src/Middleware/InjectDebugbar.php(58): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#42 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Barryvdh\Debugbar\Middleware\InjectDebugbar->handle()
#43 /home/forge/www.REDACTEDDOMAIN.com/vendor/fideloper/proxy/src/TrustProxies.php(57): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#44 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Fideloper\Proxy\TrustProxies->handle()
#45 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#46 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle()
#47 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#48 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle()
#49 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#50 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle()
#51 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(63): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#52 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle()
#53 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(105): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#54 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(145): Illuminate\Pipeline\Pipeline->then()
#55 /home/forge/www.REDACTEDDOMAIN.com/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(110): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter()
#56 /home/forge/www.REDACTEDDOMAIN.com/public/index.php(55): Illuminate\Foundation\Http\Kernel->handle()
#57 {main}
"} 
  • Is set to stack, but not used.
  • Not changed anything in that class.
Jun
08
3 months ago
Activity icon

Replied to Relationship Or Column?

@bugsysha I should have actually asked how do I run a query on the column when the data is stored as a cast?

If I understand properly you are proposing that I should to cast the column value as a json string like:

{"handle":"denim_blue","name":"Denim Blue"}

Then if I want to query that column, I do something like this?

$denimBlueProducts = Products::where('colour->handle', 'denim_blue')->get();

See: https://laravel.com/docs/7.x/queries#json-where-clauses

Then to access the property I can do:

{{ $denimBlueProducts->first()->colour->name }}

Am I on the right track here?

Activity icon

Replied to Relationship Or Column?

Wow 🤯 that video is really useful, thanks. I just wonder how that will affect query performance. But I'll have a proper look into it.

Activity icon

Replied to Relationship Or Column?

@bugsysha So what you're saying is that I could use a column on the products table then make an accessor for the value?

e.g.

// Product.php
public function getColourAttribute($value)
{
    // $value = 'denim_blue';
    return ucwords(str_replace('_', ' ', $value); // "Denim Blue"
}
Activity icon

Replied to Relationship Or Column?

Thanks both, I am going to try the @martinbean way and see how I get on.

To confirm I would have a pivot that looks like this:

Schema::create('product_product_attribute', function (Blueprint $table) {
    $table->unsignedBigInteger('product_id');
    $table->unsignedBigInteger('product_attribute_id');
    $table->string('value'); // "denim_blue"
    $table->string('name'); // "Denim Blue"
    $table->primary(['product_id', 'product_attribute_id'], 'product_product_attribute');
});
Activity icon

Started a new Conversation Relationship Or Column?

I have a Product model with any number of attributes. Each product has one of each of these attributes. E.g. such as colour, size, gender, and say plus 8-10 more.

Can people tell me what seems more logical out of the following options:

Option 1 Eloquent relationship per attribute, e.g. models for every attribute: Colour, Size

Option 2 Use a column on the same table with snake cased value. Then use some sort of lookup array to get the human readable name per snake_cased attribute.

Option 3 An eloquent ProductAttribute which allow multiple attributes per product.

Option 1 seems like a lot of tables. Option 2 seems hacky. Option 3 seems convoluted and might cause unnecessarily slow queries.

Any opinions / best practices for this seemingly common situation?

May
20
3 months ago
Activity icon

Replied to Refactor Saving Many To Many Relationship

Thank you @michaloravec that's perfect.

Activity icon

Started a new Conversation Refactor Saving Many To Many Relationship

I know this can be refactored into something beautiful but don't have enough skill to know how to do it.

Would someone be able to help me get this code block looking a bit shorter and more readable?

    // [email protected]

    // $request->get('services') :
    // "services" = [
    //   "service_handle",
    //   "another_service_handle"
    // ]

    $serviceIds = [];
    if ($request->has('services')) {
      foreach ($request->get('services') as $maybeNewService) {
        $existingService = Service::where('handle', $maybeNewService)->first();
        if ($existingService) {
          $serviceIds[] = $existingService->id;
        } else {
          $newService = Service::create([
            'handle' => $maybeNewService,
            'name' => ucwords(str_ireplace('_', ' ', $maybeNewService)),
          ]);
          $serviceIds[] = $newService->id;
        }
      }
    }

    $booking->services()->sync($serviceIds);