Ifrit

Member Since 5 Years Ago

Experience Points
7,320
Total
Experience

2,680 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
0
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 2
7,320 XP
Apr
21
2 days ago
Activity icon

Replied to Password Confirmation

What I'm trying to do is make sure that the password they typed is the same password in the database. That was why I'm using confirmed in the validation.

Is there another way to do it?

Activity icon

Started a new Conversation Password Confirmation

I've created a page that will allow a user to edit their profile data and before they can make a change they need to enter their password.

The problem I'm having is that when I enter the correct password I'm getting the The password does not match error

Here is my code

Profile.vue

<template>
    <div>
        <div class="card">
            <div class="card-body">
                <div class="form-group">
                    <label>Name</label>
                    <input type="text" class="form-control" v-model="name">
                </div>

                <div class="form-group">
                    <label>Password</label>
                    <input type="password" class="form-control" v-model="password">
                    <div v-if="passwordExists">
                        {{  passwordError  }}
                    </div>
                </div>

                <div class="form-group">
                    <button class="btn btn-success float-right" @click="update">Save</button>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        props: ['user'],
        data(){
            return {
                name: this.user.name,
                password: null,
                passwordExists: false,
                passwordError: ''
            }
        },
        methods: {
            update(){
                axios.post(`/api/profile/${this.user.id}/profile-update`, {
                    name: this.name,
                    password: this.password
                }).then(response => {
                    if (response.data.errors) {
                        this.passwordExists = true;
                        this.passwordError = response.data.passwordError;
                    } else {
                        this.passwordExists = false;
                    }
                })
            },
        },
        mounted(){

        }
    }
</script>

My [email protected]

$validation = Validator::make(request()->all(), [
            'password' => 'required|confirmed'
        ]);

if($validation->fails()){

    $errors = $validation->errors();

    return [
        'errors' => true,
        'passwordError' => $errors->first('password')
    ];
}
Mar
31
3 weeks ago
Activity icon

Replied to Getting The Selected Value

I've changed

<option {{p.id== selectedId ? 'selected'}}

to

<option v-for="p in product.children" :value="p.id" :selected="p.id === selectedId ? 'selected' : ''">{{ p.text }}</option>

but my dropdown didn't selected the correct option

Activity icon

Replied to Getting The Selected Value

I've tried that and I'm getting this error

Cannot read property 'text' of null

and my phpstorm is complaining about

<option {{p.id== selectedId ? 'selected'}}
Activity icon

Replied to Getting The Selected Value

ok but then how would I grab it to have the dropdown selected?

Activity icon

Started a new Conversation Getting The Selected Value

I have 2 pages the one has a list of products and the other page has a bunch of data for that product. There is also a drop down in the second page

The problem I'm having is that I'm struggling to get the dropdown to have the selected product selected.

So for example if I select product 1 from the first page then on the second page the dropdown will show product 1 and if I select product 2 then the dropdown will show product 2

Here is my code for productIndex.vue

<template>
    <div>
        <div class="content-header">
            <div class="container">
                <div class="row">
                    <div class="col-md-12">
                        <div class="card">
                            <div class="card-header">
                                <h3 class="card-title">Product Index</h3>
                            </div>
                            <div class="card-body p-0">
                                <table class="table table-sm table-hover">
                                    <thead>
                                        <tr>
                                            <th>ID</th>
                                            <th>Product Name</th>
                                            <th style="width: 180px;"></th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr v-for="product in products">
                                            <td>{{ product.id }}</td>
                                            <td>{{product.name}}</td>
                                            <td class="text-right">
                                                <a @click="goToProductData(product.id)" class="btn btn-xs btn-primary">
                                                    Data
                                                </a>
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>

</template>

<script>
    export default {
        props: ['products'],
        data() {
            return {

            }
        },
        methods: {
            goToProductData(product_id){
                localStorage.setItem('product',  product_id);
                window.location =  `/product-data`;
            }
        },
    }
</script>

and here is my productData.vue

<template>
    <div>
        <div class="content-header">
            <div class="container">
                <div class="card">
                    <div class="card-body">
                        <div class="row mb-2">
                            <div class="col-sm-6">
                                <label for="product_id_select">Product</label>
                                <select id="product_id_select" class="form-control select2" style="width: 100%;">
                                    <optgroup v-for="product in selectProducts" :label="customer.text">
                                        <option v-for="p in product.children" :value="p.id">{{ p.text }}</option>
                                    </optgroup>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        props: ['products'],
        data() {
            return {

            }
        },
        computed: {
            selectProducts() {
                let select2Options = [];

                Object.keys(this.products).forEach(product => {
                    let productOptions = [];

                    this.products[product].forEach(p => {
                        productOptions.push({ id: p.id, text: p.name });
                    });

                    select2Options.push({
                        text: product,
                        children: productOptions
                    });

                });

                return select2Options;
            }
        }
    }
</script>

Mar
30
3 weeks ago
Activity icon

Started a new Conversation Pushing To An Array In Vue Based On Name

I have an array that looks like this

0 => [
    'id' => 1,
    'name' => 'Item 1',
    'price' => [
        'price' => 123,
        'vat' => 12
    ]
]
1 => [
    'id' => 2,
    'name' => 'Item 2',
    'price' => [
        'price' => 123,
        'vat' => 12
    ]
]
2 => [
    'id' => 3,
    'name' => 'Item 3',
    'price' => [
        'price' => 123,
        'vat' => 12
    ]
]

and what I'm trying to do is push the total into my v-for loop.

So this is what I have in my vue

<template>
    <div>
        <div class="content-header">
            <div class="container">
                <div class="row">
                    <div class="col-md-12">
                        <div class="card">
                            <div class="card-header">
                                <h3 class="card-title">Items</h3>
                            </div>

                            <div class="card-body p-0">
                                <div class="overlay-wrapper">
                                    <table class="table table-sm table-hover">
                                        <thead>
                                            <tr>
                                                <th>Name</th>
                                                <th>Total</th>
                                            </tr>
                                        </thead>

                                        <tbody>
                                            <tr v-for="item in items">
                                                <td>{{item.name}}</td>
                                                <td>{{ item.total }} kWh</td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        props: ['items'],
        data() {
            return {
                
            }
        },
        methods: {
            getTotalPrices() {
                axios.post(`/api/getPrice`).then(response => {
                    Object.values(this.items).forEach(item => {
                        response.data.forEach(r => {
							if(item.name === r.name){
								this.items(item.name).push({
									'total': r.total
								})
							}
						}
                    }
                });
            },
        },
    }
</script>

my getTotalPrices gets the total and that is where I would like to push the total.

and my response looks like this

0 => [
    'id' => 1,
    'name' => 'Item 1',
    'price' => 135
]
1 => [
    'id' => 2,
    'name' => 'Item 2',
    'price' => 135
]
2 => [
    'id' => 3,
    'name' => 'Item 3',
    'total' => 135
]
Mar
29
3 weeks ago
Activity icon

Replied to Getting 500 Error

I went to the nginx error logs and there is nothing

Activity icon

Replied to Getting 500 Error

I did do that but there is no logs in storage/logs

Activity icon

Started a new Conversation Getting 500 Error

I when from using homestead to using vmware with ubuntu installed and now when I grab my site from my bitbucket repo it doesn't want to work. I get a 500 error, but if I install a brand new laravel app it works fine. I'm not sure how to fix this or what to add here to help

Mar
08
1 month ago
Activity icon

Started a new Conversation Getting Months From Now And A Couple Of Months Ago

What I'm trying to do get the month names from this month all the way to last year, but I'm not sure how to get that.

Mar
03
1 month ago
Activity icon

Started a new Conversation Sum Up Items From An Array

I have an array that looks like this

array:2 [▼
  0 => array:2 [▼
    "product_name" => "Product 1"
    "product_price" => "123"
  ]
  1 => array:2 [▼
    "product_name" => "Product 2"
    "product_price" => "123"
  ]
]

and I'm trying to sum my product_price together so I can have a total.

I'm not quite sure how to do it.

Here is my code


$comparePrice = [];
foreach($products as $product)
{
    $total = 0
    $comparePrice[] = [
        'product_name' => $product->name
        'product_price' => $product->price
    ]

}
Activity icon

Replied to Getting Page To Delay Until File Gets Saved

The Storage::put() isn't saving my pdf

Mar
02
1 month ago
Activity icon

Started a new Conversation Getting Page To Delay Until File Gets Saved

I have a link that when you click on it, it will generate a pdf and then you can download it. The issue I'm having is that I'm getting a file not found type of error and that is because the system has saved the file yet so I kind of need to delay it until it's there. At least I'm hoping that is the case.

This is what I've tried before

public function downloadPdf(User $user, Bill $bill)
{
    $billPdf = billService()->createPdf($user, $bill);

    sleep(5);

    return response()->download(storage_path('users/'.$user->id.'/bills/'.$billPdf), $bill->filename)
}

and my createPdf

public function createPdf(User $user, Bill $bill)
{
    $pdf = PDF::loadView('pdf.bill-format', ['bill' => $bill]);

    $path = "bills/".$bill->created_at;
    Storage::disk('users/'.$user->id.'/bills/')->put(path, $pdf->output());

    return Storage::disk('bills')->path($path);
}
Feb
27
1 month ago
Activity icon

Replied to Is There A Way To Have Both The V-model And Value?

What I'm trying to do is have a page that has a list of products and there will be textboxes where I can enter the price of the product and what I'm trying to do is when I go to save my data to the database I would like to add the product name to the new table that I'm trying to save to.

Does that help?

Feb
26
1 month ago
Activity icon

Started a new Conversation Is There A Way To Have Both The V-model And Value?

So I need to grab my product's name so I can save it with a bunch of other data, the problem I have is that I don't know how to add both the v-model and value.

Here is my code

<template>
    <div class="content-header">
        <div class="container">
            <div class="row">
                <div class="col-sm-12">
                    <div class="card">
                        <div class="card-body">
                            <div class="row">
                                <div class="col-lg-12">
                                    <table class="table">
                                        <thead>
                                            <tr>
                                                <th>Name</th>
                                            </tr>
                                        </thead>

                                        <tbody>
                                            <tr v-for="product in products" >
                                                <td>
                                                    <input type="text" v-model="productName" value="{{ product.name }}">
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
export default{
    props: [],
    data(){
        return {
            products: [],
            productName: null
        }
    },
    methods: {
        getProducts(){
            axios.get(`/api/products`).then(response => {
                this.products = response.data.products;
            });
        },
        postData(){
            axios.post(`/api/products/summary, {
                productName: this.productName
            }).then(response => {

            })
        }
    },
    mounted() {
        this.getProducts();
    }
}
</script>
Feb
25
1 month ago
Activity icon

Started a new Conversation Getting A NaN When Typing A Value

I'm trying to calculate a value from 2 input boxes and then get the subtotal of them and the issue I'm having is that when I type in a number in the first box my output is NaN instead of 0.

Here is my code

<template>
    <div class="content-header">
        <div class="container">
            <div class="row">
                <div class="col-sm-12">
                    <div class="card">
                        <div class="card-body">
                            <div class="row">
                                <div class="col-lg-12">
                                    <table class="table">
                                        <thead>
                                            <tr>
                                                <th>Name</th>
                                                <th>Unit</th>
                                                <th>Price</th>
                                            </tr>
                                        </thead>

                                        <tbody>
                                            <tr v-for="product in products">
                                                <td>{{ product['name'] }}</td>
                                                <td>
                                                    <input type="text" class="form-control" v-model="unit[product['unit']]" @change="calculateCost(product['name'])">
                                                </td>
                                                <td>
                                                    <input type="text" class="form-control" v-model="price[product['price']]" @change="calculateCost(product['name'])">
                                                </td>
                                                <td>
                                                    {{ cost[product['name']] }}
                                                </td>
                                            </tr>

                                            <tr>
                                                <td></td>
                                                <td></td>
                                                <td></td>
                                                <td>
                                                    Subtotal: {{ subTotal }}
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
export default{
    props: [],
    data(){
        return {
            products: [],
            unit: {},
            price: {},
            cost: []
        }
    },
    computed:{
        subTotal(){
            if(this.fees !== null)
            {
                if(Object.keys(this.fees).length !== 0){
                    return  Object.keys(this.fees).reduce((carry, item) => {
                                carry+= Number(this.fees[item])
                                return carry;
                            }, Number(0))
                }else{
                    return 0;
                }
            }
        }
    },
    methods: {
        getProducts(){
            axios.get(`/api/product/all`).then(response => {
               this.products = response.data.products;
            });
        },
        calculateCost(item){
            this.cost[item] = Number(this.unit[item]) * Number(this.price[item]);
        },
    },
    mounted() {
        this. getProducts();
    }
}
</script>
Activity icon

Started a new Conversation The Specified Value Cannot Be Parsed, Or Is Out Of Range In Vue

I'm trying to create a form that will update a product's pricing when adding the unit amount of the product and a price of the product, but when I type into one of my textboxes I end up getting this error

The specified value "unit_product_1" cannot be parsed, or is out of range

I don't know what that means or how to solve it.

Here is my code

<template>
    <div class="content-header">
        <div class="container">
            <div class="row">
                <div class="col-sm-12">
                    <div class="card">
                        <div class="card-body">
                            <div class="row">
                                <div class="col-lg-12">
                                    <table class="table">
                                        <thead>
                                            <tr>
                                                <th>Name</th>
                                                <th>Unit</th>
                                                <th>Price</th>
                                            </tr>
                                        </thead>

                                        <tbody>
                                            <tr v-for="product in products">
                                                <td>{{ product['name'] }}</td>
                                                <td>
                                                    <input type="text" class="form-control" v-model="product['unit']">
                                                </td>
                                                <td>
                                                    <input type="text" class="form-control" v-model="product['price']">
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
export default{
    props: [],
    data(){
        return {
            products: [],
            unit_product_1: null,
            price_product_1: null,
        }
    },
    computed:{

    },
    methods: {
        getProducts(){
            axios.get(`/api/product/all`).then(response => {
               this.products = response.data.products;
            });
        }
    },
    mounted() {
        this. getProducts();
    }
}
</script>
Activity icon

Replied to Price Not Automatically Being Calculated

How would I then get it to update

Activity icon

Started a new Conversation Price Not Automatically Being Calculated

I'm trying to create a page where my product's amount will automatically get calculated, the problem I'm having is that my computed property isn't calculating the amount.

Here is my code

<template>
    <div class="content-header">
        <div class="container">
            <div class="row">
                <div class="col-sm-12">
                    <div class="card">
                        <div class="card-body">
                            <div class="row">
                                <div class="col-lg-12">
                                    <table class="table">
                                        <thead>
                                            <tr>
                                                <th>Name</th>
                                                <th>Unit</th>
                                                <th>Price</th>
                                                <th>Amount</th>
                                            </tr>
                                        </thead>

                                        <tbody>
                                            <tr v-for="product in products">
                                                <td>{{ product }}</td>
                                                <td>
                                                    <input type="text" class="form-control" v-model="product['unit']">
                                                </td>
                                                <td>
                                                    <input type="text" class="form-control" v-model="product['price']">
                                                </td>
                                                <td>
                                                    {{ calculateAmount }}
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
export default{
    props: [],
    data(){
        return {
            products: [],
            unit_product_1: null,
            rate_product_1: null
        }
    },
    computed:{
        calculateAmount(){
            return this.unit_product_1 * this.rate_product_1;
        },
        convertToArray(){
            let testArray = [];

            Object.keys(this.products).forEach(item => {
                if(item === 'product_1'){
                    testArray.push({
                        'name': 'Product 1',
                        'unit': 'unit_'+item,
                        'price': 'price_'+item
                    });
                }

                if(item === 'product_2'){
                    testArray.push({
                        'name': 'Product 2',
                        'unit': 'unit_'+item,
                        'price': 'price_'+item
                    });
                }
            });

            return testArray;
        }
    },
    methods: {
        getProducts(){
            axios.get(`/api/product/all`).then(response => {
               this.products = response.data.products;
            });
        }
    },
    mounted() {

    }
}
</script>
Feb
24
1 month ago
Activity icon

Replied to Not Getting My V-model Value

Then how would I sort it out. Even if I make the selectedValue as an empty string or if I remove it from my

data() {
       return {
    
        }
}

it still isn't working

Activity icon

Started a new Conversation Not Getting My V-model Value

I'm trying to get the value of my select but it isn't being picked up and I'm not sure why. When I check my console I have a null.

Here is my code.

<template>
    <div class="content-header">
        <div class="container">
            <div class="row">
                <div class="col-sm-6">
                    <div class="card">
                        <div class="card-body">
                            <div class="row mb-2">
                                <div class="col-sm-12">
                                    <label for="product_select">Products</label>
                                    <select id="product_select" class="form-control" v-model="selectedValue">
                                        <optgroup v-for="product in products" :label="product.text">
                                            <option v-for="list in product.children" :value="list.id">{{ list.text }}</option>
                                        </optgroup>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    export default{
        props: ['products'],
        data(){
            return {
                selectedValue: null
            }
        },
        computed:{

        },
        watch: {

        },
        methods: {

        }
        mounted() {
          console.log(this.selectedValue);
        }
    }
</script>
Activity icon

Started a new Conversation Array To String Converstion Error

I'm getting this error

Array to string conversion

It happens when I pass an array through to the vue page.

Here is my code.

My ProductController

public function getUserProducts()
{
  return view('products.product-list. [
    'products' => request()->user()->list_products
  ])
}

my product-list.blade.php

<div id="app">
  <products :products="{!! $products !!}"/>
</div>
Feb
23
2 months ago
Activity icon

Started a new Conversation Getting A Null When Console.log(this.user)

I'm using vue with my laravel site and when I click on a button I get taken to another page, the issue I'm having is that I'm not getting my info from my props.

When I console.log(this.user) in my CreateProduct.vue page I get a null

Here is my code

My app.js

Vue.component('index', require('../js/admin/Index').default);
Vue.component('create-product', require('../js/admin/CreateProduct').default);

if(document.getElementById('app) ! == null){
  const app = new Vue({
    el: '#app,
    data(){
        return {
          user: null
        }
    },
    methods:{

    },
    mounted(){
      axios.get('/api/getUser').then(response => {
        this.user = response.data;
      });
    }
  })
}

My Index.vue

<template>
  <div>
    <button class="btn btn-sm btn-success" @click="createProduct">Create Product</button>
  </div>
</template>

<script>
  export default{
    props: [],
    data(){
      return {

      }
    },
    methods: {
      createProduct(){
        window.location = /admin/create/product';
      }
    }
  }
</script>

Then my create-product.blade.php

@extends('layouts.app')
@section('content')
  <div id="app">
    <create-product :user="user"/>
  </div>
@endsection

and my CreateProduct.vue

<template>
  <div>
    This is the create product page
  </div>
</template>

<script>
  export default{
    props: ['user'],
    data(){
      return {

      }
    },
    methods: {
      
    },
    mounted(){
      console.log(this.user);
    }
  }
</script>
Feb
22
2 months ago
Activity icon

Started a new Conversation Error When Trying To Create A Feature Using Opensoft/Rollout

I'm trying to get opensoft/rollout to work and I've added this to my bootstrap/app.php

if(!function_exists('rollout'))
{
    function rollout() : \Opensoft\Rollout\Rollout{
        return app('Opensoft\Rollout\Rollout');
    }
}

if(!function_exists('feature'))
{
  function feature(string $feature) : bool {
      return rollout()->isActive($feature, request()->user());
  }
}

And in my app/Providers/AppServiceProvider.php I have

$this->app->singleton('rollout', function(){
  $conn = DB::connection()->getPdo();
  $rollout = new Rollout(new PDOStorageAdapter ($conn));
});

and in my artisan command I have

$feature = rollout()->isActive('testing');
dd($feature);

and what happens is when I run my artisan command I get this error

Target [Opensoft\Rollout\Storage\StorageInterface] is not instantiable while building [Opensoft\Rollout\Rollout].
Activity icon

Replied to Intergrating A Pacakge

From what I understand that package isn't useable for laravel 8

Activity icon

Replied to Intergrating A Pacakge

I've checked it out and I'm trying to get the PDOStorageAdapter storage to work.

I thought that I just needed to do this

$conn = DB::connection();
$rollout = new Rollout(new PDOStorageAdapter($conn));

but then I got this error

Argument 1 passed to Opensoft\Rollout\Storage\PDOStorageAdapter::__construct() must be an instance of PDO, instance of Illuminate\Database\MySqlConnection given
Activity icon

Started a new Conversation Intergrating A Pacakge

I'm trying to integrate this https://github.com/opensoft/rollout into laravel and I'm struggling to find articles on the net on how to do this.

Is there any advice or does anyone know where I can go look?

Activity icon

Replied to Clearing Cache

I ended up getting this error Too few arguments to function Illuminate\Redis\Connections\PhpRedisConnection::eval(), 1 passed in /home/ifrit/Documents/projects/laravel-app/vendor/laravel/framework/src/Illuminate/Redis/RedisManager.php on line 276 and exactly 2 expected

Activity icon

Started a new Conversation Clearing Cache

I'm using redis for my cache and I'm trying to create a command that will clear the cache, the problem is, is that my cache key is something like this post:accepted:$date and I would like to be able to clear all my cache that has post:accepted.

I would like to maybe use redis-cli flushdb but I'm not sure on how to call that in my command

Activity icon

Replied to Getting Posts For Today

Will go through them this weekend

Activity icon

Started a new Conversation Getting Posts For Today

I'm trying to create a query that gets all the posts that was created today, but what I want is to get the posts based on the date and not the time.

Here is the query

$posts = Post::where('created_at', '=', Carbon::now()->format("Y-m-d"))->get();
Feb
18
2 months ago
Activity icon

Started a new Conversation Getting Seeders To Link Together

I'm trying to create some seeders that will link my items together.

This is what my tables look like

here are my migration files

Schema::create('products', function (Blueprint $table) {
    $table->id();
    $table->string('name');
    $table->timestamps();
    $table->softDeletes();
});

Schema::create('categories', function (Blueprint $table) {
    $table->id();
    $table->string('name');
    $table->unsignedBigInteger('product_id');
    $table->timestamps();
    $table->softDeletes();
});

Schema::create('users', function (Blueprint $table) {
    $table->id();
    $table->string('name');
    $table->string('email')->unique();
    $table->timestamp('email_verified_at')->nullable();
    $table->string('password');
    $table->dateTime('last_login_at')->nullable();
    $table->softDeletes();
    $table->rememberToken();
    $table->timestamps();
});

Schema::create('product_user', function (Blueprint $table) {
    $table->unsignedBigInteger('product_id');
    $table->unsignedBigInteger('user_id');
});

What I would like is to be able to create some dummy data but I would like my seeders to link them as well.

This is what I have at the moment

In my CategoryFactory

public function definition()
{
    return [
        'name' => $this->faker->company,
        'product_id' => $this->faker->numberBetween(1, 10),
    ];
}

My ProductFactory

public function definition()
{
    return [
        'name' => $this->faker->company,
    ];
}

My UserFactory

public function definition()
{
    return [
        'name' => $this->faker->name,
        'email' => $this->faker->unique()->safeEmail,
        'email_verified_at' => now(),
        'password' => bcrypt('secret'), // password
        'remember_token' => Str::random(10),
    ];
}

My ProductUserFactory

public function definition()
{
    return [
        'product_id' => $this->faker->numberBetween(1, 10),
        'user_id' => $this->faker->numberBetween(1, 10),
    ];
}

Then I have in my ProductSeeder

public function run()
{
    Product::factory()
                ->count(10)
                ->create();
}

and I also have the HasFactory on my Product model.

I also have CategorySeeder, UserSeeder, ProductUserSeeder

Activity icon

Replied to Redirecting After Login

Yep that was it. Thank you

Activity icon

Started a new Conversation Redirecting After Login

I'm trying to redirect depending if the user is either admin or customer.

I've tried changing my LoginController to this

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */

    use AuthenticatesUsers;

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    protected $redirectTo = RouteServiceProvider::HOME;

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }

    protected function redirectTo()
    {

        if(auth()->user()->role == 'admin')
        {
            return redirect()->route('home');
        }else{
            return redirect()->route('customer');
        }
    }
}
Feb
17
2 months ago
Activity icon

Started a new Conversation Getting Highest, Avg And Lowest Prices

I'm trying to get the highest, avg and lowest price I have for product prices during a given time frame. I'm not sure as to how about to do this.

Here is my code

$start = request('start');
$end = request('end');

$prices = Product::whereBetween('created_at', [$start, $end])->get();
Feb
15
2 months ago
Activity icon

Replied to How To Get My Range Date To Show Up

@corvs - thank you. I set your answer as correct since that was my question. @guybrush_threepwood - thank you for your advice I decided to remove the hidden inputs since I didn't need them because fo the @this.set()

Activity icon

Started a new Conversation How To Get My Range Date To Show Up

The problem I'm having is that after I've selected a date range and the page refreshes and the date that I selected is not showing. I'm using livewire

Here is my code

<div id="reportrange" wire:model="rangeDate" style="background: #fff; cursor: pointer; padding: 5px 10px; border: 1px solid #ccc;  width: 100%; height: 36px;  border-radius: 5px; margin-top: 4px; overflow: hidden;">
    <i class="fa fa-calendar"></i>&nbsp;
    <span wire:model="rangeDate"></span> <i class="fa fa-caret-down"></i>

    <input type="hidden"  id="startDate" wire:model="startDate">
    <input type="hidden"  id="endDate" wire:model="endDate">
</div>

<script type="text/javascript">
    $(function() {
        var start = moment();
        var end = moment();

        function cb(start, end) {
            $('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
        }

        $('#reportrange').daterangepicker({
            startDate: start,
            endDate: end,
            ranges: {
                'Today': [moment(), moment()],
                'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
                'Last 7 Days': [moment().subtract(6, 'days'), moment()],
                'Last 30 Days': [moment().subtract(29, 'days'), moment()],
                'This Month': [moment().startOf('month'), moment().endOf('month')],
                'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
            }
        }, function(start, end){
            $('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));

            @this.set('startDate', start.format('YYYY-MM-DD'));
            @this.set('endDate', end.format('YYYY-MM-DD'));
        }, cb);

        cb(start, end);
    });
</script>

and this is my Index.php

<?php

namespace App\Http\Livewire\Products;

use App\Models\Product;
use Livewire\Component;

class Index extends Component
{
    public $startDate = '';
    public $endDate = '';
    public $rangeDate;

    public function render()
    {
        $products = Product::whereBetween('created_at', [$this->startDate, $this->endDate]);

        $this->rangeDate = $this->startDate;
        return view('livewire.products.index', ['products' => $products]);
    }
}
Feb
03
2 months ago
Activity icon

Started a new Conversation Selecting A Distinct

How do I select only 1 of each value in my query, so for example I have

Category 1
Category 1
Category 1
Category 2
Category 3

and what I want is to get

Category 1
Category 2
Category 3

Here is what I have

$categories = Product::all()->unique('category');

but that isn't correct

Feb
02
2 months ago
Activity icon

Replied to Trying To Access Array Offset On Value Of Type Int

But what if I just want the Title 1?

Activity icon

Started a new Conversation Trying To Access Array Offset On Value Of Type Int

I have an array that looks like this

array: {
    0 => 'Title 1',
    1 => 'Description 1'
}

The problem I'm having is when I do this in my blade file

@foreach($arrays as $array)
    {{ $array[0] }}
@endforeach 

I get this error

Trying to access array offset on value of type int

Jan
25
2 months ago
Activity icon

Started a new Conversation Getting A List Of New And Old Values

I have a table that as a list of roles and what I'm trying to do is when a user uploads a new position it needs to compare the differences between the new roles and the old roles.

So what I'm trying to do is get some kind of list that will give me a list of missing roles and the price that they have in the roles tabled pased on the positions ID.

For example

My roles table looks like this

    id | name          | salary | position_id
    1  | Admin         | 1234   |     1
    2  | Manager       | 1111   |     1
    3  | Sales Manager | 1111   |     1
    4  | Clerk         | 10     |     2

So when the user uploads a new role for a specific position my roles table will look like this

    id | name          | salary | position_id
    1  | Admin         | 1234   |     1
    2  | Manager       | 1111   |     1
    3  | Clerk         | 10     |     2
    4  | Admin         | 2222   |     3
    5  | Manager       | 3333   |     3
    6  | Sales Manager | 1111   |     3

And what I'm trying to do is (in this example) is grab Admin and Manager where the position is the old position EG: position_id = 1 and where the position is the new position EG: position_id = 3 and where the price is different

Here is my code

    public function changeRoles(Position $position)
    {
        $old_roles = Role::where('position_id', $position->id)->get();

        $new_position = Position::find(request('position'));
        $new_roles = Role::where('position_id', $new_position->id)->get();
        
        $old_arr = [];
        $old_salary = [];

        foreach($old_roles as $old_role)
        {
            $old_arr[] = $old_role->name;
            $old_salary[] = $old_role->salary;
        }

        $new_arr = [];
        $new_salary = [];

        foreach($new_roles as $new_role)
        {
            $new_arr[] = $new_role->name;
            $new_salary[] = $new_role->salary;
        }

        // grabing only the totals where there is a difference between the old one and new one
        $total_diff = array_diff($new_salary, $old_salary);
        
        
        // List all new and old stuff
	$newStuff = Role::whereIn('position_id', [$new_position ->id, $position_id->id])
                                ->whereColumn('salary', '!=' ,'salary')
                                ->get();

    }
Jan
19
3 months ago
Activity icon

Replied to Comparing Arrays Is Looping To Many Times

how would you do that?

Jan
18
3 months ago
Activity icon

Started a new Conversation Not Able To Vagrant Up With Homestead

I'm trying to get homestead to work on my windows 10 machine, but I'm getting this error

Bringing machine 'homestead' up with 'virtualbox' provider...
==> homestead: Checking if box 'laravel/homestead' version '9.5.1' is up to date...
==> homestead: A newer version of the box 'laravel/homestead' is available and already
==> homestead: installed, but your Vagrant machine is running against
==> homestead: version '9.5.1'. To update to version '9.7.2',
==> homestead: destroy and recreate your machine.
==> homestead: Clearing any previously set forwarded ports...
==> homestead: Clearing any previously set network interfaces...
==> homestead: Preparing network interfaces based on configuration...
    homestead: Adapter 1: nat
    homestead: Adapter 2: hostonly
==> homestead: Forwarding ports...
    homestead: 80 (guest) => 8000 (host) (adapter 1)
    homestead: 443 (guest) => 44300 (host) (adapter 1)
    homestead: 3306 (guest) => 33060 (host) (adapter 1)
    homestead: 4040 (guest) => 4040 (host) (adapter 1)
    homestead: 5432 (guest) => 54320 (host) (adapter 1)
    homestead: 8025 (guest) => 8025 (host) (adapter 1)
    homestead: 9600 (guest) => 9600 (host) (adapter 1)
    homestead: 27017 (guest) => 27017 (host) (adapter 1)
    homestead: 22 (guest) => 2222 (host) (adapter 1)
==> homestead: Running 'pre-boot' VM customizations...
==> homestead: Booting VM...
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["startvm", "33155129-8efb-4194-a2e3-394aa799b6ab", "--type", "headless"]

Stderr: VBoxManage.exe: error: Failed to open/create the internal network 'HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter #2' (VERR_INTNET_FLT_IF_NOT_FOUND).
VBoxManage.exe: error: Failed to attach the network LUN (VERR_INTNET_FLT_IF_NOT_FOUND)
VBoxManage.exe: error: Details: code E_FAIL (0x80004005), component ConsoleWrap, interface IConsole
Jan
15
3 months ago
Activity icon

Replied to Comparing Arrays Is Looping To Many Times

It looped through the foreach loops and was comparing it so I had a huge array. It was the same as what I ended up getting with my original code

Activity icon

Replied to Comparing Arrays Is Looping To Many Times

but wouldn't the same thing happen with it looping all the time and having it compare to all the values?

Activity icon

Started a new Conversation Comparing Arrays Is Looping To Many Times

I'm trying to compare 2 arrays, but the problem is that it's looping so many times that it isn't working correctly Here is my code

public function bulkUploadProducts(Category $category)
{
    $oldProducts = Product::where('category_id', $category->id)->get();
    $newProducts = Product::where('category_id', request('category_id'))->get();

    $oldPrices = [];
    foreach($oldProducts as $oldProduct)
    {
        $oldPrices[] = [
            'excluding' => $oldProduct->excluding,
            'including' => $oldProduct->including
        ];
    }

    $newPrices = [];
    foreach($newProducts as $newProduct)
    {
        $newPrices[] = [
            'excluding' => $newProduct->excluding,
            'including' => $newProduct->including
        ];
    }

    $diff = [];
    foreach($oldPrices as $oldPrice)
    {
        foreach($newPrices as $newPrice)
        {
            if($oldPrice['excluding'] == $newPrice['excluding'])
            {

            }else{
                $diff[] = [
                    'excluding' => $newPrice['excluding']
                ];
            }
        }
    }

    dd($diff);
}

What I need is for it to only give me the new prices where there is a difference.

For example if the old price is 123 and the new price is 234 then I need $diff to be 234, but if the old price is 123 and the new price is 123 then nothing is supposed to happen

Activity icon

Started a new Conversation Not Passing Data Through To Blade File

I'm trying to send some data through to a blade file but I'm not getting anything, it is just returning to the page without displaying the message.

Here is my controller code

public function missingProducts(Category $category)
{
    $oldProducts = Product::where('category', $category->id)->get();
    $newProducts = Product::where('category', request('category'))->get();

    $oldArr = [];
    foreach($oldProducts as $oldProduct)
    {
        $oldArr[] = $oldProduct->name;
    }

    $newArr = [];
    foreach($newProducts as $newProduct)
    {
        $newArr[] = $newProduct->name;
    }

    $missingProducts = array_diff($oldArr, $newArr);

    if(!empty($missingProducts))
    {
        return redirect()->route('admin.category', ['category' => $category->id])
                                ->with(['missingProducts' => $missingProducts]);
    }else{
        dd('there is NO products missing');
    }
}

My blade file

@if(!empty($missingProducts))
    <div class="alert alert-success">
        We are missing products
    </div>
@endif
Jan
13
3 months ago
Activity icon

Started a new Conversation No Query Results For Model

I'm trying to update my product but I'm getting this error

"message": "No query results for model [Modules\Products\Models\Product] 488"

Here is my vue file

<template>
    <div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label>Name</label>
                    <input
                        type="text"
                        class="form-control"
                        v-model="product.name"
                    >
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        props: ['product'],
        computed: {
      
        },
        data() {
            return {

            }
        },
        methods: {
            updateProduct() {
                axios.put(`/api/products/${this.product.id}`,{
                    name: this.product.name
                }).then(response => {
            },
        },
        mounted() {

        }
    }
</script>

and my updateProduct function in my controller

public function updateProduct(Product $product)
{
    dd(request('name'));
}
Jan
12
3 months ago
Activity icon

Started a new Conversation All Textboxes Turning Red

I have a bunch of textboxes that I would like to change to red when a user has made a change to it, the problem I'm having is that all the textboxes goes red and not the one that was changed.

Here is my code

<template>
    <div class="row">
        <div class="col-sm-12">
            <table class="table table-sm">
                <thead>
                    <tr>
                        <th>Name</th>
                        <th style="width:70px;">Price</th>
                    </tr>
                </thead>
                <tbody>
                    <tr v-for="product in products">
                        <td>
                            <input
                                class="form-control"
                                type="number"
                                v-model="product.name"
                                @change="onChange();"
                                :style="{ color: conditionalColor}"
                            >
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</template>

<script>
    export default {
        props: [],
        data() {
            return {
                change: false
            }
        },
        computed: {
            conditionalColor(){
                return this.change ? 'red' : ''
            }
        },
        methods: {
            onChange(){
                return this.change = true;
            }
        },
        mounted() {

        }
    }
</script>