theUnforgiven

theUnforgiven

Member Since 5 Years Ago

UK

Web Developer at NRS

Experience Points 270,820
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 1495
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.

13 Jun
4 days ago

theUnforgiven left a reply on Problem With V-model On Message Input & IsTyping Indicator

But then how would the rest of the repsonse be rendered in that case?

theUnforgiven left a reply on Problem With V-model On Message Input & IsTyping Indicator

No that doesn't work either and i don't particularly want to go down that road, what I have setup already does work 90%

theUnforgiven left a reply on Problem With V-model On Message Input & IsTyping Indicator

That just shows Cannot read property 'message' of undefined

theUnforgiven left a reply on Problem With V-model On Message Input & IsTyping Indicator

No, I don't think that will work, as I push the response into this array also.

theUnforgiven left a reply on Problem With V-model On Message Input & IsTyping Indicator

My data obj is:

data() {
            return {
                group_id: this.group.id,
                conversations: [],
                typing: false,
                user: '',
                message: '',
                groups: []
            }
        },

theUnforgiven left a reply on Problem With V-model On Message Input & IsTyping Indicator

It seems that after playing around again for a couple of hours, it's something to do with Authorization on the channels.php class.

Or maybe something else, i've missed not sure!!!

But The conversation list shows now, typing indicator still doesn't and the input doesn't clear either, but again think this is linked to the same problem.

I've just tried again to got the following error

[Vue warn]: Error in render: "TypeError: Cannot read property 'account_type' of undefined"

found in

---> <GroupChat> at resources/assets/js/laravel/components/GroupChat.vue
       <Groups> at resources/assets/js/laravel/components/Groups.vue
         <Root>

Which relates to this piece of code:

<div class="panel-body chat-panel">
                                <ul class="list-unstyled">
                                    <li class="media" v-for="(conversation,index) in conversations" :key="index">
                                        <i class="far fa-user mr-3 img-thumbnail"></i>
                                        <div class="media-body">
                                            <h5 class="mt-0 mb-1">{{ user }} ({{ conversation.user.account_type | capitalize }})</h5>
                                            <p>
                                                {{ conversation.message }}<br />
                                                <small class="text-muted pt-1">{{ conversation.created_at | formatDate }}</small>
                                            </p>
                                        </div>
                                    </li>
                                </ul>
                                <span v-show="typing" class="help-block" style="font-style: italic;">
                                    {{ user.name }} is typing...
                                </span>
                            </div>

Which comes from the GET response which does have all the user details in etc, so not sure why it's not rendering.

Which you can see from the response in the network tab:

created_at: "2019-06-13 12:16:57"
group_id: 127
id: 363
message: "skjdhff"
updated_at: "2019-06-13 12:16:57"
user: {id: 126, membership_number: "SBM02101925", title: null, name: "Del Trotter", ema...

theUnforgiven left a reply on Problem With V-model On Message Input & IsTyping Indicator

I'm still having issues with the typing indicator and the message not clearing and updating in realtime, even though as you can see from the last image I posted, Pusher is been notified so this obviously as something to do with the Vue file, but I'm unsure as to what.

12 Jun
5 days ago

theUnforgiven left a reply on Problem With V-model On Message Input & IsTyping Indicator

Pusher is showing typing indicator and the message, but the chat isn't updating in realtime, i did forgot to run queue:listen, but that's made no difference :)

theUnforgiven left a reply on Problem With V-model On Message Input & IsTyping Indicator

Yes this is true, been trying for the past 2 hrs lol

theUnforgiven left a reply on Problem With V-model On Message Input & IsTyping Indicator

Nope and the message isn't been pushed into the list and the input isn't been emptied after submitting either, really weird this.

theUnforgiven left a reply on Problem With V-model On Message Input & IsTyping Indicator

isTyping() {
                let channel = Echo.private('groups.' + this.group.id);
                this.typing = true // set to true here
                setTimeout(function() {
                    channel.whisper('typing', {
                        user: Laravel.userName,
                        typing: true
                    });
                }, 3500);

                
            },

And nothing and yes removed ()

<input
                                        type="text" 
                                        class="form-control input-sm chat-input" 
                                        placeholder="Type your message here..." 
                                        v-model="message" 
                                        @keyup.enter="store" 
                                        @keydown="isTyping" 
                                    >
                                    <span class="input-group-btn">
                                        <button class="btn btn-success" 
                                                style="border-radius: 0px 10px 10px 0px!important;" 
                                                @click.prevent="store"
                                        >
                                        <i class="far fa-paper-plane"></i> Send
                                        </button>
                                    </span>

theUnforgiven left a reply on Problem With V-model On Message Input & IsTyping Indicator

isTyping method also is set oto true:

isTyping() {
                let channel = Echo.private('groups.' + this.group.id);
                
                setTimeout(function() {
                    channel.whisper('typing', {
                        user: Laravel.userName,
                        typing: true // true here
                    });
                }, 3500);
            },

theUnforgiven left a reply on Problem With V-model On Message Input & IsTyping Indicator

Ok, added that, but still nothing, also I have in the store method

store() {
                axios.post('/conversations', {message: this.message, group_id: this.group.id})
                .then((response) => {
                    
                    this.conversations.push(response.data);
                    this.message = ''; // To empty the message out, but this isn't working either, and doesn't seem to be posting to the server, but checking the network tab I see it is and is 200 response.
                });
            },

theUnforgiven left a reply on Problem With V-model On Message Input & IsTyping Indicator

Typing in the input something then opening up dev tools it does then show message:"something" And the isTyping still not working.

theUnforgiven left a reply on Problem With V-model On Message Input & IsTyping Indicator

As for the isTyping I have @keydown="isTyping" on the input

theUnforgiven left a reply on Problem With V-model On Message Input & IsTyping Indicator

Yes, I was tinkering around before posting here, but removed both () from both the input and button

theUnforgiven left a reply on Problem With V-model On Message Input & IsTyping Indicator

Figured i quickly show that dev tools is open and I can confirm is working and refreshed, but have a look at this screen cast - https://www.dropbox.com/s/ng158s8oxny3s2r/chat.mov?dl=0

Hitting the button for the store method seems to do nothing, but if I check Pusher and the database I can see the typing indicator works and also the message was sent to Pusher and also the db.

theUnforgiven left a reply on Problem With V-model On Message Input & IsTyping Indicator

Anyone willing to help a brother out please? :-)

theUnforgiven started a new conversation Problem With V-model On Message Input & IsTyping Indicator

Hi all,

I have a problem with a v-model on “message” input and isTyping. As the code is quite long I made a gist - https://gist.github.com/lstables/1ffdbe4e2d1c19015862b9398f7024e6

As you can see below. the message is empty and even when I was typing the isTyping is still set to false.

I’m guessing this is because it should be within the groups array, so question is how does one get this working so the typing indicator and message inputs works, as this should be realtime using Pusher, which Pusher is receiving the typing indicator and message, but Vue isn’t doing as it should, obviously my mistake, so hoping you wonderful lot will help me out here :slight_smile:

11 Jun
6 days ago

theUnforgiven left a reply on JSON Into A V-for Select Dropdown [HELP]

Yeah, my bad bloody thing! Thanks anyhow dude, greatly appreciated for your help :)

theUnforgiven left a reply on JSON Into A V-for Select Dropdown [HELP]

Think I may have found the problem, arrgghh!!

Just checked the db and this is the JSON that gets saved

[{"id":1,"unit_no":"1","floor":"1","landlord":"hghg","landlord_email":"[email protected]","agent":null,"agent_email":null},{"id":2,"unit_no":"2","floor":"1","landlord":"hghg","landlord_email":"[email protected]","agent":null,"agent_email":null},{"id":3,"unit_no":"3

Because the col was set to varchar, it's not saved the remaining characters, school boy error.

It works now! OMG not a good start to the day for me :(

theUnforgiven left a reply on JSON Into A V-for Select Dropdown [HELP]

I tried that also if you look at my original post, which gave me

Uncaught (in promise) SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)

which is why then I wrapped in JSON.stringify

theUnforgiven left a reply on JSON Into A V-for Select Dropdown [HELP]

![]|(https://imgur.com/HHfqlcA.png) as the payload is only thing I'm interested in.

theUnforgiven left a reply on JSON Into A V-for Select Dropdown [HELP]

Tried that and results in lots of empty () which isn't right. Upon selecting the block, it should then show unit no and floor for each on in that object.

theUnforgiven left a reply on JSON Into A V-for Select Dropdown [HELP]

@simon1709 - console log for payload is:

{"id":1,"unit_no":"1","floor":"1","landlord":"hghg","landlord_email":"[email protected]","agent":null,"agent_email":null},{"id":2,"unit_no":"2","floor":"1","landlord":"hghg","landlord_email":"[email protected]","agent":null,"agent_email":null},{"id":3,"unit_no":"3

theUnforgiven started a new conversation JSON Into A V-for Select Dropdown [HELP]

I have the following from a JSON get request:

units:Array[1]
0:"{"id":1,"unit_no":"1","floor":"1","landlord":"hghg","landlord_email":"[email protected]","agent":null,"agent_email":null},{"id":2,"unit_no":"2","floor":"1","landlord":"hghg","landlord_email":"[email protected]","agent":null,"agent_email":null},{"id":3,"unit_no":"3"....

I now want to add the unit_no and floor in a v-for loop within a select.

But the following doesn't work

<select v-model="unitSelection" class="form-control">
      <option>Please select</option>             
      <option v-for="unit in units" :value="unit.id" :key="unit.id">
              {{ unit.unit_no }} ({{ unit.floor }})
      </option>
</select>

Where am I going wrong?

10 Jun
1 week ago

theUnforgiven left a reply on Passing Vue Arrays To Laravel

Oh yes, I know it is, it's just that transition from using jQuery for so long to something new.

theUnforgiven left a reply on Passing Vue Arrays To Laravel

@maverickchan Yes, I realised this just a couple of hours ago, I'm still learning Vue on the job so this as been one great learning curve. But having done what you suggested like I said I realised this a couple of hour ago, all is good and works. But I will howver give you the "correct answer" credit as it's a good answer anyways.

theUnforgiven left a reply on Passing Vue Arrays To Laravel

My form as <form id="form" @submit.prevent="submit"> also and everything is wrapped inside this

theUnforgiven started a new conversation Passing Vue Arrays To Laravel

I have the following data in my Vue file, of which I need to pass to Laravel in order to save the data.

I have a method like so:

 submit(e) {
      var form = document.getElementById("form");
      var formData = new FormData(form);

      axios.post("/block/save", formData).then(
        response => {
          // success callback
          console.log("Success");
        },
        response => {
          // error callback
          console.log("ERROR!");
          console.log(response.data);
        }
      );
    }

Then dd() $request->all(); shows the following:

 "block_name" => "fsd"
  "no_of_units" => "3"
  "floors" => "2"
  "lift" => "no"
  "address" => "Some Address Two"
  "facility" => array:4 [
    0 => "fob"
    1 => "gate_entry"
    2 => "finger"
    3 => "bike_storage"
  ]
  "block" => array:1 [
    "unit" => "3"
  ]

But it's not showing the blocks array in which I need it to so I can save each row.

05 Jun
1 week ago

theUnforgiven left a reply on Help With Vue Cloning

Here's the v-for I have:

<tr v-for="(input, index) in inputs" :key="index">
                                <td><input type="number" v-model="input.unit_no" :id="input.id" value="" class="form-control"></td>
                                <td><input type="number" v-model="input.floor" :id="input.id" value="" class="form-control"></td>
                                <td><input type="text" v-model="input.landlord" :id="input.id" value="" class="form-control"></td>
                                <td><input type="email" v-model="input.landlord_email" :id="input.id" value="" class="form-control"></td>
                                <td><input type="text" v-model="input.agent" :id="input.id" value="" class="form-control"></td>
                                <td><input type="email" v-model="input.agent_email" :id="input.id" value="" class="form-control"></td>
                            </tr>

theUnforgiven started a new conversation Help With Vue Cloning

I have this for adding new rows.

addRows() {
  for (let i = 0; i < this.units; i++) { 
    this.inputs.push(this.newInput);

  }
},

But from the screen shot, when I enter in each of the boxes I get the same value, when in actual fact, they all need to remain empty until a user types something in. I also want those rows to be associated with the index key.

30 May
2 weeks ago

theUnforgiven left a reply on Arrays, Saving Multiple

Anyone willing to help me on this one, and please be gentle, it's been on of those weeks :(

29 May
2 weeks ago

theUnforgiven left a reply on Arrays, Saving Multiple

Theres always one! ?

theUnforgiven left a reply on Arrays, Saving Multiple

Anyone to help me please

theUnforgiven left a reply on Arrays, Saving Multiple

anyone care to help me out and be gentle!

theUnforgiven left a reply on Arrays, Saving Multiple

0

Unable to save arrays with the correct key based on how many inputs the user selects.

I'm sure it the jQuery clone script, but not sure how to put this right as jQuery not my strongest point.

Here's the html:

 <div class="row">
        <div class="col">
            <div class="form-group">
                <label>Block Name</label>
                <input type="text" name="name_of_blocks[]" class="form-control">
            </div>
        </div>
        <div class="col">
            <label>No of units in the block</label>
            <input type="number" name="no_units[]" class="form-control" id="blockNo">
        </div>
        <div class="col">
            <label>Number of floors</label>
            <input type="number" class="form-control" name="no_of_floors[]">
        </div>
        <div class="col">
            <label>Does this block have a lift?</label>
            <select class="form-control" name="lift[]">
                <option>Please Select</option>
                <option value="yes">Yes</option>
                <option value="no">No</option>
            </select>
        </div>
 </div>

 <div class="row">
        <div class="col">
            <label>What facilities does this block have?</label>
            <div class="row">
                <div class="col">
                    <ul class="list-unstyled">
                        <li><input type="checkbox" name="facilities[]" value="fob"> Fob Entry</li>
                        <li><input type="checkbox" name="facilities[]" value="gate_entry"> Gate Entry</li>
                        <li><input type="checkbox" name="facilities[]" value="key"> Key Entry</li>
                        <li><input type="checkbox" name="facilities[]" value="finger"> Fingerprint Entry</li>
                        <li><input type="checkbox" name="facilities[]" value="Code Entry"> Code Entry</li>
                        <li><input type="checkbox" name="facilities[]" value="mailbox"> Mailbox Area</li>
                    </ul>
                </div>
                <div class="col">
                    <ul class="list-unstyled">
                        <li><input type="checkbox" name="facilities[]" value="bar"> Bar</li>
                        <li><input type="checkbox" name="facilities[]" value="bike_storage"> Bike Storage</li>
                        <li><input type="checkbox" name="facilities[]" value="car_park"> Secure Car Parking</li>
                        <li><input type="checkbox" name="facilities[]" value="off_road"> Off-road Parking</li>
                        <li><input type="checkbox" name="facilities[]" value="visitor_parking"> Visitor Parking</li>
                        <li><input type="checkbox" name="facilities[]" value="concierge"> Concierge</li>
                    </ul>
                </div>
                <div class="col">
                    <ul class="list-unstyled">
                        <li><input type="checkbox" name="facilities[]" value="gym"> Gym</li>
                        <li><input type="checkbox" name="facilities[]" value="pool"> Swimming Pool </li>
                        <li><input type="checkbox" name="facilities[]" value="snooker"> Snooker/Pool Table</li>
                        <li><input type="checkbox" name="facilities[]" value="cafe"> Cafe</li>
                        <li><input type="checkbox" name="facilities[]" value="maintenance"> Maintenance Service</li>
                        <li><input type="checkbox" name="facilities[]" value="various"> Various businesses/commercial outlets</li>
                    </ul>
                </div>

Heres what I have in my controller, but this either doesn't save correctly or saves one row if there's two and doesn't save the correct info:

$data = $request->all();
$count = $data['number_of_blocks'];
for ($i = 0; $i < $count; $i++) {

    $blok = new Blocks;
    $blok->block_id = $block->id;
    $blok->name_of_blocks = array_key_exists($i, $data['name_of_blocks']) ? $data['name_of_blocks'][$i] : null;
    $blok->no_units = array_key_exists($i, $data['no_units']) ? $data['no_units'][$i] : null;
    $blok->no_of_floors = array_key_exists($i, $data['no_of_floors']) ? $data['no_of_floors'][$i] : null;
    $blok->lift = array_key_exists($i, $data['lift']) ? $data['lift'][$i] : null;
    $blok->facilities = array_key_exists($i, $data['facilities']) ? $data['facilities'][$i] : null;
    $blok->save();
}

I do have some clone script to clone the amount of form fields based on how many the user wants, so this could also be a problem, but I'm not sure what or where:

$("#continue").click(function () {
    $("#first").hide();
    $("#second").show();

    var blocks = $("#noBlocks").val();
    var name = $("#blockName").val();
    $(".clone").hide();
    var select = parseInt(blocks, 10);
    var $clone = $('.clone').html();
    var html = '';
    while (select > 0) {
        html += $clone;
        select--;
    }

    $("#area").empty().html(html);

    $("#bno").html(blocks);
    $("#bn").html(name);
});

Basically if the user selects 2 then I want the code to save two rows and the facilities to be json encoded for each row, and match what the user selects. Any help advice greatly appreciated.

23 May
3 weeks ago

theUnforgiven left a reply on Moving From Joomla Framework To Laravel

Right here on Laracasts. There's a ton of videos.

22 May
3 weeks ago

theUnforgiven left a reply on Re-useable Vue Popover/tooltip

@MAVERICKCHAN - Yeah I get that, but don't want to use jQuery at all. I'll grab one from the net and adopt my needs, was just looking for some pointers from your wonderful people. :)

theUnforgiven left a reply on Re-useable Vue Popover/tooltip

I was using Boostraps native tooltip, but it's having some conflicts with another file and it's all from a Bootstrap template I bought, but I also want to do away with the majority of Bootstrap's JS and jQuery and convert to Vue

20 May
4 weeks ago

theUnforgiven started a new conversation Re-useable Vue Popover/tooltip

Can anyone point me in the right direction to something or how to build a vue component for a tooltip or popover that is reusable, allowing me to send the direction and the text content to display.

I\ve googled but they are all packages and stuff and really want to write something tailored to my needs and try and use less packages.

17 May
1 month ago

theUnforgiven left a reply on Signature Pad

Not related but I saw:

$(function(){
            $('#datepicker').datepicker();
            });
        $(function(){
            $('#datepicker1').datepicker();
            });
        $(function(){
            $('#datepicker2').datepicker();
            });
        $(function(){
            $('#datepicker3').datepicker();
            });

That you could reduce to just $('.datepicker').datepicker(); change from ID to a class, then you aren't duplicating on the same code.

As for the signature pad, from what I can see quickly, looks ok to me and did you follow the docs through on the github repo?

15 May
1 month ago

theUnforgiven left a reply on Signature Pad

Sorry without seeing the JS and view file in full etc I can't really help

theUnforgiven left a reply on Arrays, Saving Multiple

@CRONIX - Cool, thanks I'll give that a try. Presume that will work also based on the form I posted regardless?

theUnforgiven left a reply on Arrays, Saving Multiple

Is there an easy way to achieve this in that case?

Here's the form in question:

<div class="clone">
                            <div class="row">
                                <div class="col">
                                    <div class="form-group">
                                        <label>Block Name</label>
                                        <input type="text" name="name_of_blocks[]" class="form-control">
                                    </div>
                                </div>
                                <div class="col">
                                    <label>No of units in the block</label>
                                    <input type="number" name="no_units[]" class="form-control" id="blockNo">
                                </div>
                                <div class="col">
                                    <label>Number of floors</label>
                                    <input type="number" class="form-control" name="no_of_floors[]">
                                </div>
                                <div class="col">
                                    <label>Does this block have a lift?</label>
                                    <select class="form-control" name="lift[]">
                                        <option>Please Select</option>
                                        <option value="yes">Yes</option>
                                        <option value="no">No</option>
                                    </select>
                                </div>
                            </div>

                            <div class="row">
                                <div class="col">
                                    <label>What facilities does this block have?</label>
                                    <div class="row">
                                        <div class="col">
                                            <ul class="list-unstyled">
                                                <li><input type="checkbox" name="facilities[]" value="fob"> Fob Entry</li>
                                                <li><input type="checkbox" name="facilities[]" value="gate_entry"> Gate Entry</li>
                                                <li><input type="checkbox" name="facilities[]" value="key"> Key Entry</li>
                                                <li><input type="checkbox" name="facilities[]" value="finger"> Fingerprint Entry</li>
                                                <li><input type="checkbox" name="facilities[]" value="Code Entry"> Code Entry</li>
                                                <li><input type="checkbox" name="facilities[]" value="mailbox"> Mailbox Area</li>
                                            </ul>
                                        </div>
                                        <div class="col">
                                            <ul class="list-unstyled">
                                                <li><input type="checkbox" name="facilities[]" value="bar"> Bar</li>
                                                <li><input type="checkbox" name="facilities[]" value="bike_storage"> Bike Storage</li>
                                                <li><input type="checkbox" name="facilities[]" value="car_park"> Secure Car Parking</li>
                                                <li><input type="checkbox" name="facilities[]" value="off_road"> Off-road Parking</li>
                                                <li><input type="checkbox" name="facilities[]" value="visitor_parking"> Visitor Parking</li>
                                                <li><input type="checkbox" name="facilities[]" value="concierge"> Concierge</li>
                                            </ul>
                                        </div>
                                        <div class="col">
                                            <ul class="list-unstyled">
                                                <li><input type="checkbox" name="facilities[]" value="gym"> Gym</li>
                                                <li><input type="checkbox" name="facilities[]" value="pool"> Swimming Pool </li>
                                                <li><input type="checkbox" name="facilities[]" value="snooker"> Snooker/Pool Table</li>
                                                <li><input type="checkbox" name="facilities[]" value="cafe"> Cafe</li>
                                                <li><input type="checkbox" name="facilities[]" value="maintenance"> Maintenance Service</li>
                                                <li><input type="checkbox" name="facilities[]" value="various"> Various businesses/commercial outlets</li>
                                            </ul>
                                        </div>

                                    </div>
                                </div>
                            </div>
                            <br />
                            <hr />
                            <br />
                        </div>

theUnforgiven left a reply on Arrays, Saving Multiple

There was only 1 as I only entered one at the time, as some inputs will have data and some won't but the new db rows should be entered still the same just with null values.

theUnforgiven left a reply on Arrays, Saving Multiple

Thanks @cronix I'll give that a go.

I'm basically showing another form from a previous form, this form will have a certain amount of duplicated inputs based on user's previous selection. I use jQuery to clone the inputs based on their inputs. Then I want to save each one as a row within the db, hope this make sense.

theUnforgiven left a reply on Arrays, Saving Multiple

Anyone? Sorry for such a school boy question, but just having a massive mental block

14 May
1 month ago

theUnforgiven started a new conversation Arrays, Saving Multiple

I have the following, and I want to save then as individual rows as they will be related to a block

array:5 [▼
  "name_of_blocks" => array:4 [▼
    0 => null
    1 => "test1"
    2 => "test2"
    3 => "test3"
  ]
  "no_units" => array:4 [▶]
  "no_of_floors" => array:4 [▼
    0 => null
    1 => "2"
    2 => "2"
    3 => "3"
  ]
  "lift" => array:4 [▼
    0 => "Please Select"
    1 => "no"
    2 => "no"
    3 => "yes"
  ]
  "facilities" => array:1 [▼
    0 => "visitor_parking"
  ]
]

How does one save these again I'm forgot and having a major meltdown about it lol

I have tried the following but this fails:

$data = $request->except('_token');

        for($i = 0; $i < count($data); $i++){
            $block = new Blocks;
            $block->name_of_blocks = $name[$i];
            $block->no_units = $units[$i];
            $block->no_of_floors = $floors[$i];
            $block->lift = $lift[$i];
            $block->facilities = $facilities[$i];
            $block->save();
        }