theUnforgiven

theUnforgiven

Member Since 4 Years Ago

UK

Web Developer at NRS

Experience Points 267,540
Experience Level 50

0 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 1470
Lessons
Completed
Best Reply Awards 45
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

18 Apr
1 week ago

theUnforgiven left a reply on Eloquent, Relationships And Foreach Loops

@tykus - presuming you saw my reply, I'm still looking to get this sorted with a solution of sort, your help greatly appreciated.

15 Apr
1 week ago

theUnforgiven left a reply on Eloquent, Relationships And Foreach Loops

Sorry, I'm wanting to show all income/rents that are paid so there should be 5 rows there, then for expenditure/payments, there's 2 rows so in total on the html table/view I should see 7 rows.

theUnforgiven left a reply on Eloquent, Relationships And Foreach Loops

$incomes = DB::table('companies')
                        ->where('companies.id', user()->companies()->first()->id)
                        ->leftJoin('payments', 'companies.id', '=', 'payments.company_id')
                        ->leftJoin('rents', function ($join) {
                            $join->on('companies.id', '=', 'rents.landlord_id')->where('status', '!=', 'unpaid');
                        })
                        ->leftJoin('properties', 'rents.property_id', '=', 'properties.id')
                        ->get();

theUnforgiven left a reply on Eloquent, Relationships And Foreach Loops

Anyone else willing to chip in?

theUnforgiven left a reply on Eloquent, Relationships And Foreach Loops

Also this is kinda like a Balance sheet, so income should be rents and payments will be expenditure

theUnforgiven left a reply on Eloquent, Relationships And Foreach Loops

There's 8 records showing and they are duplicates of each rent item, so each showing twice, there should be 6 items in total (should be 7 but we exclude the unpaid one) I guess i need a groupBy() of some sort just not sure as I'm a little new to this join/sub query stuff.

theUnforgiven left a reply on Eloquent, Relationships And Foreach Loops

Yeah, I can see that now and I think I should be able to figure the rest out, thanks buddy. Failing that I may be back later :)

theUnforgiven left a reply on Eloquent, Relationships And Foreach Loops

That query is showing:

SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous (SQL: select * from `companies` left join `payments` on `companies`.`id` = `payments`.`landlord_id` left join `rents` on `companies`.`id` = `rents`.`company_id` and `status` != unpaid where `id` = 59)

theUnforgiven started a new conversation Eloquent, Relationships And Foreach Loops

I have the following html table:

Which I want to populate with the income and any expenditure. I have a payments table and a rents table, these will be income and expenditure respectively.

I have the following query, which is producing the correct amount of results, but I don't really want to do 3 foreach loops

$incomes = Company::with(['rents' => function($q) {
                                $q->where('status', '!=', 'unpaid');
                            }])
                            ->with('payments')
                            ->where('id', user()->companies()->first()->id)
                            ->get();

Rents Table:

Payments Table:

How the collection is rendering when dd()

Again like I say I wan this to fit within the html table is laid out so it all fits in the correct places, but don't see how without doing 3 foreach loops.

Any help/advice greatly appreciated.

08 Apr
2 weeks ago

theUnforgiven left a reply on Join Two Tables, And Get Full Sum Of Both Amount Cols In Each Table

I dont have SQL for it as its something im trying to do. I basocally want those two tables joining and then be able to total both amount columns on both tables to give me a total

theUnforgiven left a reply on Uploading File Or Any Type

Seems there's still nothing in the array:

"items" => array:1 [
    0 => array:6 [
      "id" => null
      "item" => "ad"
      "amount_os" => "23"
      "value" => null
      "description" => "23"
      "file" => null
    ]
  ]

theUnforgiven left a reply on Uploading File Or Any Type

Ah, no I didn't. Thanks I'll give that a whirl ;)

theUnforgiven left a reply on Join Two Tables, And Get Full Sum Of Both Amount Cols In Each Table

Apologies, thought I'd posted it, meh!!

This is my payments table

This is my rents table

I have the relationships setup, but the results I am getting arent what I'm expecting, I'm expecting to see all rows from both tables and then be able to total it up at the end of the HTML table, it's basically a balance sheet for income and expenditure.

theUnforgiven started a new conversation Join Two Tables, And Get Full Sum Of Both Amount Cols In Each Table

I have two tables both of which have an amount column, how can I join these two tables together using Eloquent so I can use the relationships etc, but then get the total of both amount columns.

theUnforgiven left a reply on Uploading File Or Any Type

Does anyone else have any suggestions to make this work within one component?

06 Apr
2 weeks ago

theUnforgiven left a reply on Uploading File Or Any Type

Now, I get Cannot read property 'files' of undefined error based on what you said.

theUnforgiven left a reply on Uploading File Or Any Type

Yes, I see what you mean. Maybe I can live with that, I'll try it out and see how it feels.

theUnforgiven left a reply on Uploading File Or Any Type

I don't really want to have it as an extra component, surely it can all be done from the same component?

theUnforgiven left a reply on Uploading File Or Any Type

Anyone? As I'm not sure how to resolve this... :(

05 Apr
2 weeks ago

theUnforgiven left a reply on Uploading File Or Any Type

Anyone? As I'm not sure how to resolve this... :(

theUnforgiven left a reply on Uploading File Or Any Type

Ok thanks good spot! How would one change that to do what i need it do?

theUnforgiven started a new conversation Uploading File Or Any Type

Hi all,

I'm looking for a little advice here, I'm trying to get all form inputs as well as any type of file the user selects to upload. I have the following in my Vue component:

<template>
<div>
    <div class="inputArea" v-for="(input, index) in inputs" :key="index">
        <div class="table-responsive">
            <table class="table-sm">
                <tr>
                    <td>Item
                        <input type="text" :id="input.id" v-model="input.item" name="item[]"  class="form-control" value="" autocomplete="off" placeholder="Gas Bill">
                    </td>
                    <td>
                         Amount Outstanding
                        <div class="input-group">
                          <div class="input-group-prepend">
                            <span class="input-group-text">£</span>
                          </div>
                          <input type="number" :id="input.id" v-model="input.amount_os" name="amount_os[]" class="form-control" value="" autocomplete="off" placeholder="22.00">
                        </div>
                    </td>
                    <td>
                        Description
                        <input :id="input.id" v-model="input.description" type="text" class="form-control" name="description[]" value="">
                    </td>
                    <td>
                        Invoice
                        <input type="file" id="file" ref="file" @change="handleFileUpload()">
                    </td>
                    <td>
                        <br />
                        <button v-on:click.prevent="removeInput(input.id)" class="btn btn-sm btn-danger"><i class="fa fa-trash"></i></button>
                        <button @click.prevent="addInput" class="btn btn-sm btn-primary">Add Item</button>
                    </td>
                </tr>
            </table>

            <button class="btn btn-success mt-3" @click.prevent="addBill">Update</button>
        </div>
    </div>
</div>
</template>

<script>

export default {

    data() {
        return {
            counter: 0,
            inputs: [{
                id: '',
                item: '',
                amount_os: '',
                value: '',
                description: '',
                file: ''
            }],
        }
    },

    methods: {
        addInput(e) {
            e.preventDefault();
            this.inputs.push({
                id: `item${++this.counter}`,
                item: '',
                amount_os: '',
                value: '',
                description: '',
                file: ''
            });
        },
        removeInput : function (input) {
            this.inputs.splice(input, 1);
        },
        addBill() {                
            axios.post('/bills', { 
                    headers: {
                        "Content-type": "multipart/form-data; charset=utf-8; boundary=" + Math.random().toString().substr(2)
                    },
                    items: this.inputs, file: this.file     
                }).then(response => {
                        console.log(response);
                });
        },
        handleFileUpload(event){
            this.inputs.file = this.$refs.file.files[0];
          }
    }
}
</script>

Which results in the following response:

array:2 [
  "headers" => array:1 [
    "Content-type" => "multipart/form-data; charset=utf-8; boundary=9473711616144889"
  ]
  "items" => array:1 [
    0 => array:6 [
      "id" => null
      "item" => "qwe"
      "amount_os" => "22"
      "value" => null
      "description" => "qw"
      "file" => null
    ]
  ]
]

But there's no file there, even though I did select a file to upload. Any help & suggestions, greatly appreciated.

19 Mar
1 month ago

theUnforgiven left a reply on For Loop With Dates

@grenadecx solution worked a treat, so I've opted for that. Both I'd like to thank for these suggestions.

theUnforgiven left a reply on For Loop With Dates

Thanks guys, that should give me enough ideas on how best to do this now, much appreciated ;-)

theUnforgiven left a reply on For Loop With Dates

So within the return statement I guess I can add the following: ??

$rents = new RentDetails;
$rents->user_id = $tenant->id;
$rents->landlord_id = user()->companies->first()->id;
$rents->property_id = $property->id;
$rents->item = 'rent';
$rents->amount = $property->rent;
$rents->amount_paid = 0;
$rents->due_date = ''; // this is where the date should be the set due date then plus 1 month thereafter
$rents->paid = 0;
$rents->part_paid = 0;
$rents->upaid = 1;
$rents->paid_date = null;
$rents->month = '';
$rents->paid_to = '';
$rents->save();

theUnforgiven started a new conversation For Loop With Dates

Hi all,

I hope everyone is having a good week so far....

I'm looking for some help from you awesome people, I want to have a number of rows entered into the database, based on the selection from a user.

For Example:

So if the user selects 6 month, then I want to enter 6 rows with the first row due date been the due date that is set, then the remaining 5 rows be due date plus 1 month.

Like wise if it's 12 month, 2 year etc

I have the following switch statement, which strips out a - and everything after it so in essence just words and this gives me the number.

$duration = strstr($request->input('duration'), '-', true);
        switch ($duration) {
            case 6: // 6mth
                $os_payments = 6;
                break;
            case 12: //12 mth
                $os_payments = 12;
                break;
            case 18: // 18 mth
                $os_payments = 18;
                break;
            case 2: // 2 yr
                $os_payments = 24;
                break;
            case 3: // 3 yr
                $os_payments = 36;
                break;
            case 4: // 4 yr
                $os_payments = 48;
                break;
            case 5: //5 yr
                $os_payments = 60;
                break;
        }

Which then I have the amount of months, but I can't seem to do a for loop for this, to enter the correct amount of rows and the due dates like I mentioned above.

Any help, greatly appreciated.

04 Mar
1 month ago

theUnforgiven left a reply on Creating Foreign Key In Laravel 5.8.2 Failling

I found the same issue and just changed bigInteger to integer

21 Feb
2 months ago

theUnforgiven left a reply on Selecting Checkboxes With VueJS Chat

By adding an extra method to the component with help from @RachidLaasri

selectUser(userId) {
                if(this.selected.includes(userId)) {
                    return this.selected.remove(userId);
                }
                this.selected.push(userId);
            },

This is now working.

theUnforgiven left a reply on Selecting Checkboxes With VueJS Chat

Anyone willing to help

theUnforgiven left a reply on Selecting Checkboxes With VueJS Chat

Anyone willing to try and help a brother out?

theUnforgiven left a reply on Selecting Checkboxes With VueJS Chat

Just a pointer too, the current code is saving all 3 users I have associated with the company rather than what is selected.

theUnforgiven started a new conversation Selecting Checkboxes With VueJS Chat

Hi all,

I have a small problem with a chat application I'm building.

I have a method like this:

getEveryone(event) {
                axios.get('/chat/users/' + this.property)
                    .then((response) => {

                        let user_groups = response.data;
                        user_groups.map((user_groups) => {
                            console.log(user_groups);
                            this.users.push(user_groups);
                        });
                    });
            },

Which is a get request to get users associated with a company but it's no longer showing the user etc, and before it did work and I could select a user, but it wouldn't store the IDs of multiple users.

I have the following store method on my controller that is responsible for this:

public function store()
    {
        $group = Group::create(['name' => request('subject'), 'subject' => request('subject')]);

        $users = collect(request('users'));
        $users->push(auth()->user()->id);
        $group->users()->attach($users->pluck('id'));

        broadcast(new GroupCreated($group))->toOthers();
        return $group;
    }

I have the following with the template:

<div class="form-check" v-model="users" v-for="(user, index) in users" :key="index">
                        <input class="form-check-input" type="checkbox" id="inlineCheckbox1" :value="user.id" >
                        <label class="form-check-label" for="inlineCheckbox1">{{ user.name }} <span class="text-dark">({{ user.account_type | capitalize }})</span></label>
                    </div>

Then also the method to store the new chat group

createGroup() {
                axios.post('/groups', {subject: this.subject, users: this.users})
                    .then((response) => {
                        this.subject = '';
                        this.selected = [];
                        Bus.$emit('groupCreated', response.data);

                        location.reload();
                });
                location.reload();
            }

As you can see from this screen shot the creating of a group is the problem:

I believe looking at the package I'm using https://github.com/viraj-khatavkar/group-chat-app-laravel-pusher the group creation should just be a bunch of IDs as it's a pivot table. But I've been trying to resolve this for the past 2 days, to no avail; so looking to this awesome community to help a brother out ;)

12 Feb
2 months ago

theUnforgiven left a reply on Help With Name Field W/VueJS Saving As Array?

I can't use axios in this case as I said the component is wrapped with the form tag anyhow and I save all the data at the same time.

11 Feb
2 months ago

theUnforgiven left a reply on Help With Name Field W/VueJS Saving As Array?

@realrandyallen so what you are saying is not wrong, but not what I require.

theUnforgiven left a reply on Help With Name Field W/VueJS Saving As Array?

The vue component is part of the form, but I want the Vue component to be responsible for adding new rows and such, then save these values.

theUnforgiven left a reply on Help With Name Field W/VueJS Saving As Array?

Apologies, I should have mentioned that the vue view is within a regular form tag as follows, as there's more stuff I collect and save on the same page:

<form method="POST" action="{{ route('company.profile.edit', $company) }}" enctype="multipart/form-data">

theUnforgiven left a reply on Help With Name Field W/VueJS Saving As Array?

How would I then get the parsed computed into my request obj?

theUnforgiven left a reply on Help With Name Field W/VueJS Saving As Array?

Sure

<template>
    <div>
        <div v-for="(input, index) in inputs" :key="index">
            <div class="row">
                <div class="col">
                    <div class="form-group">
                        <input type="text" 
                            class="form-control" 
                            :id="input.id" 
                            v-model="input.item" 
                            :name="'fees['+index +input.item+']'"
                            placeholder="Enter any new fees here"
                        >
                    </div>
                </div>

                <div class="col">
                    <div class="form-group">
                        <div class="input-group mb-3">
                            <div class="input-group-prepend">
                              <div class="input-group-text">£</div>
                            </div>
                            <input type="number" 
                                class="form-control" 
                                placeholder="0.00" 
                                :id="input.id" 
                                v-model="input.amount" 
                                :name="'fees['+index + input.amount+']'"
                            >
                            <button v-on:click.prevent="removeInput(input.id)" 
                                    class="btn btn-sm btn-danger">
                                    <i class="fa fa-trash"></i>
                            </button>
                        </div>   
                    </div>
                </div>
            </div>
        </div>
        
        <button class="btn btn-sm btn-outline-secondary mt-1 mb-3" @click="addInput">Add new fee</button>
    </div>
</template>

<script>

    export default {

        data() {
            return {
                counter: 0,
                inputs: [{
                    id: '',
                    item: '',
                    amount: '',
                    value: ''
                }],
            }
        },

        methods: {
            addInput(e) {
                e.preventDefault();
                this.inputs.push({
                    id: `item${++this.counter}`,
                    item: '',
                    amount: '',
                    value: ''
                });
            },
            removeInput : function (input) {
                this.inputs.splice(input, 1);
            }
        }
    }

</script>

Basically it adds new rows, so the name fields I want to be like I explain within the array above when I save the data from my Laravel controller

theUnforgiven left a reply on Help With Name Field Within A Form W/VueJS

Anyone, willing to help out please, I know it's something simple I'm missing

theUnforgiven left a reply on Help With Name Field Within A Form W/VueJS

Can anyone shed any light on this please?

10 Feb
2 months ago

theUnforgiven left a reply on Help With Name Field Within A Form W/VueJS

Anyone, willing to help out please, I know it's something simple I'm missing

09 Feb
2 months ago

theUnforgiven left a reply on Help With Name Field Within A Form W/VueJS

I have just tried the following: :name="'fees['+index + input.item+']'"

But that results in

 "fees" => array:5 [▼
    "admin" => "10.00"
    "reminder" => "40.00"
    "bank" => "50.00"
    "0qwerty" => "qwerty"
    "0123" => "123"
  ]

Which is still not right like I said it should be "qwerty" => "123"

theUnforgiven started a new conversation Help With Name Field Within A Form W/VueJS

I have the following form in a Vue file:

<div v-for="(input, index) in inputs" :key="index">
            <div class="row">
                <div class="col">
                    <div class="form-group">
                        <input type="text" 
                            class="form-control" 
                            :id="input.id" 
                            v-model="input.item" 
                            placeholder="Enter any new fees here"
                        >
                    </div>
                </div>

                <div class="col">
                    <div class="form-group">
                        
                        <div class="input-group mb-3">
                            <div class="input-group-prepend">
                              <div class="input-group-text">£</div>
                            </div>
                            <input type="number" 
                                class="form-control" 
                                placeholder="0.00" 
                                :id="input.id" 
                                v-model="input.amount" 
                            >
                            <button v-on:click.prevent="removeInput(input.id)" class="btn btn-sm btn-danger" onclick="return confirm('Are you sure you want to remove this?')"><i class="fa fa-trash"></i></button>
                        </div>   
                    </div>
                </div>
            </div>
        </div>

Once the form is submitted I want to have name values like this is from another element within the same form. Basically add to this array with what the user types in the first input and then the fee amount in the amount field.

 "fees" => array:4 [▼
    "admin" => "10.00"
    "reminder" => "40.00"
    "bank" => "50.00"
  ]

I did try :name="'fees[' + input.item + ']'" but this results in:

"fees" => array:5 [▼
    "admin" => "10.00"
    "reminder" => "40.00"
    "bank" => "50.00"
    "new item" => "new item" // wrong
    0 => "99" // wrong
    // should be 
    "new item" => "99"
  ]

Can anyone help me on what the name field should be please J

24 Jan
3 months ago

theUnforgiven left a reply on Pivot Data On Query

Yes I just realised this hehe

theUnforgiven left a reply on Pivot Data On Query

I get Trying to get property of non-object on line 19 which responds to $query->where('id', '<>', $auth_user->company->id);

Based on:

$auth_user = user(); //auth()->user();
    return User::orderBy('name')
                    ->where('id', '!=', $auth_user->id)
                    ->whereHas('company', function ($query) use($auth_user) {
                          $query->where('id', '<>', $auth_user->company->id);
                    })
                    ->get();

theUnforgiven left a reply on Pivot Data On Query

User Model

public function company()
{
        return $this->belongsTo(Company::class);
}

Company Model

 public function users()
{
        return $this->hasMany(User::class, 'company_user', 'user_id', 'id');
}

Then within my controller I call

return Company::with('users')->where('owner_id', '=', user()->companies()->first()->id)->orderBy('name')->get();

Should be get all users associated with the authenticated user's company id like user()->companies()->first()->id shows