chrisgrim

at Self Employed

Member Since 2 Years Ago

Petaluma

Experience Points
37,430
Total
Experience

2,570 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
147
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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.

  • Community Pillar

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

Level 8
37,430 XP
May
05
3 days ago
Activity icon

Started a new Conversation Production.ERROR: Expected Response Code 250 But Got Code "550", With Message "550 Bad HELO - Host Impersonating Domain Name

Hi All, I just updated my server's php and suddenly started getting this error in my Laravel logs.

production.ERROR: Expected response code 250 but got code "550", with message "550 Bad HELO - Host impersonating domain name [everythingimmersive.com]

I looked at my .env and have

MAIL_DRIVER=smtp
MAIL_HOST=arrow.mxrouting.net
MAIL_PORT=465
MAIL_USERNAME=usernamehidden
MAIL_PASSWORD=passwordhidden
MAIL_ENCRYPTION=ssl

[email protected]
MAIL_FROM_NAME=EverythingImmersive

Does anyone know what could cause this?

May
04
4 days ago
Activity icon

Started a new Conversation Vue Axios .catch() Doesn't Stop The Method

Hi, When I do

await axios.post('/materials', this.material)
                .catch(error => {
                    let errors = error.response.data.errors;
                    for (let field of Object.keys(errors)) {
                        alert(errors[field][0], 'error');
                    }
                })
                .then( res => {
                    location.reload();
                });

if I get an error it still continues to the .then() and reloads the page. I even tried to do

await axios.post('/materials', this.material)
                .catch(error => {
                    let errors = error.response.data.errors;
                    for (let field of Object.keys(errors)) {
                        alert(errors[field][0], 'error');
                    }
				return ;
                })
                .then( res => {
                    location.reload();
                });

and it still goes

May
01
1 week ago
Activity icon

Replied to Recommended Video Player /tutorial For Vue

Thanks so much. Sad that he never made the vue video!

Activity icon

Started a new Conversation Recommended Video Player /tutorial For Vue

Hi All, I am looking for the best way to display users shared youtube/vimeo videos. Im guessing I should use iframes but I am looking for any info anyone has. I would prefer to program it myself but I am willing to look into a Vue plugin. Thanks!

Apr
12
3 weeks ago
Activity icon

Replied to User Policy Not Working Like Expected.

Oh I think I see, Is it because there is no user variable so it automatically errors out?

Activity icon

Replied to User Policy Not Working Like Expected.

When I do that it works however when I do

 public function __construct()
    {
        $this->middleware('can:update,user');
    }

it doesn't. Do you know why?

Activity icon

Started a new Conversation User Policy Not Working Like Expected.

Hi, I generated a user policy and added

public function __construct()
    {
        $this->middleware('can:update,user');
    }

to my ProfilesController.php and in my UserPolicy.php I have

<?php

namespace App\Policies;

use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;

class UserPolicy
{
    use HandlesAuthorization;

    /**
     * Determine whether the user can update the model.
     *
     * @param  \App\Models\User  $user
     * @param  \App\Models\User  $model
     * @return mixed
     */
    public function update(User $user, User $model)
    {
        return true;
    }
}

However when I try to go to /users which goes to the controller

public function index(User $user)
    {
        return 'test';
    }

I get a 403 you shouldn't be here which is confusing because I am just saying true in the policy. If I try removing the

$this->middleware('can:update,user');

and do

public function index(User $user)
    {
        return Gate::inspect('update', $user);
    }

it returns

{
"allowed": true,
"message": null,
"code": null
}

so it makes me think the Policy is working. Am I doing something wrong?

Apr
07
1 month ago
Activity icon

Replied to UnsignedDecimal Vs Decimal Database

Thats what I thought, but I wanted to make sure it wasn't going to bite me later on

Activity icon

Started a new Conversation UnsignedDecimal Vs Decimal Database

If I am confident that all of my stored numbers are going to be positive is there any reason not to do an UnsignedDecimal?

Apr
05
1 month ago
Activity icon

Replied to Trying To Setup Simple Validation With Vue And Laravel

I will look into that! Thanks!

Activity icon

Replied to Trying To Setup Simple Validation With Vue And Laravel

Ahh I just needed to add it on the second line as well. Is this the simplest way to write this or is there a shorthand like

v-if="exists.serverErrors.errors.name"

or something

Activity icon

Started a new Conversation Trying To Setup Simple Validation With Vue And Laravel

Hi All, I am trying to setup a quick validation with Vue and Laravel to catch duplicate names. I have it setup like so now

<input
                    type="text" 
                    v-model="title.name" 
                    placeholder=" "
                    :class="{ active: active == 'name','error': $v.title.name.$error }"
                    @input="clearInput"
                    @click="active = 'name'"
                    @blur="active = 'null'">
                <div v-if="serverErrors " class="validation-error">
                    <p class="error" v-if="serverErrors.errors.name">An event with this name already exists. </p>
                </div>


async onSubmit(value) {
                if ( this.checkForChanges(value) ) { return this.onForward(value) }
                if ( this.checkVuelidate() ) { return }
                await axios.patch( this.endpoint, this.title )
                .catch( error => {
                    console.log(error.response.data);
                    this.serverErrors = error.response.data;
                })
            },

            clearInput() {
                this.serverErrors = {};
            },

This works but I am getting an error when clearInput fires

"TypeError: Cannot read property 'name' of undefined"

I know this is because I have made server errors an empty object where it used to have

serverErrors
	errors
		name:duplicate name

What is the cleanest way to check for this without the error throwing?

Activity icon

Awarded Best Reply on Route Url For Updating Team Name In Laravel 8

Nm I just generated my own route! Sorry!

Activity icon

Replied to Route Url For Updating Team Name In Laravel 8

Nm I just generated my own route! Sorry!

Activity icon

Started a new Conversation Route Url For Updating Team Name In Laravel 8

Hi, I was trying to find the url to update a team name in Laravel 8. I am trying to look in vendor/laravel/jetstream/routes/livewire but the only input I see is

Route::put('/current-team', [CurrentTeamController::class, 'update'])->name('current-team.update');

which leads to this

public function update(Request $request)
    {
        $team = Jetstream::newTeamModel()->findOrFail($request->team_id);

        if (! $request->user()->switchTeam($team)) {
            abort(403);
        }

        return redirect(config('fortify.home'), 303);
    }

which I can't see how it updates the team.

Mar
29
1 month ago
Activity icon

Awarded Best Reply on Can't Understand Why Computed Property Isn't Working

I realize I needed to use a method to do this. Computed properties only exists for individual items like @tykus said.

 <p 
                        class="r-5" 
                        v-for="(price, index) in individualPriceList(material)"
                        :key="price.id">
                        ${{ price.price }}
                    </p>

individualPriceList(material) {
                if (this.priceColumns === 'single') { return new Array(material.prices[0]); }
                if (this.priceColumns === 'double') { return new Array(material.prices[0]); }
                if (this.priceColumns === 'half') { return material.prices.slice(0,12); }
                if (this.priceColumns === 'full') { return material.prices; }
            },

Activity icon

Replied to Can't Understand Why Computed Property Isn't Working

I realize I needed to use a method to do this. Computed properties only exists for individual items like @tykus said.

 <p 
                        class="r-5" 
                        v-for="(price, index) in individualPriceList(material)"
                        :key="price.id">
                        ${{ price.price }}
                    </p>

individualPriceList(material) {
                if (this.priceColumns === 'single') { return new Array(material.prices[0]); }
                if (this.priceColumns === 'double') { return new Array(material.prices[0]); }
                if (this.priceColumns === 'half') { return material.prices.slice(0,12); }
                if (this.priceColumns === 'full') { return material.prices; }
            },

Activity icon

Replied to Can't Understand Why Computed Property Isn't Working

I suppose I could but do you know why this wouldn't work?

Activity icon

Replied to Can't Understand Why Computed Property Isn't Working

the eventual goal is to do something like

individualPriceList() {
if (this.priceColumns === 'currentDate') { return material.prices[0]; }
if (this.priceColumns === 'yearOut') { return material.prices[13]; }
}
Activity icon

Started a new Conversation Can't Understand Why Computed Property Isn't Working

Hi, I have a bunch of materials that each have a bunch of prices. I have this which is working

<div 
            class="row" 
            v-for="(material, index) in materials"
            :key="material.SKU">
	<p 
          class="r-5" 
          v-for="(price, index) in material.prices"
         :key="price.id">
        {{price}}
      </p>

</div>

However when I try to do

<div 
            class="row" 
            v-for="(material, index) in materials"
            :key="material.SKU">
	<p 
          class="r-5" 
          v-for="(price, index) in individualPriceList"
         :key="price.id">
         {{price}}
      </p>
</div>



computed: {

            individualPriceList() {
                return material => material.prices
            }
        },


nothing shows up.

Mar
25
1 month ago
Activity icon

Replied to Storing Decimal Numbers To Database

@martinbean I seeeee. Ok that makes sense now. Thanks so much

Activity icon

Replied to Storing Decimal Numbers To Database

@jlrdw Sorry? If I enter 12 I get the error Numeric value out of range: 1264 Out of range value for column 'product_weight'. I assumed Mysql would handle it like you said but it is erroring out.

Activity icon

Replied to Storing Decimal Numbers To Database

Ok I see that the first 6 is the precision and second 6 is the scale. Does that mean I would have to store 12.0000?

Activity icon

Started a new Conversation Storing Decimal Numbers To Database

Hi, In my migration table I have

$table->decimal('product_weight', 6, 6)->nullable();

And when I try to store a number like 0.02645547146218531 it works fine storing it as 0.026455 however when I try to save a number like 12.00 I get the error

Numeric value out of range: 1264 Out of range value for column 'product_weight' at row 1 (SQL: update `boms` set `product_weight` = 12.00, `weight_type` = pounds, `boms`.`updated_at` = 2021-03-25 17:52:55 where `id` = 1)"

I thought the first 6 was before the decimal and the second 6 was for after the decimal?

Mar
23
1 month ago
Activity icon

Replied to Computed Value Not Returning Correctly

This helped me so much!! Thank you

Mar
22
1 month ago
Activity icon

Replied to Computed Value Not Returning Correctly

I guess I am a little confused. So would I just use a method and not a computed?

Activity icon

Replied to Computed Value Not Returning Correctly

@tykus if I do

<div 
                        class="row" 
                        v-for="(material, index) in recipe.materials"
                        :key="material.SKU">
                        {{test(material)}}      
                    </div>


computed: {
            test() {
                return material => material.SKU
            }
        },

it will return the SKU for each material

Activity icon

Started a new Conversation Computed Value Not Returning Correctly

Hi, I am using a computed value to return the price of the model that falls within the current date. Here is my code

<div 
                        class="row" 
                        v-for="(material, index) in recipe.materials"
                        :key="material.SKU">            
                        <p> {{currentMonth(material)}} </p>
                    </div>


computed: {
            currentMonth() {
                return material => this.currentMonthPrice(material);
            }
        },

methods: {
currentMonthPrice(material) {
                material.prices.forEach(function(price) {
                    let date = new Date();
                    let priceDate = new Date(price.month);
                    var thisMonth = new Date(date.setMonth(date.getMonth() ));
                    var lastMonth = new Date(date.setMonth(date.getMonth() -1));
                    if (priceDate > lastMonth && priceDate < thisMonth) {
                        return price.price
                    }
                });
            },

I know I should be using .map() and can clean the code a lot but I am just trying to get it working. If I console.log the price.price then I do see the price for the current month but it doesn't output the current price to my template.

Mar
18
1 month ago
Activity icon

Started a new Conversation Need Help With Complicated Calculation

Hi, I am getting stuck with a complicated calculation. I have a material list array with multiple materials. Each material has a pivot with a percentage and a list of prices by month. The calculation I need to do is to first multiply each price in each material list by the percentage. So for the first material price1 would be 3.9 and price3 would be 5.1. Then I need to add up all the march 1st prices to get a total and so on. So the first value would be 3.9 (13*.3) + 2 (10 * .2) = 5.9 and so on.

material list:
    material1 
        pivots:
            percentage: 30
        prices:
            price1
                13.00
                march 1st
            price2
                13.00
                april 1st
            price3
                17.00
                may 1st
            price4
                11.00
                june 1st
            price5
                19.00
                july 1st
    material2:
        pivots:
            percentages: 20
        prices:
            price1
                10.00
                march 1st
            price2
                10.00
                april 1st
            price3
                13.00
                may 1st
            price4
                11.00
                june 1st
            price5
                10.00
                july 1st

I have tried to do

        computed: {
            totals() {
                return this.materialList.forEach(mat => mat.prices.map(price => price.price * how do I get the material.pivot.percentage into here? ));
            }
        },

but I am having trouble getting values where I need them.

Activity icon

Started a new Conversation Add Values From Multiple Arrays

I am sure this is easy but I am having trouble thinking it through. If I have

[1, 4, 6]
[2, 6, 6]
[3,  4, 5 ]

how would I get the values of each column added. So the result would be

[6, 14, 17]

Thanks

Mar
17
1 month ago
Activity icon

Replied to Question Setting Up A Database

Ahh That is genius! Thanks @tykus

Activity icon

Replied to Question Setting Up A Database

*this (Note also, the $material instance will only have a pivot property whenever loaded as a relationship of the Recipe;) is my issue.

Is there a way to get the pivot information with just a material instance or do I have to do :

$recipe->materials->fresh();
Activity icon

Replied to Question Setting Up A Database

@tykus

Thanks for helping clean up the code! When I do my axios patch I am sending this

SKU: "SXZ"
company_id: 1
created_at: "2021-03-17T21:37:46.000000Z"
id: 1
name: "Almond"
pivot: Object
    material_id: 1
    percentage: "1.00"
    recipe_id: 1
prices: Array(12)
    0: {…}
    1: {…}
    2: {…}
    3: {…}
    4: {…}
    5: {…}
    6: {…}
    7: {…}
    8: {…}
    9: {…}
    10: {…}
    11: {…}
supplier_id: 1
type: "ingredient"
updated_at: "2021-03-17T21:37:46.000000Z"
user_id: 1

and then when I am doing the return $material after changing the percentage I get this back

SKU: "SXZ"
company_id: 1
created_at: "2021-03-17T21:37:46.000000Z"
id: 1
name: "Almond"
supplier_id: 1
type: "ingredient"
updated_at: "2021-03-17T21:37:46.000000Z"
user_id: 1
Activity icon

Replied to Question Setting Up A Database

@tykus I have a quick question

I added the withPivot to the materials belongs to many on the Recipe.php.

/**
     * Each recipe belongsToMany Materials
     *
     * @return \Illuminate\Database\Eloquent\Relations\belongsToMany
     */
    public function materials()
    {
        return $this->belongsToMany(Material::class)->withPivot('percentage');
    }

This works when I do

$materials = $recipe->materials->load('prices');

It includes a pivot table with the two pivots and the percentage. However when just have one of the materials

public function updatePercentage(Request $request, Material $material, Recipe $recipe)
    {
        Recipe::find($recipe->id)->materials()->updateExistingPivot($recipe->id,['percentage' => $request->pivot['percentage'] ]);
        return $material;
    }

when I try to do

return $material->pivot->percentage;

I get the error

"Trying to get property 'percentage' of non-object"
Activity icon

Replied to Question Setting Up A Database

Wow!! This is why I love this forum. You guys rocks.

Activity icon

Started a new Conversation Question Setting Up A Database

Hi, I have two models, a recipe.php and a materials.php. I have them both currently as belongsToMany with each other and the database is setup like

Schema::create('recipes', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('SKU');
            $table->string('description');
            $table->foreignId('company_id');
            $table->foreignId('user_id');
            $table->timestamps();
        });

Schema::create('materials', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('SKU');
            $table->string('type');
            $table->foreignId('user_id');
            $table->foreignId('company_id');
            $table->foreignId('supplier_id')->nullable();
            $table->timestamps();
        });

        Schema::create('material_recipe', function(Blueprint $table) {
            $table->foreignId('material_id');
            $table->foreignId('recipe_id');
            $table->timestamps();
        });

Im doing it this way because I want materials to be able to be used between multiple recipes. However I need to setup a way to do percentages of each material per recipe. Since I am not generating a new material for each recipe I can't add the percentage column to the material model. I am assuming that I need to make a new model called percentages that would look something like

Schema::create('percentages', function(Blueprint $table) {
			$table->id();
            $table->foreignId('material_id');
            $table->foreignId('recipe_id');
			$table-> decimal('percentage');
            $table->timestamps();
        });

However I am having trouble figuring out how to easily append it. Preferably when I do

$recipe->materials()->get()

it would somehow append the percentage to each of the materials for that recipe. I could do a .filter in vue to do this but I would prefer to do this in the backend.

Thanks!

Activity icon

Replied to Returning A Model After Update Still Shows Old Values

That worked great @michaloravec !!! Thanks

return $price->material->prices->fresh();
Activity icon

Started a new Conversation Returning A Model After Update Still Shows Old Values

Hi, When I update a record and then try to return the values right away I am seeing that it is the old record.

public function update(Request $request, Price $price)
    {
        $material = $price->material->prices->filter(function ($value) use ($price) {
            return $value->id >= $price->id;
        });
        $prices = $material->pluck('id');
        Price::whereIn('id', $prices)->update([
            'price' => $request->price
        ]);
        return $price->material->prices;
    }

it returns my old prices. However when I then reload the page it has the latest prices. Do I need to tell laravel to wait until the record is updated before doing?

return $price->material->prices;
Mar
16
1 month ago
Activity icon

Replied to How To Update A Collection With A Request That Has Full Collection As Array

Gotcha, ok I will create an endpoint to update the prices specifically. Thanks!

Activity icon

Started a new Conversation How To Update A Collection With A Request That Has Full Collection As Array

Hi, Sorry if my title is a bit confusing. I have a Material.php record

SKU: "DFAS"
company_id: 2
created_at: "2021-03-16T03:33:54.000000Z"
id: 6
name: "Almond"
prices: Array(12)
0: {id: 37, material_id: 6, price: "4.45", month: "2021-04-01 00:00:00", created_at: "2021-03-16T03:33:54.000000Z", …}
1: {id: 38, material_id: 6, price: "4.45", month: "2021-05-01 00:00:00", created_at: "2021-03-16T03:33:54.000000Z", …}
2: {id: 39, material_id: 6, price: "4.45", month: "2021-06-01 00:00:00", created_at: "2021-03-16T03:33:54.000000Z", …}
3: {id: 40, material_id: 6, price: "4.45", month: "2021-07-01 00:00:00", created_at: "2021-03-16T03:33:54.000000Z", …}
4: {id: 41, material_id: 6, price: "4.45", month: "2021-08-01 00:00:00", created_at: "2021-03-16T03:33:54.000000Z", …}
5: {id: 42, material_id: 6, price: "4.45", month: "2021-09-01 00:00:00", created_at: "2021-03-16T03:33:54.000000Z", …}
6: {id: 43, material_id: 6, price: "4.45", month: "2021-10-01 00:00:00", created_at: "2021-03-16T03:33:54.000000Z", …}
7: {id: 44, material_id: 6, price: "4.45", month: "2021-11-01 00:00:00", created_at: "2021-03-16T03:33:54.000000Z", …}
8: {id: 45, material_id: 6, price: "4.45", month: "2021-12-01 00:00:00", created_at: "2021-03-16T03:33:54.000000Z", …}
9: {id: 46, material_id: 6, price: "4.45", month: "2022-01-01 00:00:00", created_at: "2021-03-16T03:33:54.000000Z", …}
10: {id: 47, material_id: 6, price: "4.45", month: "2022-02-01 00:00:00", created_at: "2021-03-16T03:33:54.000000Z", …}
11: {id: 48, material_id: 6, price: "4.45", month: "2022-03-01 00:00:00", created_at: "2021-03-16T03:33:54.000000Z", …}
length: 12
__proto__: Array(0)
supplier_id: 10
type: "ingredient"
updated_at: "2021-03-16T03:33:54.000000Z"
user_id: 2

and in vue I change one of the prices of one of the months to 4.30 and then I do an axios call with the updated record

SKU: "DFAS"
company_id: 2
created_at: "2021-03-16T03:33:54.000000Z"
id: 6
name: "Almond"
pivot: {recipe_id: 2, material_id: 6}
prices: Array(12)
0: {id: 37, material_id: 6, price: "4.30", month: "2021-04-01 00:00:00", created_at: "2021-03-16T03:33:54.000000Z", …}
1: {id: 38, material_id: 6, price: "4.45", month: "2021-05-01 00:00:00", created_at: "2021-03-16T03:33:54.000000Z", …}
2: {id: 39, material_id: 6, price: "4.45", month: "2021-06-01 00:00:00", created_at: "2021-03-16T03:33:54.000000Z", …}
3: {id: 40, material_id: 6, price: "4.45", month: "2021-07-01 00:00:00", created_at: "2021-03-16T03:33:54.000000Z", …}
4: {id: 41, material_id: 6, price: "4.45", month: "2021-08-01 00:00:00", created_at: "2021-03-16T03:33:54.000000Z", …}
5: {id: 42, material_id: 6, price: "4.45", month: "2021-09-01 00:00:00", created_at: "2021-03-16T03:33:54.000000Z", …}
6: {id: 43, material_id: 6, price: "4.45", month: "2021-10-01 00:00:00", created_at: "2021-03-16T03:33:54.000000Z", …}
7: {id: 44, material_id: 6, price: "4.45", month: "2021-11-01 00:00:00", created_at: "2021-03-16T03:33:54.000000Z", …}
8: {id: 45, material_id: 6, price: "4.45", month: "2021-12-01 00:00:00", created_at: "2021-03-16T03:33:54.000000Z", …}
9: {id: 46, material_id: 6, price: "4.45", month: "2022-01-01 00:00:00", created_at: "2021-03-16T03:33:54.000000Z", …}
10: {id: 47, material_id: 6, price: "4.45", month: "2022-02-01 00:00:00", created_at: "2021-03-16T03:33:54.000000Z", …}
11: {id: 48, material_id: 6, price: "4.45", month: "2022-03-01 00:00:00", created_at: "2021-03-16T03:33:54.000000Z", …}
length: 12
__proto__: Array(0)
supplier_id: 10
type: "ingredient"
updated_at: "2021-03-16T03:33:54.000000Z"
user_id: 2

Is there an easy way in my controller to replace all the entire record? Something like

return $material->load('prices')->update($request)

This gives me the error Model::update() must be of the type array, object given

Mar
09
1 month ago
Activity icon

Awarded Best Reply on Put Model In Custom Folder And Getting Error: Failed To Open Stream: No Such File Or Directory"

I figured it out. If the model isn't in the same namespace I need to add it to my Event.php

use App\Models\Events\EventRequest;
Activity icon

Replied to Put Model In Custom Folder And Getting Error: Failed To Open Stream: No Such File Or Directory"

I figured it out. If the model isn't in the same namespace I need to add it to my Event.php

use App\Models\Events\EventRequest;
Activity icon

Started a new Conversation Put Model In Custom Folder And Getting Error: Failed To Open Stream: No Such File Or Directory"

Hi, I am setting up my relationship between my events and eventrequests models like so

/**
     * Each event has many event requests
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function eventRequest() 
    {
        return $this->hasMany(EventRequest::class);
    }

The issue is my event model is in the folder app/models while my EventRequest model is in the folder app/models/events/ Inside my actual EventRequest.php file I do have the correct namespace

namespace App\Models\Events;

however when I try to do

$event->eventRequest()->create([
            'request' => 'test'
        ]);

I get the error

"include(/Users/cgrim/code/ei/vendor/composer/../../app/Models/EventRequest.php): failed to open stream: No such file or directory
Feb
22
2 months ago
Activity icon

Replied to Typing Too Fast For Search Axios Calls

Gotcha! Thanks so much!

Activity icon

Started a new Conversation Typing Too Fast For Search Axios Calls

Hi, I was having a strange issue which I think I just figured out and I am looking for how other developers deal with it. I have a search bar which does an axios call to my laravel backend to do an elastic search.

<v-select
            v-model="searchBoxInput"
            label="searchBoxInput.model"
            :placeholder="placeholder"
            :options="searchBoxOptions"
            :filterable="false"
            :get-option-label="searchBoxInput => searchBoxInput.model.name"
            :reduce="searchBoxInput => searchBoxInput.model"
            @search="generateSearchList" 
            @search:focus="generateSearchList" 
            @input="searchInput" />
...


async generateSearchList (query) {
			console.log(query);
            await axios.get('/api/search/navbar', { params: { keywords: query } })
            .then( res => {
				console.log(res.data[0].model.name);
                this.searchBoxOptions = res.data;
            })
        },

I have it do an axios call everytime the user types so it provides a type ahead type feature. The issue I am running into is if a user types too fast it will overwrite the final search with the search just before. Here is what happens if they type in slowly

query: m
returned 1st result: To My Distant Love
query: mi
returned 1st result: The Missing
query: mis
returned 1st result: The Missing
query: mist
returned 1st result: Into The Mist

and here is what happens when they type in quickly. As you can see the final returned result is actually incorrect!

query:m
query:mi
returned 1st result: To My Distant Love
query:mis
query:mist
returned 1st result: The Missing
returned 1st result: Into The Mist
returned 1st result: The Missing

What are your solutions for fast typers?

Feb
11
2 months ago
Activity icon

Replied to Event Tracking With Ref Not Working With Child Component

I just tested it out on my side and the issue seemed to be v-if statements. Here is the code I was calling in the child component

<template>
    <p class="text">
        <span :style="`white-space: ${whiteSpace};`">{{ adjustedText }}</span>
        <span 
            v-if="showMore" 
            @click="showMore = false">... <span class="show-text"><br>Show More</span>
        </span>
        <span 
            v-if="lessButton && !showMore && this.text.split(' ').length >= this.limit"
            @click="showMore = true"><span class="show-text"><br>Show Less</span>
        </span>
    </p>
</template>

<script>

export default {

    props : {
        text: {
            type: String,
            default: ''
        },
        limit : {
            type: Number,
            default: 100,
        }, 
        whiteSpace: {
            type: String,
            default: 'pre-wrap'
        },
        lessButton: {
            type: Boolean,
            default: true
        }
    },

    computed: {
        adjustedText() {
            // return this.text.length >= this.limit && this.showMore ? this.text.substring(0, this.limit) : this.text
            return this.text.split(' ').length > this.limit && this.showMore ?  this.text.split(' ').slice(0, this.limit).join(' ') : this.text
        },
    },

    data() {
        return {
            showMore: this.text.split(' ').length >= this.limit ? true : false,
        }
    },
}
    
</script>

once I changed the v-ifs to v-show it stopped closing my window.

Activity icon

Replied to Event Tracking With Ref Not Working With Child Component

Sorry I got swamped with work. I am on it today!

Feb
08
3 months ago
Activity icon

Replied to Event Tracking With Ref Not Working With Child Component

Let me clean my code up and I will post it here. Though it is very helpful just to know that it worked for you clicking a child element.