spacedog4

spacedog4

Member Since 1 Year Ago

Umuarama - PR, Brazil

Experience Points
56,330
Total
Experience

3,670 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
526
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    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 Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 12
56,330 XP
Oct
10
1 month ago
Activity icon

Started a new Conversation Eager Load Conditional In Polymorphic Relationship

Maybe there is a way to put a conditional on

$feeds = \App\Activityfeed::with('feedable.product', 'feedable.business')->get();

So that when feedable_type = App\Event it eager loads feedable.business and when feedable_type = App\Rating it eager loads feedable.product?

Activity icon

Started a new Conversation Return "with" Only In This Case

I have an Activity model that have a subject polymorphic relationship, so it can be Production model, Productionstep model, so on

I want if i call Activity::first()->subject and it returns the Production model with some relationshipis, I don't want to add the $with property to the model to prevent eager loading it in unnecessary places

Is there a way to do this?

Activity icon

Replied to Create A New Primary Column In Production

If you still can edit your answer, could you alter to this?

CREATE TABLE some_table_temp LIKE some_table;
INSERT some_table_temp SELECT * FROM some_table;
ALTER TABLE some_table_temp ADD id INT NULL FIRST;

SET FOREIGN_KEY_CHECKS = 0;

DROP TABLE some_table;

CREATE TABLE some_table (
    id NOT NULL AUTO_INCREMENT,
    field1 varchar(255),
    field2 varchar(255),
    PRIMARY KEY (id)
);

INSERT INTO some_table SELECT * FROM some_table_temp;

DROP some_table_temp;

SET FOREIGN_KEY_CHECKS = 1;
Activity icon

Replied to Create A New Primary Column In Production

@tray2 solved, I need to move the id column to first

ALTER TABLE pedidoproducaoetapas_temp ADD id INT NULL FIRST;

Activity icon

Replied to Create A New Primary Column In Production

@tray2 I fixed the previus issue adding an id null column

ALTER TABLE pedidoproducaoetapas_temp ADD id INT NULL;

but now I got this new one

Data truncation: Out of range value for column 'codigoempresa' at row 1

notice, I have 25321 records

Activity icon

Replied to Create A New Primary Column In Production

@tray2 I'm almost there, but in the line INSERT INTO some_table SELECT * FROM some_table_temp i got this error Column count doesn't match value count at row 1

I think that might be because the new table as a extra column

Activity icon

Replied to MorthTo With Multiple Columns

@johnbraun I rewrited my question, take a look and see if it is clearly.

English is not my native language so it can be confusing

Activity icon

Replied to Create A New Primary Column In Production

@itsfg I tryied that, I think it should work, but caused this error General error: 1025 Error on rename of './gestor/#sql-1_1943f2' to './gestor/pedidoproducao' (errno: 150 - Foreign key constraint is incorrectly formed)

Activity icon

Replied to Create A New Primary Column In Production

@tray2 Can I do that to only a table? Not the entire database?

Activity icon

Replied to Create A New Primary Column In Production

I can do that, but can you think an a fast way to do that? Cause I will do it in at least 3 tables, in 11 databases.

I'm not asking for the actual code, but where I would do that? Creating a command?

Activity icon

Started a new Conversation MorthTo With Multiple Columns

I have an Activity and other models that have a polymorphic relationship with Activity. The models are in portugue, so I'l translate irProduction, Productionsteps, Productionissues

One Production can ha many activities, same as Productionsteps and Productionissues and Activity can have many productions, productionsteps and productionissues.

So I need a polymorphic relationship, the problem is each Model has not only one primary key, but a group of primary keys:

Production has a primary key formed by ('key_company', 'key_branch', 'key_production')

Productionsteps has a primary key formed by ('key_company', 'key_branch', 'key_production', 'key_productionstep)

Productionissues has a primary key formed by ('key_company', 'key_branch', 'key_production', 'key_productionissue)

So how can I create a polymorphic relation ship with these models if the method as for only one key?

Activity icon

Replied to Create A New Primary Column In Production

Yes, exacly

$table->primary([
    'codigoempresa',
    'codigofilial',
    'codigopedidoproducao',
], 'pk_pedidoproducao');
Activity icon

Started a new Conversation Create A New Primary Column In Production

Today I have this table where has 3 columns setted as primary, this is causing me so much trouble, how can I create a migration to drop the primary index and create a new increments id column without erasing all data?

I tryied this:

$table->dropPrimary('PRIMARY');
$table->increments('id');

but I got this error Illuminate\Database\QueryException : SQLSTATE[HY000]: General error: 1 Cannot add a PRIMARY KEY column (SQL: alter table "pedidoproducao" add column "id" integer not null primary key autoincrement)

I need it to be a migration cause our webapp has multiples database, so I need to update all of then

Oct
08
1 month ago
Activity icon

Replied to Factory With Relationships

I'm so used to laravel that I forgot I can create a class by my self, thank you, helped me a lot

Activity icon

Started a new Conversation Factory With Relationships

I saw one time @JeffreyWay writing a test like this

factory(DummyModel::class)->withDummyRelationShip();

How does that work? Or wasn't like that?

What I need is to generates a model with a relationship, example:

factory(Production::class)->withSteps(3);

// or it can be
$this->generatesProduction()->withSteps(3);

NOTICE I know that I can create a method on the model, withSteps, but this is only for testing, It doesn't look right

Activity icon

Replied to SoftDelete On Polymorphic Relationships

I'm not, I followed a Jeffreys' tutorial, I didn't know that package exists, but I figure out how to do that this way:

$morth = $this->morphTo();

try {
    return $morth->withTrashed();
} catch (\Exception $e) {
    return $morth;
}
Oct
07
1 month ago
Activity icon

Replied to SoftDelete On Polymorphic Relationships

The problem is that I can't get the morth's model, I have only the query builder

Oct
03
1 month ago
Activity icon

Replied to Can't Find The Lesson Where He Store In The Activity Feed What Has Been Updated

@jeffreyway perfect, also gave me a few more lessons about activity that I was looking for

Activity icon

Started a new Conversation SoftDelete On Polymorphic Relationships

I'm building a activity feed in my project, but I also want to record delete activity, the problem is, to do this, I need to use softDelete in some models, in others I don't want to, so how do I user "withTrashed" in a polymorthic relationship where sometimes it can be trashed and in other can't

In laravel docs, i saw that I can use the method "trashed" to check if the model is using softDelete, but when I do it in the with method I got this error: call to undefined method Illuminate\Database\Eloquent\Builder::trashed()

Here is what i'm doing now and not working

        return Activity::with([
            'subject' => function ($query) {
                if ($query->trashed()) {
                    return $query->withTrashed();
                }

                return $query;
            },
            'usuario'
        ])->latest()->take(50)->get()->groupBy(function ($activity) {
            return $activity->created_at->format('d/m/Y');
        });
Activity icon

Started a new Conversation Can't Find The Lesson Where He Store In The Activity Feed What Has Been Updated

I found these episodes https://laracasts.com/series/lets-build-a-forum-with-laravel/episodes/25 where he teachs how to create a activity feed and display it, I remember seeing once he doing the same thing but also storing a previous version of the model and showing what have been changed

Activity icon

Commented on The Activity Deletion Bug

What about when I want to record activity for deleting the thread?

Oct
02
1 month ago
Activity icon

Started a new Conversation Unexpected Error With Sync Method In Test Environment

Laravel 5.8.34

we have 3 tables, roles, permissions and the pivot table role_permission that does not have an ID

this line of code works well in the browser

// Role.php
$this->permissions()->sync($permission);

but in my test environment I get this error where he tries to put the permissions fields in my pivot table

Unknown column 'id' in 'field list' (SQL: insert into `role_permission` (`created_at`, `id`, `label`, `name`, `permission_id`, `role_id`, `updated_at`) values (?, 2, ?, cadastrar_pessoa, 0, 1, ?))

id, label and name are from the permissions table

My test database is mysql as well my dev

A way around

I can solve that error in test doing this

// Role.php

$permission = Permission::select('id as permission_id')->whereIn('name', $permission)->get();

return $this->permissions()->sync($permission);

but I don't want to do this in all my tests

Sep
30
1 month ago
Activity icon

Replied to Where Is That Lesson That Teachs How To Use Laravel Roles And Permissions In Vue

Wasn't this one, but it helped me a lot, thank you

Sep
28
1 month ago
Activity icon

Started a new Conversation Where Is That Lesson That Teachs How To Use Laravel Roles And Permissions In Vue

I saw once and can't find it again, fi someone has the link, please send me

Sep
16
2 months ago
Activity icon

Replied to Overwrite Magic _get Method For A Custom Request Class

Hey @slev1n thanks for your reply, worked for me, I'll explain what I'm doing, sorry if it becomes hard to understand, english is not my native language

In my API i can pass a json to export multiple data (in this case a person) and inside each person in the json can have multiples relations, addresses, users, etc... So I need to extract each person of the json, test if this person already exists or not (so I need to update or create a new one), and create a new request based on that person data retrieved from the request, so I can use the same create method from the PersonsController to create a new person, address, etc, if I pass the normal request() don't work

So I have a PersonRequest class, I instantiate it with the data from the request, It was working perfect in my tests, $new_request->key returned the correct data, but for requests with a content-type of application/json works differently, it doesn't look for the key in $resquest->request->key it gets from $request->json->key and I don't know how to overwrite this json data

Activity icon

Started a new Conversation Overwrite Magic _get Method For A Custom Request Class

I have a custom request class PersonRequest where I use for an exporting project where I manipulate the original request and create new ones, I need to overwrite the default magic get method for Request

I can call $request->get($key) and I already overwrited that method in my PersonRequest, but:

How do I overwrite $request->key?

Sep
05
2 months ago
Activity icon

Commented on Ignition Is Laravel's Amazing New Error Page

That's a reaaaally wonderful improve

Sep
02
2 months ago
Activity icon

Commented on Explain How A Facade Works Under The Hood

I would like to know what is that PizzaController hahaha

Aug
22
2 months ago
Activity icon

Commented on Reduce A Query From 12 Seconds To 1 Millisecond

I started search for it after have a page that took 30 seconds to load

Aug
21
2 months ago
Activity icon

Started a new Conversation Pass Props To A Programmatically Component

I'm making a sidebar that can have dynamic content, using vuex

So, for exaple, I have this app with a Sidebar.vue that can loads a DynamicContent.vue, how do I pass a prop to that DynamicContent.vue inside

app.js

import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

import store from './store'
import Sidebar from './components/Sidebar'
import DynamicContent from './components/DynamicContent.vue'

Vue.component('sidebar', Sidebar)

const app = new Vue({
    el: '#app',
    store,
    
    data() {
        return {
            dynamicContent: DynamicContent
        }
    },

    methods: {
        toggleSidebar() {
            this.$store.commit('toggleSidebar', dynamicContent)
        }
    }
})

Sidebar.vue

Notice: I can't pass my props throught that component tag cause the components can have differents props

<template>
    <div>
        <component :is="component" />
    </div>
</template>

<script>
    export default {
        computed: {
            component() {
                return this.$store.state.sidebarComponent
            }
        }
    }
</script>

store.js

import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        sidebarOpen: false,
        sidebarComponent: null
    },

    mutations: {
        toggleSidebar(state, component) {
                state.sidebarOpen = ! state.sidebarOpen
        state.sidebarComponent = component
        },
    }
})
Aug
16
3 months ago
Activity icon

Replied to Bug Saying That I Already Completed The Series When I Don't

Really? If it is true, I don't think is a good choice, cause to see if has new episodes to watch I go to the "Series" page and at the section of "Recently Updated" and look for a serie that isn't completed, in this case, MySQL Database Design" was completed

Activity icon

Started a new Conversation Bug Saying That I Already Completed The Series When I Don't

I watched all the episodes from MySQL Database Design, completed, but when you realesed news episodes it confused me cause it was still saying that I has completed 100% the series

http://prntscr.com/otmzko

Aug
14
3 months ago
Activity icon

Commented on Filtering Aggregated Data

If I use limit, the "having" will be affected?

Aug
12
3 months ago
Activity icon

Commented on Series Chapters

Love that course, it is a patch note integrated with a lesson

Activity icon

Started a new Conversation How Do I Create A New Request Overwriting Json()->all()

I'm developing an exporter, when I'm exporting data to an table I pass all the data trought post, inside a records parameter and the server discover if it needs to update or create a new row.

{
    "records" => "[{\"foo\":\"bar\"}]"
}

I get this records parameter and create another Request cause inside it can have child relationships, so I create another request to pass trought the validation.

$created_request = new NewRequest(
    [], // query
    ["foo" => "bar"], // request
    [] // attributes
);

The problem is, if I make a normal request, when I call $created_request->all() it will return me ["foo" => "bar"], correct, but if I make a json request, it will return me the old data "records" => "[{\"foo\":\"bar\"}]"

Basic, doing my research, I discovered that in a normal request, $created_request->all() will return $created_request->query->all() and $created_request->request->all(), on the other hand in a json request, $created_request->all() will return $created_request->json()->all() that always return the old data, how do I create a new request overwriting json()->all()

Jun
03
5 months ago
Activity icon

Started a new Conversation How To Use Laravel Echo And Pusher In Laravel 5.8 With API Authentication

I'm trying to build a real-time chat app, but I'm having problem with laravel echo in vue js

This chat needs an api authentication, so in my broadcast it need to

this next code is in my main app.js file

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: process.env.MIX_PUSHER_APP_KEY,
    cluster: process.env.MIX_PUSHER_APP_CLUSTER,
    logToConsole: true,
    encrypted: true,
    auth: {
        headers: {
            Authorization: `Bearer TOKEN`
        },
    },
    authEndpoint: "/api/broadcasting/auth",
})

How can I get this Beare Token (that I pass on the URL) and use it in my app.js file, dinamyc since It could be any user