JamesFreeman

JamesFreeman

Member Since 4 Years Ago

::1

Experience Points
43,910
Total
Experience

1,090 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
440
Lessons
Completed
Best Reply Awards
1
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 9
43,910 XP
Oct
09
1 month ago
Activity icon

Replied to Is It Possible To Load A Model Without All Relationships By Default

I have them loaded on the model by default with the $with variable but in very minimal places, they aren't relevant so I don't want to load them.

I was trying to find in the docs/API if there was something that already does that, but I couldn't find any.

Activity icon

Started a new Conversation Is It Possible To Load A Model Without All Relationships By Default

Hi, I have a model which has a bunch of relationships that I do not need for a certain query, is there a method I can call to remove all the eager loaded relationships?

I currently have this which works but if I add any future relationships won't be included?

$product = Product::without([
'attachments', 'brand', 'categories', 'flag', 'pivots', 'photos', 'recommended', 'related'
])

If there isn't a method that does this, do you think I should send a PR to the Laravel repo to add it as a feature?

Sep
20
1 month ago
Activity icon

Replied to Curl Print

Can you see what the CURL request is setting the $json_arr to? It should be set to an array if you have done my sets from earlier?

Activity icon

Replied to Curl Print

Try changing: return view('show', $data); to return view('show', ['data' => $data]);

Activity icon

Replied to Curl Print

Add $json_arr = []; after

$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
Jul
15
4 months ago
Activity icon

Replied to Mocking 3rd Party Classes Within Singleton

I do agree this is at a low level, I wouldn't normally go down this far, but it's for a service integration which has an expected input, It'll be nice to know moving forward that it is getting the parameters it needs.

I did think about doing that, unfortunately, it's on a 3rd party class so I can't create those methods on the class, I'm thinking I could potentially extend the base class and add those methods on.

What do you think?

Activity icon

Replied to Mocking 3rd Party Classes Within Singleton

Hi Martin, Thanks for the reply.

I'm trying to test that TwitterOAuth is receiving certain config values from this singleton.

$this->app->singleton(TwitterOAuth::class, function () {
    return new TwitterOAuth(
        config('twitter.consumer_key'),
        config('twitter.consumer_secret'),
        config('twitter.oauth_key'),
        config('twitter.oauth_secret')
    );
});

I could imagine that the test would look something like this:

function test_take_it_gets_the_correct_params()
{
    $mock = Mockery::mock(TwitterOAuth::class);
    
    config('twitter.consumer_key', 'A');
    config('twitter.consumer_secret', 'B');
    config('twitter.oauth_key', 'C');
    config('twitter.oauth_secret', 'D');
    
    $mock->shouldRecieve('__construct')->once()->with('A', 'B', 'C', 'D');
    
    $this->artisan('app:load-tweets');
}
Activity icon

Started a new Conversation Mocking 3rd Party Classes Within Singleton

I'm looking to test that TwitterOAuth is initiated with the correct config information, I have attached the code I have at the moment. Is it possible to dependency inject within the singleton call?

Anyone have an ideas on how I can complete this task?

TwitterServiceProvider

<?php

namespace App\Services\Twitter;

use Abraham\TwitterOAuth\TwitterOAuth;
use Illuminate\Support\ServiceProvider;

class TwitterServiceProvider extends ServiceProvider
{
    /**
     * Register services.
     *
     * @return void
     */
    public function register()
    {
        $this->app->singleton(TwitterOAuth::class, function () {
            return new TwitterOAuth(
                config('twitter.consumer_key'),
                config('twitter.consumer_secret'),
                config('twitter.oauth_key'),
                config('twitter.oauth_secret')
            );
        });

        $this->app->singleton(Twitter::class, function(){
            return new Twitter($this->app->make(TwitterOAuth::class));
        });
    }

    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot()
    {
        //
    }
}

TwitterCommandTest

<?php


namespace Tests\App\Commands;

use Mockery;
use Tests\App\TestCase;
use App\Services\Twitter\Twitter;
use Illuminate\Support\Facades\Cache;

/**
 * @runTestsInSeparateProcesses
 * @preserveGlobalState disabled
 */
class TwitterCommandTest extends TestCase
{
    /**
     * @test
     */
    public function test_tweets_should_be_cached()
    {
        $this->instance(Twitter::class, Mockery::mock(Twitter::class, function ($mock) {
            $mock->shouldReceive('get')->once()->andReturn('[1,2,3]');
        }));

        $this->artisan('app:load-tweets');

        $this->assertSame(Cache::get('twitter.cache'), '[1,2,3]');
    }
}

LoadTweets

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Services\Twitter\Twitter;
use Illuminate\Support\Facades\Cache;

class LoadTweets extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'app:load-tweets';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';


    protected $twitter;

    /**
     * Create a new command instance.
     *
     * @param Twitter $twitter
     */
    public function __construct(Twitter $twitter)
    {
        parent::__construct();

        $this->twitter = $twitter;
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $this->info('Loading Tweets');

        Cache::forever(
            'twitter.cache',
            $this->twitter->get()
        );

        $this->info('Saved Tweets');
    }
}