Nospoon

Nospoon

Member Since 4 Years Ago

Experience Points 19,795
Experience Level 4

205 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 321
Lessons
Completed
Best Reply Awards 0
Best Reply
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.

02 May
2 weeks ago

Nospoon started a new conversation Capture Model Count In Factory

I need a way to generate data in factory based on the number of models being generated in the current run. Is there a way to do this? I know I can do incrementation using Generator, but that has a global scope, what I need is an increment for each separate run of a factory.

10 Dec
5 months ago

Nospoon left a reply on Why Doesn't Laravel Include Rabbitmq Queue Driver?

I think the original question is a good point. Why isn't it supported out of the box? RabbitMQ is the most popular message queue service.

29 Nov
5 months ago

Nospoon left a reply on General Error: 2014 Cannot Execute Queries While Other Unbuffered Queries Are Active.

Sorry I can't provide any additional code for security reasons, but $sql is just the raw query string which I kept separate to make things cleaner, as it's a pretty large one. But it doesn't actually vary between runs.

I'm a big fan of eloquent and collections but couldn't use them here due to efficiency reasons.

After doing some more research it looks like the issue might actually be related to mysql version on the db server, as it seems to have started happening shortly after switching servers.

28 Nov
5 months ago

Nospoon started a new conversation General Error: 2014 Cannot Execute Queries While Other Unbuffered Queries Are Active.

I'm randomly getting a PDO error on my query:

SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.

The most confusing part is this is not happening regularly, only on 1% of queries or less. Also this started happening recently without any relevant change to the code, so I'm actually suspecting a bug in the mysql php library.

I already did quite a bit of searching and didn't really find any helpful solutions. The PDO::MYSQL_ATTR_USE_BUFFERED_QUERY is on by default so the suggestion from error itself is of no use.

Below is the code fragment containing query execution.

$query = \DB::connection('sip_slave')
            ->table($table . ' AS c')
            ->selectRaw(\DB::raw($sql))
            ->leftJoin('destinations AS d', 'd.intDestinationId', '=', 'c.destination')
            ->leftJoin('tariffData AS td', 'td.intTariffDataId', '=', 'c.tariffData')
            ->whereRaw($where, [
                'fromDate' => $fromDate->format('Y-m-d H:i:s'),
                'toDate' => $toDate->format('Y-m-d H:i:s'),
                'accountId' => $account->id
            ]);
$query->get();

The above sits in a method which runs inside a foreach loop.

07 Aug
9 months ago

Nospoon left a reply on Dusk Integration In PhpStorm

Yeah I don't intend to run those at every save by any means. I just like the convenience of being able to run tests with keyboard shortcut. I've tried hooking it up as Bash configuration, hoping it would just run the command as you normally would, but that doesn't seem to work or I'm doing something wrong.

Nospoon started a new conversation Dusk Integration In PhpStorm

Does anyone know a way to integrate Laravel Dusk tests in in PhpStorm in a similar fashion to PhpUnit tests?

11 Jul
10 months ago

Nospoon left a reply on Custom Authentification Query

You would need to implement a custom authentication guard. You can probably lift most of the logic from Illuminate/Auth/SessionGuard

Nospoon started a new conversation Accessing Passport JSON API

I am probably completely misunderstanding some concepts here, but would be grateful for some guidance. So in the documentation (https://laravel.com/docs/5.6/passport#personal-access-tokens) it says that "Passport also includes a JSON API for managing personal access tokens." However looking at the Passport's RouteRegistrar, it looks like all the routes are using web middleware, and indeed, if I try to access the routes via a REST client, it tries to display te login form or shows Unauthenticated if I pass in the Accept: application/json header. However if that is the case, then how can the axios calls be performed within the included Vue components like so:

getTokens() {
                axios.get('/oauth/personal-access-tokens')
                        .then(response => {
                            this.tokens = response.data;
                        });
            },

The main question I have is this: is it possible to be able to access those routes as JSON API and at the same time be able to still use the front-end? I know that I can change the web guard to use passport, but then the front-end will not work.

25 Jun
10 months ago

Nospoon left a reply on Queue::assertPushed() Not Working

I am calling the fake method on Queue as the first thing in the test.

/** @test */
    public function it_pushes_send_job_to_the_queue()
    {
        \Queue::fake();
        $user = factory(User::class)->create();
        factory(FaxApplication::class)->states(['with_cover', 'default'])->create([
            'user_id' => $user->id,
        ]);
        $mail = storage_path('testing/mail/mail_simple');
        $channel = new Channel();

        $asteriskClientMock = \Mockery::mock(AriClient::class, ['originate' => $channel]);
        $this->instance(AsteriskClientInterface::class, $asteriskClientMock);

        \Artisan::call('test:email', ['file' => $mail]);

        \Queue::assertPushed(SendFax::class);
    }

The test:email command is relaying the test file into another artisan command responsible for all the processing. Here's the bit inside it that's pushing to the queue:

foreach ($destinations as $destination) {
    $fax = $this->faxService->generateFax($destination, $attachments, $email);

    if ($fax) {
        SendFax::dispatchNow($fax);
        $queuedFaxIds[] = $fax->id;
    }
 }
21 Jun
11 months ago

Nospoon left a reply on "The Expected [App\Jobs\ChargeBox] Job Was Not Pushed."

I'm having the same problem when trying to test queue jobs.

Nospoon left a reply on Queue::assertPushed() Not Working

Sorry, can't post the surrounding code here, but it is irrelevant to the issue either way. I've actually stumbled across the same exact problem wit \Mail::fake() today, I can verify code inside a mailable is being executed but \Mail::assertSent claims it was sent 0 times.

14 Jun
11 months ago

Nospoon left a reply on Parse String To View

Most of the comments here are totally useless. You just keep saying there's no benefit to it and why would he ever want to do this, etc. Can we just assume he really needs/wants to do this and propose actual solutions rather than just throwing the same useless comments around on and on?

Nospoon started a new conversation Queue::assertPushed() Not Working

I have a job that's being dispatched with SendFax::dispatchNow($fax);, i can confirm it being dispatched by running dd() from inside the job, however when I try to test it with Queue:fake() and then \Queue::assertPushed(SendFax::class);, it claims it didn't push, the test fails with The expected [App\Jobs\SendFax] job was not pushed. I tried changing dispatchNow() to dispatch() also but that didn't help. Any ideas what could be wrong?

03 May
1 year ago

Nospoon left a reply on SqLite "no Such Table" Error In Unit Tests With Migrations

I'm having the same problem with the new project I started recently. Funny thing is, I have this working perfectly in another project, but can't get it working on the new one.

01 Feb
1 year ago

Nospoon started a new conversation Refresh Config Instance On Running Process

Is it possible to reload Config instance on a daemon process without terminating it? I have a config value that's resolved from a method call and what I need is for it to be updated each time a method in my queue handler is called, rather than fetched from the existing Config instance.

26 Jan
1 year ago

Nospoon left a reply on No Concat Method On Collection

Updating composer dependencies helped. I'm guessing laravel/framework (v5.4.23 => v5.4.36) is what fixed it.

Nospoon left a reply on No Concat Method On Collection

I'd really love to, but the site blocks all of my attempts to post any code whatsoever.

It is really simple though, I just instantiate a new Illuminate\Support\Collection and then try to run a concat on it, with a result set from elasticsearch query.

Nospoon started a new conversation No Concat Method On Collection

The documentation for L 5.4, which is what I'm using, lists the concat method being available on collections. However when I try to use it, I get an error, as the method doesn't exist.

06 Dec
1 year ago

Nospoon left a reply on Eloquent Help: Generating Attribute Values Before Creating Record

Ah, nevermind, I forgot to set the attributes array.

05 Dec
1 year ago

Nospoon left a reply on Eloquent Help: Generating Attribute Values Before Creating Record

I'm trying to do something similar, where I'm generating an api key and secret for the user upon creation, however for some reason the fields are not being persisted to the database. They're there when the object is created, but when I grab a fresh instance from db they're gone. Any ideas?

28 Jun
1 year ago

Nospoon left a reply on [5.4] Contextual Binding Not Working

Ok I figured it out. The problem was that the contextual binding only works with interfaces and I was trying to to use it on a concrete SmsMessageService class. I had to have the class implement an interface and inject that in my controller instead. I'm not too happy about having to implement an interface that's only ever used once in that class, but at least that solves the problem.

27 Jun
1 year ago

Nospoon started a new conversation [5.4] Contextual Binding Not Working

I'm trying to use contextual binding for one of my services, but just can't get it work. I tried everything, injecting inside controller's constructor as well as using app() or resolve(). In the register method on my service provider I have something like this:

\App::when(SmsController::class)
    ->needs(SmsMessageService::class)
    ->give(function () {
        return new SmsMessageService(new SmsMessageParser(new SmsUdh()));
});
\App::when(VcardController::class)
    ->needs(SmsMessageService::class)
    ->give(function () {
        return new SmsMessageService(new SmsMessageParser(new VcardUdh()));
});

No matter what I do, it always resolves with the wrong dependency in the VcardController

Nospoon started a new conversation Container Instance Override Not Working

I have a SmsMessageParser class which accepts a dependency of either SmsUdh or VcardUdh class the default being SmsUdh. I'm trying to override a DI instance inside my controller like so:

$udh = new VcardUdh();
$messageParser = new SmsMessageParser($udh);
\App::instance('sms_message_parser', $messageParser);

But when I dd(\App::make('sms_message_parser')); it always returns the SmsMessageParser with SmsUdh instead of VcardUdh.

I also tried using contextual binding for this, but that didn't work either.

25 Jun
1 year ago

Nospoon left a reply on Laravel Mix Not Processing Scss

@bobbybouwmann , you're right in that if I disable the semantic-ui include and use mix.sass it does work. Unfortunately with semantic-ui included it throws an error. Invalid CSS after "r": expected 1 selector or at-rule, was "require('./js/api')"

Nospoon left a reply on Laravel Mix Not Processing Scss

I can't, If I use sass it will throw an error as the semantic-ui-sass package uses .scss and they're not compatible.

Nospoon started a new conversation Laravel Mix Not Processing Scss

For some reason webpack doesn't process the scss into css. When I run npm run dev it goes through fine without errors, but it doesn't produce app.css file. I'm using pretty standard setup in my webpack.mix.js:

 mix.js('resources/assets/js/app.js', 'public/js')
    .extract(['vue', 'semantic-ui-sass'])
    .scss('resources/assets/sass/app.scss', 'public/css')
    .version();

And in my main template I'm including it with mix like this: <link href="{{ mix('css/app.css') }}" rel="stylesheet">

04 May
2 years ago

Nospoon left a reply on Issue With Model Relation

Solved it. Still I do not understand why it behaved like it did.

It was an issue with the HashedId trait. It contained the following method:

public static function findHashed($hashid)
    {
        $decoded = \Hashids::decode($hashid);

        if (!$decoded) {
            return null;
        }

        return self::find($decoded);
    }

The first line should be $decoded = \Hashids::decode($hashid)[0];.

It returned an array with single value, which was then being passed to application()->associate(Application::findHashed($request->get('application_id'))), causing it to create a collection of related entities, even though there was only one.

I still do not understand though why it was returning the collection when requesting $message->application_id, which should just return the value of database row and why was $message->application returning null.

Nospoon started a new conversation Issue With Model Relation

I'm experiencing a very weird issue with one of my relations. I have a Message model which has an application_id foreign key.

In my Message model I have a relation declared like so:

public function application()
    {
        return $this->belongsTo(Application::class);
    }

However whenever I request $message->application_id, which should just give me the plain ID value, it returns the whole Application object instead.

Weirdly enough, $message->application()->associate($application); seems to work, but $message->application gives me null.

I've double and triple checked everything and can't figure out what the hell is wrong with it. I've never seen anything like this with any of my other models.

28 Apr
2 years ago

Nospoon left a reply on Routes And Url

The only thing that comes to my mind is that the route name could be clashing with the actual bare url. Try renaming the route to something like shop.index and see what happens.

Nospoon left a reply on Validate Attribute Contains The Value Of Another Attribute

I don't think this is what I'm looking for.

I need both fields to be required, but additionally the expected value in second field is dynamic, depending on what the user puts in first field. So it could be %some_key%, $differentone or #whateveryoufancy. Also the second field would contain some additional text, so it's not a simple 1 to 1 check.

Nospoon left a reply on Routes And Url

Can you show how are you rendering the urls in your views?

I'm guessing you're using relative urls without preceding /. Try using absolute ones with url() method or name your routes and use route() method in your hrefs.

Nospoon started a new conversation Validate Attribute Contains The Value Of Another Attribute

I have this specific requirement for validation, I need to check that a value specified in one input attribute is present in another attribute.

For example: Say we have two inputs, keyword and message. If the keyword attribute has a value of %some_key%, I want to verify that a message attribute's value is something like Hello, your key is %some_key%. and I want it to fail if it doesn't contain the %some_key% keyword.

How would I best approach that?

Nospoon left a reply on What To Test In A RESTful API

It all depends. I'd say if you know you have your auth middleware applied on the whole group, testing it on every single endpoint is redundant.

Depending on what happens in your application, you might sometimes want to have a mix of unit and functional tests for some more complex stuff.

As a general rule - Think about what should happen and what could possibly go wrong and test against that. Think how would you be testing it manually, what would you be looking for.

I always tend to test the return values of each endpoint as well as required parameters if applicable. I also check if resources are saved to database as expected. If it handles the input the way you want it and spills out the output you expect, it's all good.

26 Apr
2 years ago

Nospoon left a reply on Route::bind() To Decode Hashid

I'm facing a similar situation but for me the Route::bind is not working at all. What I have is:

Route::bind('application', function ($id, $route) {
                return \Hashids::decode($id)[0];
            });

But it's still passing through hashed id. It makes absolutely no difference whether I disable or enable the binding block.

23 Feb
2 years ago

Nospoon left a reply on Eloquent Results As Array Instead Of Object

@Mittensoff , It's more of a unique case this one so I probably wouldn't want this to be the default. Is it possible to set it on runtime?

@cipsas , toArray() on collection only converts the collection, not underlying objects.

I could use (array) conversion on every object, but it doesn't really solve the performance problem as it is still being hydrated as an object in the first place, so it's just an additional step on top.

Nospoon started a new conversation Eloquent Results As Array Instead Of Object

Is it possible to return a collection of arrays rather than objects from Eloquent query?

I am performing a raw query and for performance reasons would like the results not to be hydrated into objects (huge amounts of data being parsed) but returned as arrays inside the collection. So far I couldn't find a way around this, even with raw query it always returns instances of StdObject.

17 Feb
2 years ago

Nospoon left a reply on [L5] Nice Names Attributes - Validation

Is it actually possible to disable the automatic underscore removal? When working on an API this is not a good thing.

03 Feb
2 years ago

Nospoon left a reply on Valet V1.1.2 Update: Just Keep Getting The 'It Works'

I'm using Valet 2.0.3 and nothing of the above seems to be working. I had it working for some time but now suddenly all I can get i "It works!". Even after I stop apache this page is still displayed. Neither restarting nor completely removing and reinstalling Valet helps.

07 Jan
2 years ago

Nospoon left a reply on Handling Authorize() Fails By Redirecting To A Specific Page

I have the same problem. I want to redirect users to login page if they hot a page that requires them to be logged in to see it. I tried overwriting the deny method on my custom policy to do a redirect instead of throwing an exception, but it didn't work.

21 May
3 years ago

Nospoon left a reply on Auth Session Killed After Redirect | Laravel 5.2

It's also important to pass the request parameter in the controller action (the one you're redirecting to after login), otherwise it will not see the session. Just something I learned today when facing the same issue.

27 Aug
3 years ago

Nospoon left a reply on L5.1 - Issues With Blade's Nesting And Includes

Just as a quick note, since this error appeared for me again when using phpUnit. It seems to be an issue when using xdebug. It can be setting xdebug.max_nesting_level to a higher value in php.ini or module config file.

Nospoon left a reply on L5.1 - Issues With Blade's Nesting And Includes

I thought I got rid of this error but there it is again this time when running phpUnit test. Fatal error: Maximum function nesting level of '100' reached, aborting!

23 Aug
3 years ago

Nospoon left a reply on L5.1 - Issues With Blade's Nesting And Includes

Now here's a weird thing. Today I fired it up just as I left it yesterday without doing anything and it doesn't throw an error. Somehow it automagically fixed itself, I assume that restarting apache did this but not sure why that would be the case.

Btw, navbar and footer are just simple html chunks so I doubt they would be causing the issue. Also they worked fine in two level nested views, just not with three levels.

And yes, the () after @endsection was a typo on my end.

22 Aug
3 years ago

Nospoon started a new conversation L5.1 - Issues With Blade's Nesting And Includes

So I've stumbled across an issue today. I have a structure of views like this: base -> view.base -> view, where the first base file also includes some partials like navbar and footer.

Thing is, when going into third level of inheritance, I get an exception: Maximum function nesting level of '100' reached, aborting!

It appears that the reason for this error are the includes in first parent view. If I remove those it all renders fine.

Does anyone know a way around it or have a better idea for organizing this?

Here's a bit more of how my views look like:

...
<body id="body">
    <header>
        @include('partials.navbar')
    </header>
    <main>
        @yield('body')
    </main>
    <footer>
        @include('partials.footer')
    </footer>
    @yield('scripts')
</body>
...
@extends('base')

@section('title', 'Overview')

@section('body')
    <div class="row">
        <div class="medium-2 columns">
            @yield('sidebar')
        </div>
        <div class="medium-10 columns">
            @yield('content')
        </div>
    </div>
@endsection()
@extends('panel.base')

@section('title', 'Overview')

@section('sidebar')
    <nav class="side-nav sidebar">
    ...
    </nav>
@endsection

@section('content')
    <div class="row">
        <div class="large-6 columns">
            ...
        </div>
    </div>
@endsection
09 Aug
3 years ago

Nospoon left a reply on Laravel 5.1 - Can't Get Facade To Work

@usman clear-compiled didn't help as well. Still getting Class address_finder does not exist.

Nospoon left a reply on Laravel 5.1 - Can't Get Facade To Work

Ok so the only way I've managed to get this working is by: in register() method of service provider referencing full class name:

$this->app->singleton('App\Services\AddressFinder', function () {
            return new AddressFinder('idealpostcodes');
        });

in facade

protected static function getFacadeAccessor()
    {
        return 'App\Services\AddressFinder';
    }

However this is not how it's done with all other service providers...

Nospoon left a reply on Laravel 5.1 - Can't Get Facade To Work

Yes I did:

App\Providers\AddressFinderServiceProvider::class,

Nospoon left a reply on Laravel 5.1 - Can't Get Facade To Work

Well that's kind of the part which I don't exactly understand, how do I make the binding correctly so that it's available by address_finder handle?

Nospoon left a reply on Laravel 5.1 Can't Get Facade To Work

I've also seen different ways of binding the service, not sure which one is the correct one so I tried them all:

$this->app->singleton('address_finder', function () {
            return new AddressFinder('idealpostcodes');
        });

as well as

$this->app->bind('address_finder', function() {
            return new AddressFinder('idealpostcodes');
        });

Nospoon left a reply on Laravel 5.1 Can't Get Facade To Work

Yes, multiple times, didn't help.