goatshark

Experience

44,405

20 Best Reply Awards

  • Member Since 2 Years Ago
  • 413 Lessons Completed
  • 9 Favorites

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 • 4 weeks 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 • 1 month 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 • 1 month 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? • 1 month 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 • 1 month 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 • 1 month 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 • 1 month 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 • 1 month 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 • 1 month 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 • 1 month 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 • 1 month ago

@kamran186 Can you post what is returned?

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

18th August, 2017

goatshark left a reply on Laravel - Forbidden Error • 3 months ago

Yo @Leff7 You should return true from authorize() in your FormRequest.

    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

goatshark left a reply on Vue Component Inside A Foreach Loop • 3 months ago

Just a random human's $.02...

I have zero heartburn firing up any number of components via a foreach loop. I do it frequently...most of the time I'm v-foring through a list because I'm already in a Vue component, but the idea is the same. And I have definitely fired them up with a Blade @foreach loop when not in a component already.

goatshark started a new conversation Vue Error Every Time App.scss Is Compiled • 3 months ago

Greetings. I've had a strange problem with a handful of recent projects. I will have to check on the exact versions, but it's been every new Laravel project in the last month or so.

Typical setup, using Vue, watching/compiling it with an unaltered webpack.mix.js file (npm run watch). Everything works well.

Any time I update app.scss or _variables.scss (seemingly anything having to do with css), it gets compiled successfully, but any page loads result in a console error...

Uncaught TypeError: Cannot read property 'common' of undefined

If I save a couple of my .vue files, compilation is executed again and everything works as expected. Seriously, I just open a couple component files and save them. I found that just saving one file once didn't do the trick.

It's as if compiling layout changes (css), while not making nmp run watch cranky, is making the compile app.js cranky. The fix, every time, just save a few Vue components and let things get compiled again.

Thoughts? Has anyone else seen this?

17th August, 2017

goatshark left a reply on Storage::put - To A Specific Directory • 3 months ago

Hey @timpackwood87 I think you can just feed the path into $name. You could

Storage::put('folder/folder/'.$name, $content);

Or set $name to the path relative to storage/app before that

$full_path = 'folder/folder/' . $name;
Storage::put($full_path, $content);

goatshark left a reply on Get User Password After Authentication • 3 months ago

@Yokovaski That is strange. Are you getting that exception just by implementing public function authenticated(Request $request, $user) in the Spark LoginController? Even if you implement it without any instructions, except again maybe a \Log::info('hit the authenticated method');?

goatshark left a reply on How To Filter And Order Table Rows In Vue 2.x • 3 months ago

Hey @rfountain I have not yet. That should change in the next 48 hours though as I'm rebuilding part of a front-end and am definitely going to have to use filters.

goatshark left a reply on Vue 1 - Event Emitting • 3 months ago

@jeff7 I think that sneaky little this is biting you. Maybe try one of these:

ready() {
    let self = this;
    eventHub.$on('videos.counter', function (counter) {
        self.numberOfVideos = counter;
    }
}

or

ready() {
    eventHub.$on('videos.counter', (counter) => {
        this.numberOfVideos = counter;
    }
}

goatshark left a reply on Get User Password After Authentication • 3 months ago

@yokovaski I haven't used Spark. I would think that if your LoginController uses Illuminate\Foundation\Auth\AuthenticatesUsers and it doesn't already implement the authenticated() method, then you should still be okay to implement that method on your LoginController.

Although, see "I haven't used Spark"... so I'm just making things up.

goatshark left a reply on How To Filter And Order Table Rows In Vue 2.x • 3 months ago

@rfountain Here's what I've been doing...

        data: function() {
            return {
                customers: {},
                sortKey: ['customer_name'],
                sortOrder: ['asc'],
            }
        },

        computed: {
            customersSorted: function() {
                return _.orderBy(this.customers, this.sortKey, this.sortOrder);
            },
        },

        methods: {
            fetchCustomers: function() {
                axios.get('/api/customers').then((response) => {
                    this.customers = response.data;
                }).catch(function(error) {
                    console.log(error);
                });
            },
            sortBy: function(key) {
                if (key == this.sortKey) {
                    this.sortOrder = (this.sortOrder == 'asc') ? 'desc' : 'asc';
                } else {
                    this.sortKey = key;
                    this.sortOrder = 'asc';
                }
            },

In my view, I iterate through customersSorted to display the data.

And I use triggers like this in my html in the heading of a table column...

<span class="fa fa-sort" @click="sortBy('customer_name')">

Maybe this helps.

goatshark left a reply on Get User Password After Authentication • 3 months ago

I haven't jumped into the login process for a while, but I think if you add this method from Illuminate\Foundation\Auth\AuthenticatesUsers, it should allow you to splice in there...

    /**
     * The user has been authenticated.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  mixed  $user
     * @return mixed
     */
    protected function authenticated(Request $request, $user)
    {
        //
    }

Is that what you already tried? I would toss a \Log::info($user); in there or something to test.

goatshark left a reply on Get User Password After Authentication • 3 months ago

@Yokovaski I'm not sure how you'd get the plaintext password from a User record. If it has a typical configuration, the entered password will be run through bcrypt() before being written to the db. You could always snag the entered password from the form and keep it until after authentication is successful, but that would involve burning down anything resembling best-practice for storage and handling of a password. Maybe you can mitigate the risks by logging into the remote API as part of your authentication workflow so you can use the password given in the login form instead of trying to use a $user->password property on the logged in user object. Does that make sense?

goatshark left a reply on JSON Handling Change? • 3 months ago

@Apeli This is very strange. I spent several hours yesterday "fixing" a project, in production, that hasn't had any changes to it in months. The symptoms: Responses from my API were being treated as strings instead of objects in Vue!! Seriously, exact same issue.

I started with what you did, JSON.parse(response.data). In the end, I opted for using response.json() instead of JSON.parse(response.data). Maybe they're the same thing.

A few more details: this project is Laravel 5.3 using Vue 1.0.26 and Vue-resource 0.9.3.

I'm still baffled that this scale of error started in a project that hasn't had code changes in months.

9th August, 2017

goatshark left a reply on Code Structure Behind Controller • 3 months ago

@rikw Sounds like a text book example of the use case for Repositories.

https://laracasts.com/search?q=repositories

goatshark left a reply on Filtering Nested Collections • 3 months ago

@swaz Strange. I've got something similar that is working...obviously not similar enough though. :) If you're feeling froggy and want to post the output, maybe there's something small to tweak to get it working.

goatshark left a reply on Filtering Nested Collections • 3 months ago

@tuneless getPercentCompleteAttribute() just returns an integer. It doesn't have anything to do with @swaz's project. It was just an example I pulled from one of my projects.

goatshark left a reply on Filtering Nested Collections • 3 months ago

@swaz I'm not 100% sure I've done this exactly, but if not, I've certainly danced around it.

What about something like this:

Client::with(['schedules' => function($query) {
    return $query->get()->where('some_custom_attribute', '=', 'something');
}])->get();

Also, I haven't tested this, but you might need to have your custom attribute added to the $appends array for that model. I.E. in Schedule::class protected $appends = ['some_custom_attribute'];

goatshark left a reply on Filtering Nested Collections • 3 months ago

Hey @swaz, maybe this will help on the eager loading angle (or maybe this doesn't fit what you're doing at all)....

When I want to eager load with custom attributes, I make sure ->get() is executed on the query before ->with() or ->where(). Like this:

    public function scopeIncomplete($query) {
        return $query->get()->where('percent_complete', '<', 100);
    }

In this example, percent_complete is a custom attribute obtained in the usual way with a getPercentCompleteAttribute() method.

If that fits into what you're doing, perhaps it can get you back on the eager loading path. ?? ymmv

Edit Your Profile
Update

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