goatshark

Experience

47,315

22 Best Reply Awards

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

18th January, 2018

goatshark left a reply on Pattern Suggestion For Requests • 1 month 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 • 1 month 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 • 1 month 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 • 1 month 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 • 1 month ago

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

goatshark left a reply on Migrate And Seed Only Once • 1 month 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 • 1 month 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 • 1 month 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() • 1 month 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 • 1 month 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 ? • 1 month 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 • 1 month 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 • 1 month 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 • 1 month 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 • 1 month 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 • 1 month 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 • 1 month 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 • 3 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 • 4 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 • 4 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? • 4 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 • 4 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 • 4 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 • 4 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 • 4 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 • 4 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 • 4 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 • 4 months ago

@kamran186 Can you post what is returned?

goatshark left a reply on TokenMismatchException In VerifyCsrfToken.php (line 68) In Laravel 5.4 • 4 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 • 4 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 • 4 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 • 4 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 • 4 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? • 4 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

21st September, 2017

goatshark started a new conversation Resource Classes - How Are You Using Them? • 5 months ago

Greetings humans. The new resource classes are currently blowing my mind and making me rethink how I'm delivering data from my Laravel applications. I'm considering a separate group of routes, something like /api/resources/<whatever> to return resource classes for a standard way to get my transformed data from the API. I can see scope creep on the horizon with this approach though (which isn't stopping me from running with to see how it feels).

What are you wielding resource classes?

goatshark left a reply on How To Store Jpg File Into Sql Server? • 5 months ago

@tyzhang3 In that case, I have no idea, sorry. There are a lot of wicked smart people in these forums, so I'm sure you'll find a solution. Good luck.

goatshark left a reply on How To Store Jpg File Into Sql Server? • 5 months ago

@tyzhang3 I let the file system handle the files and just store the location (path) to them in the database as a text string. That is a pretty typical, dare I say the "normal", way to get this done.

On a related note, you should totally check out Spatie's Laravel Media Library. https://docs.spatie.be/laravel-medialibrary/v6/introduction

15th September, 2017

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

Hey @edoc, no update yet. Thanks for the link to that github issue. I did jump into that thread and will stick around in there to see where it goes. If/when something good is found, I'll get back in here and post about it.

11th September, 2017

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

@andreasbakir Will do! Today I have new strategy. I call it "harsh language and threats". I am optimistic. Your milage may vary.

8th September, 2017

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

@andreasbakir I almost feel guilty posting this... Looks like whatever the issue is, it's still there. After the first couple of saves, the same symptoms started again. I am going to dig into this over the weekend. I will, of course, post anything interesting (or fixing) I find.

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

@andreasbakir Good call on the removing node_modules and re-installing. That worked.

This was the first time I've installed with yarn instead of npm install. At this point, I won't know if it was rebuilding the node_modules directory alone that fixed it or if it was the use of yarn during the rebuild that fixed it. It was enough of a PITA though that I'm pretty okay with that this time.

Thanks again.

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

@andreasbakir That's an interesting point. I've been continuing to use npm install and haven't touched yarn yet. I'll try whacking the node_modules and reinstalling packages. Thanks for the suggestion.

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

@jminklerdmopc Just an update to the thread. Out of the box Laravel 5.5 project . . . seeing the same thing. If I make changes to my css, I see this error until I re-save a Vue file at least 3 times. I know it sounds like bad troubleshooting data, but it's all I have so far.

4th September, 2017

goatshark left a reply on Queues Vs Events • 5 months ago

Hey @lukasl Events vs. Queues isn't really a thing. Events have listeners. Listeners don't have to be queued, but they can be and often are. Jobs can also be queued. There is quite a bit of discussion 'out there' about Events vs. Jobs, which always ends up boiling down to personal preference (imo).

28th August, 2017

goatshark left a reply on Route::view • 5 months ago

@topvillas I'll second that with some light sobbing.

25th August, 2017

goatshark left a reply on Pulling In JSON Data From Another Domain • 5 months ago

@jackjones It sounds like you are/were just having problems because the server(s) you deployed to did not have libcurl installed. If that's the case, it isn't a problem with programming. You just need to make sure the appropriate software is installed on whatever server you're deploying to. You'll either need to make sure libcurl is available by default or that you have the required access to the server (ssh and sudo) to install it yourself. It's a very common library and is usually installed by default. Good luck.

goatshark left a reply on How To Run Vue.js Script After Page And All Other Scripts Have Fully Loaded? • 5 months ago

@jpeterson579 To prove it's an issue with timing, you could wrap it in a setTimeout() inside of mounted().

mounted() {
    setTimeout(() => {
        ...your code...
    }, 5000);
}

I know this doesn't produce a fix for you, but it might help you confirm you're working on the correct problem.

24th August, 2017

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

@jminklerdmopc I don't have any more data about this failure than I did when I posted it. It isn't that my troubleshooting hasn't gone anywhere. It is that I'm not yet sure where to start troubleshooting. I think I'll jump back into it tomorrow and see if I can come up with anything. I will, of course, post any results.

Edit Your Profile
Update

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