goatshark

Experience

51,785

23 Best Reply Awards

  • Member Since 3 Years Ago
  • 460 Lessons Completed
  • 10 Favorites

23rd August, 2018

goatshark left a reply on Send Data From One Component To Another • 1 month ago

@craigb88 You could dive into Vuex. I haven't yet. Alternatively, I sometimes add this to the app.js file:

window.EventBus = new Vue({});

This EventBus can be used by both components.

You can emit():

EventBus.$emit('some-event-name');

Or emit() with data:

EventBus.$emit('some-event-name', data);

On the receiving component, I add the listener to an initializeEventBus method and call that method from the created method. I also stop listening in the standard beforeDestroy method.

    created: function() {
        this.initializeEventBus();
    },

    beforeDestroy: function() {
        EventBus.$off();
    },

    methods: {
        initializeEventBus: function() {
            EventBus.$on('some-event-name', function() {
                // do some things
            }.bind(this));
        },
    }

21st August, 2018

goatshark left a reply on Is There Exist Any Way To Get Ipv6 From Client Request? • 1 month ago

Hey @alihoushyaripour Have you looked in $request->server? The REMOTE_ADDR might/should hav it. You can see if that's got what you are looking for by tossing something like this in your web.php file.

Route::get('test', function(\Illuminate\Http\Request $request) {
    dd($request->server);
});

goatshark left a reply on Laravel Cloud Storage • 1 month ago

@srikanthgopi Like so many other things, it depends. I think the one that you can afford and get working is a good place to start. I realize that that's kind of a dick answer, but . . . it depends.

goatshark left a reply on Laravel Cloud Storage • 1 month ago

@srikanthgopi This might sound a little over simplified, but I would suggest taking a look at Spatie's Laravel Medialibrary. The destination of the files should be dependent only on what filesystems you configure in Laravel and subsequently which filesystems you tell Medialibrary (or your code) to use.

20th August, 2018

goatshark left a reply on How To Change Env Variable / Config In Dusk Test? • 1 month ago

Got it. I've used config()->set('configfile.key.whatever', 'theValue') in thesetUp()method of tests successfully, but that *should* do the same thing asConfig::set()`.

25th June, 2018

goatshark left a reply on Vagrant, Docker Or What? • 2 months ago

@gthell - Yeah, what @ejdelmonico said. :) Personally, I stopped using vagrant in dev in favor of valet. I've got Docker in production and I really love a lot of things about it. That said, it isn't all rainbows and unicorns over in the Docker camp. I'm still stubbing my toes on things that wouldn't be an issue on an old school, everything-on-one-machine-and-one-OS installation.

19th June, 2018

goatshark left a reply on Laravel Echo Not Working With No Errors • 3 months 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 months 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 months 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 months ago

@r123 Can you post your MessagePosted event?

goatshark left a reply on Laravel Echo Not Working With No Errors • 3 months 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 months 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 • 3 months 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 • 6 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 • 6 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 • 6 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 • 6 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 • 6 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 • 6 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 • 8 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 • 8 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 • 8 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 • 8 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 • 8 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 • 8 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 • 8 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 • 8 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() • 8 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 • 8 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 ? • 8 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 • 8 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 • 8 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 • 9 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 • 9 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 • 9 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 • 9 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 • 10 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 • 11 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 • 11 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? • 11 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 • 11 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 • 11 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 • 11 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 • 11 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 • 11 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.

Edit Your Profile
Update

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