petritr

Experience

2,960

0 Best Reply Awards

  • Member Since 3 Weeks Ago
  • 0 Lessons Completed
  • 0 Favorites

19th September, 2018

petritr left a reply on How Can I Display The Relation Data In Vue.js • 7 hours ago

i got it User::with('relation')->get() needed to pass the relation data too.

petritr left a reply on Fetch All Model Records With Relation • 13 hours ago

Okay got it User::with('relation')->get()

petritr started a new conversation Fetch All Model Records With Relation • 13 hours ago

How can i fetch all model records with relation ?

i get get single record, but i need all?

User::find(1)->relation();

This will work with one records, how to return all with relation ?

petritr started a new conversation How Can I Display The Relation Data In Vue.js • 14 hours ago

I have the id of the related data vue.js

jobs related table i have jobs_id

How can i loop through the other data in vue when i have the id ?

How can i display the job name in vue ?

jobs_id = 1

How can i loop though other column data ?
```

18th September, 2018

petritr started a new conversation Loop Json In Vue 2 Component • 1 day ago

I have imported an Vue component and my goal is to use this component:

https://github.com/moreta/vue-search-select

I have problem passing the json data to the component.

data() {
    return {
        options: [
        ],
        searchText: '',
        item: {
            name: '',
            id: ''
        }
    }
},

I read the data with axios

axios.get('/api/users').then(({ data }) => {
    console.log(data)
    this.options = data;

})

the console log with return the data like:

0:{…}
1:{…}
2:{…}

Inside the first json

0:
id:(...)
information:(...)
address:(...)
zip:(...)

I need to pass the data like its in the example:

options: [
          { value: '1', text: 'aa' + ' - ' + '1' },
          { value: '2', text: 'ab' + ' - ' + '2' },
          { value: '3', text: 'bc' + ' - ' + '3' },
          { value: '4', text: 'cd' + ' - ' + '4' },
          { value: '5', text: 'de' + ' - ' + '5' }
],

How can pass the axios data like this ?

petritr left a reply on SQLSTATE[23000]: Integrity Constraint Violation: Foreign Key • 1 day ago

If the other_id value dons't exist in the others table then the error will be fired. So no problem, just the value was no in the others table where i wanted to have the relation.

petritr left a reply on SQLSTATE[23000]: Integrity Constraint Violation: Foreign Key • 1 day ago

The primary key on the other table is other_id i have changed. I don't have idcolumn

petritr started a new conversation SQLSTATE[23000]: Integrity Constraint Violation: Forign Key • 1 day ago

I have the following as forign key on database migration file:

            $table->integer('other_id');
            $table->foreign('other_id')->references('other_id')->on('others');
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails 

Why i get this error on save ?

17th September, 2018

petritr left a reply on Update Inputs With Same Name Repeated • 2 days ago

Okay i got it i was a bit confuse but i got with @tykus loop.

        foreach ($devices_update["device_id"] as $index => $device) {

            $id = ($devices_update["device_id"][$index]);
            $name = ($devices_update["device_name"][$index]);
            $type = ($devices_update["device_type"][$index]);
            $modul_1 = ($devices_update["device_modul_1"][$index]);
         ...

            $DeviceForSave = Device::find($id);

            $DeviceForSave->name = $name;
            $DeviceForSave->type = $type;
            $DeviceForSave->usage = $type;
            ...

            $DeviceForSave->save();

        }

petritr left a reply on Update Inputs With Same Name Repeated • 2 days ago

okay:

"ErrorException"
file
:
"/var/www/dir/app/app/Http/Controllers/DevicesController.php"
line
:
84
message
:
"Non-static method Illuminate\Database\Eloquent\Model::update() should not be called statically"
trace
:
[{file: "/var/www/dir/app/app/Http/Controllers/DevicesController.php", line: 84,…},…]
0
:
{file: "/var/www/dir/appy/app/Http/Controllers/DevicesController.php", line: 84,…}
1
:
{function: "update_devices", class: "oderentry\Http\Controllers\DevicesController", type: "->"}
2
:
{file: "/var/www/dir/app/vendor/laravel/framework/src/Illuminate/Routing/Controller.php",…}
3
:
{,…}

petritr left a reply on Update Inputs With Same Name Repeated • 2 days ago

im using laravel 5.6 i have tired both version that you send i got errors for both:

            $deviceModel = Device::find($device['device_id']);
            $deviceModel->fill($device);
            $deviceModel->save();

error: "Creating default object from empty value"

            Device::update($device['device_id'], $device);

error: "Non-static method Illuminate\Database\Eloquent\Model::update() should not be called statically"

petritr left a reply on Update Inputs With Same Name Repeated • 2 days ago

My goal is to update all inputs that are returned from the array @Yorki If i get back 2 different device_id then update both, if one update one, if four update for.

petritr left a reply on Update Inputs With Same Name Repeated • 2 days ago

Any idea why i don't get both arrays when i loop thou them? I don't get this! :/

petritr left a reply on Update Inputs With Same Name Repeated • 2 days ago

I get this:

array:6 [
  0 => "device_id"
  1 => "device_name"
  2 => "device_type"
  3 => "device_modul_1"
]

dd after for :

        for ($i = 0; $i < count($devices['device_id']); $i++) {
            $device = [];

            foreach ($keys as $key) {
                $device[$key] = $devices[$key][$i];
            }
            dd($keys);
            //Device::findOrFail($device['device_id'])->update($device);
        }

petritr left a reply on Update Inputs With Same Name Repeated • 2 days ago

Here it is:

        $devices = $request->all();

        //dd($devices); this will return 2 arrays

        $keys = array_keys($devices);

        for ($i = 0; $i < count($devices['device_id']); $i++) {
            $device = [];

            foreach ($keys as $key) {
                $device[$key] = $devices[$key][$i];
            }
            //dd($device); this will return only one
            Device::findOrFail($device['device_id'])->update($device);
        }

petritr left a reply on Update Inputs With Same Name Repeated • 2 days ago

Yes i did use it findOrFail and i got that error Creating default object from empty value

on dd i get only one array i don't get both i don't understand this. Why?

petritr left a reply on Update Inputs With Same Name Repeated • 2 days ago

Now i get "Creating default object from empty value" both versions, im using laravel 5.6.

Uggghhhhh...

petritr left a reply on Update Inputs With Same Name Repeated • 2 days ago

Why i get alway only one device_id even in normal foreach loop and here both examples will return only one device_id i got get it.

petritr left a reply on Update Inputs With Same Name Repeated • 2 days ago

@Yorki I got back "Non-static method Illuminate\Database\Eloquent\Model::update() should not be called statically"

petritr left a reply on Update Inputs With Same Name Repeated • 2 days ago

Okay i see changed to double quotes, on dd again i do of the device_idonly 1

Should i got back two id?

petritr left a reply on Update Inputs With Same Name Repeated • 2 days ago

@tykus can you post also the update method?

When i do dd($id);i get "Use of undefined constant ‘device_id’ - assumed '‘device_id’' (this will throw an Error in a future version

Im confused :/

petritr left a reply on Update Inputs With Same Name Repeated • 2 days ago

Any help for me ?

petritr started a new conversation Update The Inputs With Same Name Repeated • 2 days ago

I have the following in the view:

@foreach ($devices as $index => $device)

    <input type="text" name="device_id_update[]" value="{{ $device->device_id }}">
    <input type="text" name="device_name_update[]" value="{{ $device->name }}">
    <input type="text" name="device_type_update[]" value="{{ $device->type }}">
    <input type="text" name="device_modul_1_update[]" value="{{ $device->modul_1 }}">

@endforeach
```

The inputs are repeated, i need to update each input based on the `device_id_update`
The array look like:

```
array:6 [
  "device_id" => array:2 [
    0 => "1"
    1 => "2"
  ]
  "device_name" => array:2 [
    0 => "Device 1"
    1 => "Device 2"
  ]
  "device_type" => array:2 [
    0 => "Type 1"
    1 => "Type 2"
  ]
  "device_modul_1" => array:2 [
    0 => "Modul 1"
    1 => "Modul 2"
  ]
]
```

I need to update each inputs based on the id in the controller i have:

```
$devices = $request->all();

    foreach ($devices['device_id'] as $device ) {
            $saveDevice = Device::find($device);
        }
        foreach ($devices['device_name'] as $device_name ) {
            $saveDevice->name = $device_name;
        }
    ....
```

This will update only the last last input, how can i update each input based on the id.
This will grab only one device_id also, im stuck here.

petritr started a new conversation Saving Array Laravel • 2 days ago

I have an array like this:

array:6 [
  "device_id" => array:2 [
    0 => "1"
    1 => "2"
  ]
  "device_name" => array:2 [
    0 => "Device 1"
    1 => "Device 2"
  ]
  "device_type" => array:2 [
    0 => "Type 1"
    1 => "Type 2"
  ]
  "device_modul_1" => array:2 [
    0 => "Modul 1"
    1 => "Modul 2"
  ]
]

How can i save each value for each id, i have an foreach loop witch as it is would save only for the last array.

$devices = $request->all();

 foreach ($devices['device_id'] as $device ) {
            $saveDevice[] = Device::find($device);

            dd($saveDevice);
            //$deviceForSave = Device::find($hub);
        }
       ......

        $saveDevice->save();

How can i save correctly for each id the correct data ?

14th September, 2018

petritr left a reply on Problem With Foreach On Update/save • 5 days ago

i have the relation working fine, im trying here to update the data on change

petritr left a reply on Problem With Foreach On Update/save • 5 days ago

It will have an single hub_idof course, okay lets go to to my goal. Wow would you save the data when you would have the exactly the same data array as me ? That would be better question and better explanation for me.

petritr left a reply on Problem With Foreach On Update/save • 5 days ago

I men the hub_id in this case was one, this will be dynamic every time will be different ID of course.

my question is how can i save the data in each column correctly when i return an array from serializeArray ? If i separate the array manually then i can same the right value for the right column.

My question is when i get all from data with serializeArray how to save the data in correct column ?

petritr left a reply on Problem With Foreach On Update/save • 5 days ago

Hmm i don't realy understand what you say, i have the problem with saving the data, i get the correct data but i cant save it.

petritr left a reply on Problem With Foreach On Update/save • 5 days ago

I can do this if i check all inputs individually like:

$('[name="name"]').map(function () {
        return $(this).val();
    }).get();
```

But when i use `.serializeArray()`i cant pass the correct data, do i have to have the same name inputs as the database or ? I don't get this quite yet! 

petritr left a reply on Problem With Foreach On Update/save • 5 days ago

If i do this then only the last value would be saved. If i have 2 inputs the last value would be taken.

dd($hub["value"];) will output also only the last input value.

How can i save all values not only the last.

petritr left a reply on Witch Is The Best Way To Listen For Form Input Changes ? • 5 days ago

Thanks, @Cruorzy any faster way in between time ? I have tested a bit with $('#form_name').change(function() { on change method jquery but not working perfectly...

petritr started a new conversation Witch Is The Best Way To Listen For Form Input Changes ? • 5 days ago

I need to check if some inputs of an form have been updated/changed, on submit button.

Any ideas or help, i might have up to 7 inputs per form, either i can have two or more forms in one blade view.

Looking for some advice/help.

13th September, 2018

petritr left a reply on Problem With Foreach On Update/save • 6 days ago

@tykus with $hubs['data'] i would be directly one level deeper in the array we wont need the second array.

As it is now i will get:

message: "Illegal string offset 'value'"

petritr left a reply on Problem With Foreach On Update/save • 6 days ago

I need to update the database, i got that array and i need to update the mode with that array, any easy smart way ?

petritr left a reply on Problem With Foreach On Update/save • 6 days ago

im trying to update the model but still i have problem.

foreach ($Hubs as $hub) {
            foreach ($hub as $value) {
                $array[] = $value['value'];
            }

            foreach ($array as $arr) {
            $hub = Hub::find($hub_id);
            $hub->name = $arr;
            $hub->save();
            }
        }

i get an error converting string to array, this is on my nerves now :) I got the problem here $hub->name = $arr;

petritr started a new conversation Problem With Foreach On Update/save • 6 days ago

I have the following array on dd():

array:2 [
  "data" => array:2 [
    0 => array:2 [
      "name" => "Hub Name"
      "value" => "100"
    ]
    1 => array:2 [
      "name" => "Hub Two"
      "value" => "200"
    ]
  ]
  "hub_id" => "1"
]

I will get invalid foreach:

        foreach ($hubs as $hub) {
            foreach($hub as $values) {

                $hub = Hub::find($hub_id);

                $hub->name = $values["value"];
                $hub->save();
            }
        }

The error: "Invalid argument supplied for foreach()"

What im doing wrong ?

petritr left a reply on Save Data From Multiples Forms In Same View With One Button And Call Different Method • 6 days ago

How can i check with ajax or js for form id before calling ajax ?

petritr left a reply on Save Data From Multiples Forms In Same View With One Button And Call Different Method • 6 days ago

Any better example if possible ?

petritr started a new conversation Save Data From Multiples Forms In Same View With One Button And Call Different Method • 6 days ago

How can i save data from multiples from with one button using ajax.

I have 2 different form with different task in one view blade template and one save button for both forms.

<form id="form_one">
    <input type="text" name="Name" class="form-control my-3" value="{{ $job['Name'] }}">
    .....
</form>

When some input from the first form was saved then call different Method from the same button

<form id="form_two">
    <input type="text" name="title name" class="form-control my-3" value="{{ $title['Name'] }}">
    .....
</form>

Im using ajax to pass the data, how can i call different ajax from one button?

11th September, 2018

petritr left a reply on How Can I Pass The Id In Ajax Url • 1 week ago

I need to grab the id without having to save to js variable then pass if as data, this way i can. I want to do it a bit smarter, just grab it.

petritr left a reply on How Can I Pass The Id In Ajax Url • 1 week ago

jquery, that will output syntax error.

petritr started a new conversation How Can I Pass The Id In Ajax Url • 1 week ago

I need to pass the id in ajax, i have something like:

        url: '{{ URL::route(delete_hub{{id}}) }}',

```

or 

```
 url: '(delete_hub{{id}}',

```

I got an strange url when i call the ajax, how can i pass the id correctly ?

petritr left a reply on Select Input Check Witch Option Is Selected • 1 week ago

@tykus i can see that you have plenty of experience with laravel, what would you recommend me to learn/watch tutorials or anything to improve my laravel skills ? i have watched some tutorials here witch i find great.

Sorry for the question, if you don't mind any feedback would be helpful :)

petritr left a reply on Show Different Error Message For 1062 Duplicate Entry When Using Ajax • 1 week ago

There is an statusCode method:

statusCode: {
      500: function() {
      alert("error");
       }
    },

That worked for me.

petritr left a reply on Select Input Check Witch Option Is Selected • 1 week ago

I got it, but i need to repeat the if twice:

 <option @if($device->usage == 'One') selected="selected" @endif >One</option>
 <option @if($device->usage == 'Two') selected="selected" @endif >Two</option>

Any ideas to improve this with one if ?

petritr started a new conversation Select Input Check Witch Option Is Selected • 1 week ago

I have the following as html:

<select class="form-control">
   <option selected="selected">One</option>
    <option>Two</option>
</select>

I will get the selected item from the database, how to check in blade and selected the correct option ?

<select class="form-control">
    <option selected="selected">{{ $device->usage }}</option>
    <option>Local Modification</option>
</select>`

petritr started a new conversation Show Different Error Message For 1062 Duplicate Entry When Using Ajax • 1 week ago

How can i show and custom text message for 1062 Duplicate entry i use ajax to process the data.

error message:

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '22' for key

10th September, 2018

petritr left a reply on Redirect Back With Ajax • 1 week ago

My goal was to leave flash message when something was created or delete, not reload or something, but i see it wont work with laravel redirect->back() method.

Thank you @tykus good reply as always.

petritr started a new conversation Redirect Back With Ajax • 1 week ago

I tray to redirect back but no success, i use ajax.

        return back()->with('delete', 'Device has been deleted.');
        return redirect()->back()->with('delete', 'Device has been deleted!');

What im missing? Non of both would redirect ?

9th September, 2018

petritr left a reply on Append The Search Result In The Input Search Field • 1 week ago

i got it

methods: {
            action(item) {
                
                this.selected = item
                this.search = item.name
                this.magic_flag=false;
            }
        },

With this.search = item.name i will append the result to search input

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.