goatshark

Experience

48,995

22 Best Reply Awards

  • Member Since 3 Years Ago
  • 440 Lessons Completed
  • 9 Favorites

19th June, 2018

goatshark left a reply on Laravel Echo Not Working With No Errors • 2 days ago

@r123 I'm glad you solved it. Most of the struggles I have with broadcasting end up being queue related. There's a lot of "How is my queue running? Oh right, cron. Oh wait, no, Horizon. So I need to restart....Horizon. Or do I need to just php artisan queue:restart. But I'm running larave-echo-server, so maybe that. Idk, maybe restart everything." ....at least, that's how it goes down here in Short Attention Span Theatre.

Have fun.

18th June, 2018

goatshark left a reply on Laravel Echo Not Working With No Errors • 3 days ago

@r123 If that controller index method is logging broadcasts, it just seems like either BROADCAST_DRIVER or QUEUE_DRIVER are set to log. I'll check a couple projects I have here.

goatshark left a reply on Laravel Echo Not Working With No Errors • 3 days ago

@r123 Where is your report of the broadcast coming from? By that I mean, the message you said you see when it fires: local.INFO: Broadcasting [App\Events\MessagePosted] on channels [presence-chatroom] with payload: Just curious. Also, I would be tempted to temporarily add \Log::info('broadcasting MessagePosted'); right beforereturn new PresenceChannel('chatroom') just to verify (re-verify?) that it's being fired.

goatshark left a reply on Laravel Echo Not Working With No Errors • 3 days ago

@r123 Can you post your MessagePosted event?

goatshark left a reply on Laravel Echo Not Working With No Errors • 3 days ago

@r123

You wouldn't want to use redis. You'll want pusher just like you have. Sorry about that.

So you see the client connections in Pusher's dashboard, but not the Event broadcasts?

goatshark left a reply on Laravel Echo Not Working With No Errors • 3 days ago

@r123 What's the BROADCAST_DRIVER set to in .env? It looks like it might be set to log. You probably want redis, if that's the case.

Also, make sure to check the Pusher console to see what is (or isn't) happening.

16th June, 2018

goatshark left a reply on Open A Bootstrap Modal Using Middleware • 5 days ago

@Snapey, I like the view composer idea. I was thinking, more generically, of mentioning that I use session variables as a dumping ground for that kind of thing. They're pretty baked in, and they're easy to import into a js framework of you're using one.

18th March, 2018

goatshark left a reply on Help How To Find String Inside Srting • 3 months ago

@HAIZONE To be clear, you want to parse this string:

HP Pavilion x360 14 ba103nj 3GB81EA

And you want to know if ba103nj 3GB81EA or 3GB81EA ba103nj exists in it?

Or are you only checking for ba103nj 3GB81EA?

This (below) doesn't cover your use case, but maybe gives an idea of an approach you could use. I find in_array() to be pretty handy.

$search_string = 'ba103nj';
$text = 'HP Pavilion x360 14 ba103nj 3GB81EA';
$parts_array = explode(' ', $text);

return in_array($search_string, $part_array);

1st March, 2018

goatshark left a reply on Firing Ansible Jobs • 3 months ago

@minitriga That is a great question. I do not think I got php-ansible working as expected. I think I bailed on it and moved on....to what? A mess of everything: some Envoy, some Symfony Process and a combination of lots of other small, not-comprehensive together, tools. I'm not feigning coy here, there's just been a lot of keyboard time since then. If you can explain what you're up to, I'd be happy to see if I have anything that fits, or tips, warnings, etc. I'd love to know what you're up to.

goatshark left a reply on Destroy Route Link • 3 months ago

@sutherland Creating a destroy form for a delete button has always seemed a little heavy handed to me too. Nonetheless, I am not aware of any alternatives that I like when I'm working without js (vue, etc.).

I usually just wrap form buttons in a form.

<form method="POST" action="something">
    {{ csrf_field() }}
    {{ method_field('DELETE') }}
   <button type="submit" class="btn btn-link text-dark float-right">Delete</button>
</form>

goatshark left a reply on MAC Addresses On LAN • 3 months ago

@smartnathan This could be a can of worms for you, but . . .

https://github.com/willdurand/nmap

There are other nmap php libraries. I've used this one and it's worked well.

27th February, 2018

goatshark left a reply on Str_slug() Ate My Baby • 3 months ago

@m-rk, @36864 Yes, exactly that. I can see that now. Thank you both!

goatshark started a new conversation Str_slug() Ate My Baby • 3 months ago

Curious: I'm trying to use str_slug to convert something like this 'One Two three' to this 'one%20two%20three'.

str_slug('Dingos ate my babies', '%20') = dingos%20ate%20my%20baby

str_slug('10009', '%20') = 1%201
str_slug('10000000009', '%20') = 1%201

Why doesn't str_slug dig zeros? I've looked through Str::class's slug() method and while it's really nice, I don't see anything that jumps out and says "I molest zeros".

Any ideas?

18th January, 2018

goatshark left a reply on Pattern Suggestion For Requests • 5 months ago

@itstrueimryan Point taken. Agreed.

Being a shameless, serial violator of SRP, myself, I use that in my requests from time to time. :)

goatshark left a reply on Pattern Suggestion For Requests • 5 months ago

While this doesn't exactly address duplication between your rules, keep in mind that you have access to the method in your Request.

For create:

if ($this->method() == 'POST')

For Update:

if ($this->method() == 'PATCH')

16th January, 2018

goatshark left a reply on Troubleshooting PHPUnit - All Tests Failing With "unauthenticated" Error • 5 months ago

Why is it that I always rm -rf vendor && composer update after fighting for far too long with bazar problems? That fixed it and I don't even care what was wrong. :)

15th January, 2018

goatshark started a new conversation Troubleshooting PHPUnit - All Tests Failing With "unauthenticated" Error • 5 months ago

So here's a situation. I've got a couple hundred tests, mostly involving API endpoints in my application. I auth my tests in what I think is a pretty typical way. I new up a user in the setUp() method and then proceed to use actingAs($this->user, 'api').

Currently, all my tests are failing with "unauthenticated".

When I use the web interface (in other words, not in phpunit env) everything still works. This makes me think it is a problem specific to phpunit.

I don't recall any changes to authentication, users, or phpunit configs. There may have been a composer update run since the last run of the tests, but not much else.

Any thoughts on how to troubleshoot this?

5th January, 2018

goatshark left a reply on Model Factories And Testing • 5 months ago

@xtremer360 Can you post your relationships for the three models (Event,Game,Team)?

goatshark left a reply on Migrate And Seed Only Once • 5 months ago

If you put the logic for deciding whether or not to create the records in your seeder, then that seeder becomes idempotent and it won't matter if it is executed multiple times.

However, if you don't want that logic in the individual seeder classes, and if you are firing your seeders from Databaseseeder::class, you could add the logic there to decide whether or not to run each seeder.

goatshark left a reply on Migrate And Seed Only Once • 5 months ago

You can base your seeder decisions on environment variables and snag the version from env().

I don't understand your question. Are you trying to have the seeder not run at all under certain circumstances?

If you're talking about your migration, php artisan migrate and it's commands should handle all of that for you. You can re-run php artisan migrate and not stomp on previous migrations.

goatshark left a reply on Migrate And Seed Only Once • 5 months ago

@eludic For the seeders, I've done all sorts of things to check for the existence of records and only add them if they are not already present. When I do that, I typically use the run() method to call protected functions, like this:

    public function run()
    {
        $this->makeRoles();
    }

Then I will have something like:

    protected function makeRoles()
    {
        if ( ! $this->adminExists() ) {
            Role::create(['name'=>'Admin','slug'=>'admin']);
        }
    }

    protected function adminExists()
    {
        return (Role::whereName('Admin')->count()) ? true : false;
    }

That's just an example. I think the most important thing to realize is that those seeders are just classes.

2nd January, 2018

goatshark left a reply on Resource CRUD Store() And Update() • 5 months ago

@fen You might want to start here:

https://laravel.com/docs/5.5/validation#form-request-validation

You can start by moving your validation into the request class. This will get you on the right path (or "a" right path). Keep in mind that these request classes can be used for more than just validation.

31st December, 2017

goatshark left a reply on ENV Not Applied • 5 months ago

@ITELLMYSELFSECRETS Have you tried it in an incognito browser or cleared your cache?

goatshark left a reply on How To Do Use Variable As Global In Controller ? • 5 months ago

@hsntngr

Considering the fetchCart() method that @shez1983 suggested...

public function fetchCart() {}

That is a method on the CartController::class. If I 'new up' an instance of CartController::class, I can execute that function on it, like this (ish):

$cart_controller = new App\Http\Controllers\CartController();
$cart = $cart_controller->fetchCart();

But, if you want to use that cart within that class, you'll need to use the constructor.

    /**
     * @var  $cart Intance of Cart::class
     */
    public $cart;

    public function __construct()
    {
        $this->cart = $this->fetchCart();
    }

Does that make sense?

29th December, 2017

goatshark left a reply on Model Factories And Testing • 5 months ago

@xtremer360

Check out ->make() instead of ->create() while working with factories. And don't forget that you can overwrite data that your factory class would have provided. That way you can make() something with:

$child = factory(Child::class)->make(['parent_id' => null]);

$parent->children()->create($child);

...or some variation of that.

27th December, 2017

goatshark left a reply on Axios Catch Error Not Show • 5 months ago

@flyforever123 Have you tried just console logging error.response.data to see what shows up in the inspector's console? I know this might be considered a little brutish, but:

    methods: {
        onSubmit() {
            axios.post('/projects', this.$data)
                .then(response => alert('Success'))
                .catch(error => console.log(error.response.data));
        }
    }

That will at least prove that you are or are not getting what you expect back from your application.

24th December, 2017

goatshark left a reply on Best Way To Store Product Images • 5 months ago

@umerhassan The Internet connection I'm on most of the time has very limited upload. It sounds like your's does/might too. If you just save locally, does it save almost immediately? Just trying to determine if the upload speed is your bottleneck. If it is, you could save locally in development and save to s3 in production. Or save locally and fire an Event/Listener or Job to do the work of talking to s3 (or anyone out in the network).

goatshark left a reply on Vue Warning: Unknown Custom Element • 5 months ago

@kylejoeckel Thanks. I'll check that out. I still run into this from time to time and am just starting the front end of a new project, so I'm sure it'll come up very soon.

Thanks.

23rd December, 2017

goatshark left a reply on Best Way To Store Product Images • 5 months ago

@UMERHASSAN I did this recently. It was yesterday-ish. I used Spatie's Laravel Medialibrary

https://docs.spatie.be/laravel-medialibrary

There are some really handy methods for treating an object as having just one single image attached to it. I also think that it handles the file storage / destination work very well.

goatshark left a reply on Laravel Storage - Retrieve All Files With Meta Data In Array • 5 months ago

@mbrown1408 You might also want to check out Spatie's Medialibrary

https://docs.spatie.be/laravel-medialibrary

27th October, 2017

goatshark left a reply on Avoid Mutating A Prop Directly Since The Value Will Be Overwritten Whenever The Parent Component Re-renders • 7 months ago

@Uzenkov Any time you try to modify data that you've sent into a component as a "prop", Vue is going to get cranky and warn you not to do it. I think your warning was about modifying this.itemstatus in your computed status.get method. You might have even gotten away with it had you returned the value instead of trying to set the value of this.itemstatus in your computed property. I always use computed properties to return something instead of just using them as property-setting-logic. Does that make sense?

17th October, 2017

goatshark left a reply on Backups On Dropbox • 8 months ago

@Lina What @Snapey said. For sure.

6th October, 2017

goatshark left a reply on Not Sure If I Am Doing My Actions The Right Way • 8 months ago

@benoit1980 Instead of returning the index view from the store method, you could instead return a redirect to get you back through the index() method on that controller.

https://laravel.com/docs/5.5/responses#redirects

goatshark left a reply on Relationships; Nested Parents? • 8 months ago

@brysonreece

public function children()
{
   return $this->hasManyThrough(Child::class, Bus::class);
}

Depending on your db layout, you might have to tell hasManyThrough() what columns to care about.

Child-->school might look like this on the Child model:

public function school()
{
   return $this->bus->school;
}

Those might not fit exactly what you're doing, but maybe they give you some ideas on what direction to go.

5th October, 2017

goatshark left a reply on Vue Error Every Time App.scss Is Compiled • 8 months ago

@edoc This problem appears to be fixed. I upgraded laravel-mix and after doing that, things seem good.

npm update didn't do it for me, so I checked my package.json file. It had this for laravel-mix:

"laravel-mix": "^1.0",

I changed that line to this:

"laravel-mix": "^1.4.5",

..and then ran npm update. The symptoms have now disappeared. Yay. I'm still a little skeptical, so I'm going to re-test this in a few other projects. That said, I think this might be a fix (although still a mystery).

4th October, 2017

goatshark left a reply on PHP Array Output • 8 months ago

@hecate0211 Are you trying to re-order the elements in the outer array? You could try array_reverse().

goatshark left a reply on DataErrorException: Trying To Get Property Of Non-object When QUEUE_DRIVER=database • 8 months ago

@blueyan Did you:

php artisan queue:table

php artisan migrate

...before switching the queue driver to database?

2nd October, 2017

goatshark left a reply on Vue Error Every Time App.scss Is Compiled • 8 months ago

@edoc Cancel that. It appears to still have the same issue. My testing procedure needs modified. :)

goatshark left a reply on Vue Error Every Time App.scss Is Compiled • 8 months ago

@edoc Here's a strange find. I've done half a dozen or so Laravel 5.5 projects that all have this problem. I have never used yarn before yesterday. For whatever reason, I used yarn add instead of npm install to install something random, in this case, 'autosize'.

After installing something via yarn, this project does not have this issue. I'm going to yarn install something in one of the other projects to see if it (magically) fixes it.

I know this isn't great troubleshooting data, but I just realized it so I haven't had time to dig in yet.

26th September, 2017

goatshark left a reply on Need Help With Eloquent Data Model/relationships Or Query Statement • 8 months ago

@stephen_p In my experience, pivot tables are not used for hasMany/belongsTo relationships. I think a hasManyThrough relationship between User and Schedule would get you most of the way there.

On User:

public function schedules()
{
    $this->hasManyThrough(Schedule::class, Account::class);
}

I'm not sure this will work with your table structure though. Unless there's a specific reason you're using pivot tables, you might try:

  1. Dumping the pivot tables
  2. Add a user_id (integer) column on acccounts
  3. Add an account_id (integer) column on schedules.

Then: user-->hasMany-->account user-->hasManyThrough-->schedule

account-->belongsTo-->user account-->hasMany-->schedule

schedule-->belongsTo-->account

Then you could $user->schedules(). .....or something like that. :)

goatshark left a reply on TokenMismatchException In VerifyCsrfToken.php (line 68) In Laravel 5.4 • 8 months ago

@kamran186 Can you post what is returned?

goatshark left a reply on TokenMismatchException In VerifyCsrfToken.php (line 68) In Laravel 5.4 • 8 months ago

@kamran186 To @nadj's point....I'm sure you checked this, but I've burned quite a few minutes in life troubleshooting things that ended up being fixed with a good old browser cache clear and reload.

25th September, 2017

goatshark left a reply on TokenMismatchException In VerifyCsrfToken.php (line 68) In Laravel 5.4 • 8 months ago

@KAMRAN186 Is the csrf field being rendered? If you view source on the page, do you see it, and does it match the app key that you have in .env?

goatshark left a reply on How To Change Value Of An Attribute Model • 8 months ago

@stackboot Yes. Also, you don't have to mutate the exact field name. By that I mean, when I have a field called (example) 'version' but I don't want to take over that property with my accessor, I create an accessor for it with a name different than the field. So it might be getVersionFormattedAttribute(). Then, you would have available to you, $model->version (the original db data) and$model->version_formatted` (your accessor). Then you can access either of these via the relationship.

goatshark left a reply on How To Change Value Of An Attribute Model • 8 months ago

@stackboot If you absolutely need a mutator, but can't use one because that value is being used elsewhere in the application in it's original format from the db, you could create a secondary/alternative model class for that database table. Alternatively, you could just create a mutator with the name of a field that is not in the database. So instead of getMyFieldAttribute() matching up with the my_field field, you could leave the db exactly as it is, but make your new accessor something like getMyNewFieldAttribute(). It can still work on the same field, you're just giving it a name that isn't going to overlap with the original db field name. Does that explanation make any sense?

goatshark left a reply on How To Change Value Of An Attribute Model • 8 months ago

@stackboot Same database or same Laravel application? If it's just the same database, then the mutators could work because you're not changing what's in the database, just how Laravel is presenting it to you. And actually, on the topic of presentation, maybe a resource class is more fitting for you because you don't have to 'commit' to a model mutator and instead can customize what's returned on a per-resource-class basis.

https://laravel.com/docs/5.5/eloquent-resources

22nd September, 2017

goatshark left a reply on How To Modify Relation When Converting To Json? • 8 months ago

@poma If you're using Laravel 5.5, you can use a resource class for exactly that.

https://laravel.com/docs/5.5/eloquent-resources

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.