Our Black Friday sale is now live! All individual subscriptions are 50% OFF. This week only!

JoaoHamerski

JoaoHamerski

Member Since 2 Years Ago

Experience Points
8,620
Total
Experience

1,380 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
59
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.

Level 2
8,620 XP
Nov
24
15 hours ago
Activity icon

Replied to Cleave.js Deletes More Characters Than Intended When Using Vue And Delimiters

It worked perfectly my brazilian fellow.

Sorry i didn't say that i changed the sample from cleave.js' docs, i though it was evident, i was not using v-cleave directly on a input but the logic was been applied to the input element, i though it would work as intended.

I'm just learning Vue now, didn't know about vnodes, i'll give a look on it.

Thank you so much for your well detailed explanation, helped me a lot.

Nov
23
1 day ago
Activity icon

Started a new Conversation Cleave.js Deletes More Characters Than Intended When Using Vue And Delimiters

First of all, here is the fiddle: https://jsfiddle.net/87e4hfc0/1/ Just type on input until a delimiter appears, so try to delete right when the cursor are on the delimiter and Cleave just deletes everthing that is before it until the previous delimiter.

I don't know why this is happening, my input is wrapped with a div and i'm using v-model in a component and followed the Vue documentation to that: https://vuejs.org/v2/guide/components.html#Using-v-model-on-Components, this is why i didn't used v-model directly on my input.

Nov
21
3 days ago
Activity icon

Replied to How To Activate Bootstrap Tooltip Inside Vue If Directive?

I cant use v-show because my v-if has a v-else that shows a button without disabled property to user click when the form has no errors.

Unless i use two v-shows, one to show when has errors and one to show when doesnt, but idk, the jquery solution seems to work well delegating and its just a tooltip, normally i dont do these things.

Anyway, thanks for clarify this issue.

Activity icon

Replied to How To Activate Bootstrap Tooltip Inside Vue If Directive?

Ok, i just found i workaround to this, but if someone have a better and correct answer it will help a lot:

I put after the Vue instance this code:

$('#app').tooltip({
  selector: '[data-toggle="tooltip"]'
});
Activity icon

Started a new Conversation How To Activate Bootstrap Tooltip Inside Vue If Directive?

Here is my code:

<div v-if="form.errors.any()">
    <span class="d-inline-block" 
        tabindex="0" 
        data-toggle="tooltip" 
        title="Fill the form correctly">
        <button style="pointer-events: none;" 
            disabled="disabled" 
            class="btn btn-success">Create account</button>
    </span>
</div>

To activate tooltips in bootstrap i had to use jQuery:

$('[data-toggle="tooltip"]').tooltip();

So i used Vue next tick to apply the code above in my root instance every cicle like so:


new Vue({
  el: '#app',
  mounted() {
    this.$nextTick(function() {
      $('[data-toggle="tooltip"]').tooltip();
    });
  }
});

The problem is that this doesnt work inside Vue directives like "if", it only works inside Vue components.

So, the question is simple, how can i use tooltips inside Vue if directives?

The HTML code above the tooltip is rendered only if the vue-if is true, so the tooltip doesnt work, but if i put the tooltip code outside the if, it works perfectly, am i missing something?

Activity icon

Replied to How To Set A Default Value To Input With A V-model Via HTML?

Ok, i just found out a way to do it if someone need, very simple:

<your-input v-model="variable = 'default  value'"/>

And that is it, you can use blade to define a default value when you want.

This works better in case you are working with properties that are not in your component, which is my case, my v-model is not a variable of my input component, is from other component.

Activity icon

Replied to How To Set A Default Value To Input With A V-model Via HTML?

So, how can i set default value when showing a edit page where i have to show predefined values in inputs?

Nov
20
4 days ago
Activity icon

Replied to How To Set A Default Value To Input With A V-model Via HTML?

As i said in the post, vue ignores default value when using v-model, is not possible change it dynamically too, we get this error: Error message: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value.

Activity icon

Started a new Conversation How To Set A Default Value To Input With A V-model Via HTML?

<input value="default value here"/>

Just that, as you guys know, Vue ignores the default value property when using v-model, i would like to know how can i set it via HTML? It's necessary when i want make a "edit" page and show all predefined values of the inputs, for example

Activity icon

Started a new Conversation How Can I Use Vue To Handle With All My Forms/inputs In All My Pages?

So i have been learning Vue, i saw that i have to create a component to manipulate some html related to it, but here is the problem:

If i had a lot of forms in diferent pages of my site, a lot of forms, how can i manipulate all of them without needing to create a different components for each form?

Currently i'm using the Form and Errors class from Jeffrey course (https://laracasts.com/series/learn-vue-2-step-by-step/episodes/21), but i would like to use these classes in all forms of my page, not create a component for each form and use on it.

The problem is that i have to bind the props of the inputs, and to do that i have to create a Vue component for each form, so i would like to know if there is a way to handle with all my forms and inputs without creating a component for each form.

Is it possible?

Nov
14
1 week ago
Activity icon

Started a new Conversation Why I Have To Use ".default" When Require Some Vue Component To Work?

For example, i have a component and i use this code to render the component:

Vue.component('sidebar', require('./components/Sidebar').default);

but if i remove the ".default" like that:

Vue.component('sidebar', require('./components/Sidebar'));

It just returns a error:

"Failed to mount component: template or render function not defined"

So, what this ".default" property really does?

Here is my component:

<template>
	<div>
		Hello world
	</div>
</template>

Note: It's just curiosity, i havent any issue here, i just would like to know why i have to put ".default" at the end of the require function.

Nov
06
2 weeks ago
Activity icon

Started a new Conversation Is It Possible To Get Some Kind Of "$this" In A Where Clause?

Here is the problem: I have to do a where and update one field from the table, but i want to update this field with the value of another field from the same record, how can i do it?

For example

App\Models\Order::where('is_closed', '1')->update(['closed_at' => [HERE I WANT THE FIELD "update at" FROM THE SAME  (CURRENT) RECORD]);
Nov
02
3 weeks ago
Activity icon

Replied to Insert Multiple Records With Same Input Name Laravel

I had a huge issue with the transpose from the link above, when sending file fields that can be nullable the transpose function made with collections just ignores totally the "NULL" from fields where has no file, so if a had multiple files, Ex: 3 forms -> 2 first forms without file field -> last form with a file field: I had a issue where the field from the last form is inserted in the first form.

The problem happens because the transpose function from the guy that @tykus send the link don't respect indexes, so this is the problem, here is how i solved it, a custom PHP transpose function.

If you'r dealing with nullable input file fields you probably will need that.

            $out = array();
            $arr = $this->all();

            foreach ($arr as $key => $subarr) {
                foreach ($subarr as $subkey => $subvalue) {
                    $out[$subkey][$key] = $subvalue;
                }
            }

	    return new static($out);

This will preserve even the key name of the fields, so you can do something like that:

$models->transpose()->map(function($model) {
	Model::create($model);
});

or if you prefer

$models->transpose()->map(function($model) {

	Model::insert([
		'some_field' => $model['some_field']
	]);
});
Oct
31
3 weeks ago
Activity icon

Replied to How To Get A Query Instance Of Two Differents Tables (not A Collection), Join Two Different Tables?

@jlrdw Thank you, this will be helpful, i know SQL but not so much, i know how most of things work but i'm not good to write SQL queries.

Activity icon

Replied to How To Get A Query Instance Of Two Differents Tables (not A Collection), Join Two Different Tables?

Unfortunatelly the tables has not the same number of columns, i tried it before and got this error.

Activity icon

Replied to How To Get A Query Instance Of Two Differents Tables (not A Collection), Join Two Different Tables?

This is what i need:

I have two tables: Payments and Expenses. I want to merge all the records from these tables and show in the same page, these tables have similar columns but not equals, i could deal with the different columns not problem with that.

Here is what i did:

$entries = Expense::all();
$entries = $entries->merge(Payment::all());

So now i have a array of models and i can sort by date (both columns have a 'date' column)

$entries->sortByDesc('date')

So i'm using a a helper to paginate the records from a collection

return view('cash-flow.index', [
    'entries' => CollectionHelper::paginate($entries->sortByDesc('date'), 10)
]);

Everything works fine, the only thing i would like to know is if it's possible to do it with a QueryBuilder instance, for example, join these two tables and sorte by date, paginate these records and show, just to make the code cleaner idk.

In my view i can distinguish when it's a Payment or Expense with a if:

@foreach ($entries as $entry)
@if ($entry instanceof \App\Models\Payment)
	// It's a payment
@else
	// It's a expense
@endif
@endforeach
Activity icon

Replied to How To Get A Query Instance Of Two Differents Tables (not A Collection), Join Two Different Tables?

I don't want to show all the records, i want to get all records and paginate it, can it be a problem?

Activity icon

Started a new Conversation How To Get A Query Instance Of Two Differents Tables (not A Collection), Join Two Different Tables?

I have two completely different tables and want to get all the records of these two tables and merge the records, is it possible to do that? I could do that with Collections but i would like to paginate this records, and only with a Query instance is possible to paginate (yes, i know, i can paginate a collection with a custom code, but i'm just checking the options here before do that).

Oct
28
3 weeks ago
Activity icon

Replied to Insert Multiple Records With Same Input Name Laravel

Great answer, thank you so much. I just had a little issue when uploading files, so if someone will use transpose when uploading file this is how i solved:

        Collection::macro('transpose', function () {
            $items = array_map(function (...$items) {
                return $items;
            }, ...$this->map(function($item) {
                return is_object($item) ? [$item] : $item;
            })->values());

            return new static($items);
        });

As objects are not allowed in array_map function you have to convert the File instance to a array.

EDIT: I forgot to set the field "name=file[]" it was "name=file", so because of that i was getting a object, you dont need to follow the code above, but i'll let the code here just in case.

Oct
27
4 weeks ago
Activity icon

Replied to Barryvdh/laravel-dompdf Table Page Break Problem

That is how i solved my problem:

i created a table for each record, as i had a rowspan the examples showed didn't work to me,

so

	@foreach($items as $item)
		<table>
			....
		</table>
	@endforeach

So in my css i put:

table {
	page-break-inside: avoid !important;
}

That worked perfectly, didn't break the images i had in the table.

Oct
26
4 weeks ago
Activity icon

Replied to Barryvdh/laravel-dompdf Table Page Break Problem

@boby it didn't work to me, maybe it doesnt work in table that have rowspans? What is this "row"? I dont have a "row" class wrapping my table, can you show me the style of the row please? And the container?

Activity icon

Replied to Barryvdh/laravel-dompdf Table Page Break Problem

should i wrap all the table in this div "page-break-after:auto"?

Activity icon

Replied to Barryvdh/laravel-dompdf Table Page Break Problem

@boby where should i put the "page-break-after:auto" ? I have the same problem, i have some tr's and need the page break automatically when get the end of page.

Oct
23
1 month ago
Activity icon

Started a new Conversation Insert Multiple Records With Same Input Name Laravel

For example, i have multiple inputs with name = description

input name="description[]"

when i submit, for example, 3 inputs, this give me an array like that:

["description"] => [0] => "some value"
                                [1] => "another value"
                                [2] => "some another value"

but if i use :

Model::create($request->all());

I have a error: "Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array, string given..."

So how can i insert dynamically all the inputs that is submitted to the server?

Oct
13
1 month ago
Activity icon

Started a new Conversation Is It Worth Make A New Table To Save Just A String Field Or Is Better To Make A Json Field To Do That?

For example, i have a table "orders", in that table maybe i have 1 or many "notes", but that notes are just strings, so i ask you guys, is it better i make a json field in "orders" to save all notes or make a new table "notes" to store all note from a order?

Sep
23
2 months ago
Activity icon

Commented on Dedicated Form Components

Just if someone wants to know why he used "load" insted of "with" to retrieve the statuses.

$statuses->load('user') // returns a model instance.

$statuses->with('user') // returns a Builder instance, so if we use $statuses->with('user')->get() we will get the same result as $statuses->load('user').
Sep
05
2 months ago
Activity icon

Commented on Object-Oriented Forms: Part 1

In Laravel 7 you have to return the error this way to work:


axios.post('/projects', this.$data)
        .then(response => console.log(response))
        .catch(error => this.errors.record(error.response.data.errors))

instead of "error.response.data" you have to type "error.response.data.errors"

Aug
26
2 months ago
Activity icon

Commented on Named Slots In A Nutshell

I'm getting this error when using the new "v-slot" in a div:

v-slot can only be used on components or template.
Jun
03
5 months ago
Activity icon

Replied to Relationship Between "Users" And "Products" With Pivot "Order" Table?

But even if it is a little weird to say that a user belongs to many products?

Jun
02
5 months ago
Activity icon

Started a new Conversation Relationship Between "Users" And "Products" With Pivot "Order" Table?

I have 3 tables, users, products and orders, the users and products has a relationship of many-to-many, but, what is the relationship in the methods of the user model? I understand that a product belongs-to-many users but, a user belongs to many products? Is it right? I don't think so.

Or i can do a user hasMany products? Is it will be wrong if i do a user hasMany products in a relationship of many-to-many between users and products? Or the two relations have to be obligatorily a "belongsToMany"?

May
23
6 months ago
Activity icon

Replied to How To Do A Query Search In Multiple Tables?

In fact it is doing the where only on the first query, i tried to use ->toSql() to see and this is the result:

select * from (select * from "table1" where "hash" = ?) union select * from (select * from "table2") union select * from (select * from "table3") union select * from (select * from "table4") . . . . 
Activity icon

Replied to How To Do A Query Search In Multiple Tables?

All my tables have the same columns, are two columns a id and json the only thing that changes are the structure of the json, but each json is a string, what i did was get all table names and do a foreach to do a union with all tables, because actually it is 56 tables. Well, the only solution i found was do a where in each query of table before do the union, but its a little bit ugly i think, if you have a better solution i'll appreciate it.

May
22
6 months ago
Activity icon

Replied to How To Do A Query Search In Multiple Tables?

@tray2 I just noticed that when i do a where search on the query search Laravel just ignores the union tables, he only do the where search on the first table, the other tables he just concat the records, do you know how can i solve it?

I'm doing something like that:

$query = DB::table('table1');

$query = $query->union(DB::table('table2'));

$data = $query->where('json->hash', 2803282938)->get();

So he show all the records from table2 next tables and apply the where clause only on the table1 , some solution for this?

Note: I'm using a SQLite database file.

Activity icon

Replied to How To Do A Query Search In Multiple Tables?

Wow that helped a lot, thanks

Activity icon

Started a new Conversation How To Do A Query Search In Multiple Tables?

For example, i have 20 tables and want to do a query search that perform a search in all tables and return a instance of Query Builder.