JoaoHamerski

Member Since 2 Years Ago

Experience Points
9,880
Total
Experience

120 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.

  • Community Pillar

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

Level 2
9,880 XP
Apr
03
1 month ago
Activity icon

Started a new Conversation How To Run A Development Server In Laravel Mix (standalone Project)

standalone project = without using Laravel

I'm trying to run a server to see my project on browser, the only way i can do it is running npx mix watch --hot, so after that my project start running at localhost:8080.

But the above command enable hot reload, i would like to know if there is some specific command to just run the server, without enabling hot reloading.

I tried npm mix watch but it not starts the server, just watch the files.

Tried calling manually webpack server with:

./node_modules/.bin/webpack serve --config="./node_modules/laravel-mix/setup/webpack.config.js"

This works (the server starts at localhost:8080 as well) but somehow it activates hot reloading too, idk why.

So, there is some way to just start the server? Without enabling hot reloading?

Here is my webpack.mix.js file:

let mix = require('laravel-mix');

mix.sass('src/scss/app.scss', 'dist/css/')
  .js('src/js/app.js', 'dist/js/').react()
  .setPublicPath('public');

Mar
31
1 month ago
Activity icon

Started a new Conversation There Is Some Good Reason To Keep Using PHP? Why Do People Are Migrating To NodeJS?

I would like to understand.

I've been seeing how much NodeJS has been growing up the last years, consequently PHP is getting less used, i would like to know if currently worth it keep using and developing new things in PHP.

Why should i use PHP instead of NodeJS?

Mar
30
1 month ago
Activity icon

Replied to How To Run Webpack Server In Laravel Mix? (without Laravel)

I just figured out what was wrong:

mix.js('src/app.js', 'dist').setPublicPath('dist/')
  .react();

I setted the publicPath to dist/ instead of public/ so webpack was looking my index.html inside my dist/ when it was inside my public/ folder, to fix it i just changed the setPublicPath to the folder where my index.html was.

Activity icon

Started a new Conversation How To Run Webpack Server In Laravel Mix? (without Laravel)

I'm using only laravel-mix on stand alone project https://laravel-mix.com/

But i cant figure out how do i config laravel-mix to run a server on my localhost

i tried npx mix watch --hot but when i go to http://localhost:8080/

i get this message: Cannot GET / even if i try to get the path to my bundle.js. Every URL returns me this error.

Mar
19
1 month ago
Activity icon

Replied to Laravel With Pusher Just Doesn't Work

Nothing happends as well, my pusher connection is ok i think because it keeps logging POST requests from time to time

Activity icon

Started a new Conversation Laravel With Pusher Just Doesn't Work

What am i missing? I did everything right but when i sent a new Event my console just doenst log anything, here is my code:

FRONT END

I imported the required libraries:

import Echo from 'laravel-echo';

window.Pusher = require('pusher-js');
window.Echo = Echo;

window.pusherEcho = new Echo({
	broadcaster: 'pusher',
	key: 'my-key',
	cluster: 'us2',
	forceTLS: true,
	wsHost: window.location.host,
	wsPort: 8000
});

BACK END

My event class:

<?php

namespace App\Events;

// ... imports

class ReceivedNotification implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $message;

    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct($message)
    {
        $this->message = $message;
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        return new PrivateChannel('received-notification');
    }
}

I registered a route just to test it:

Route::get('/event', function() {
    event(new App\Events\ReceivedNotification('Hello world'));

	return 'event sent';
});

FRONT END

I'm listening to events in some page with Laravel Echo:

pusherEcho.channel('received-notification')
    .listen('ReceivedNotification', (e) => {
        console.log(e);
});

When i go to the route /event it never triggers the console.log above, which means something is just wrong, yes my .env file is everything ok i already checked:

BROADCAST_DRIVER=pusher
. 
.
.
PUSHER_APP_ID=***
PUSHER_APP_KEY=***
PUSHER_APP_SECRET=***
PUSHER_APP_CLUSTER=us2
Mar
13
1 month ago
Activity icon

Started a new Conversation How 'migrations' Table Works In Laravel?

I have 3 connections configured on my application each one with a different database:

  • mysql
  • mysql_connection2
  • mysql_connection3

Currently i'm only using mysql_connection2 and mysql_connection3, i migrated some tables to these two connections that are located in different folders using the commands:

  • php artisan migrate --path=database/migrations/connection2
  • php artisan migrate --path=database/migrations/connection3

So the issue here is, i couldn't find the migrations table, Laravel just didn't created the migrations table in these two connections, so looking for that i found the migrations table on my first connection database mysql, so can someone explain me how migrations table works? And how can i specify to Laravel create one migration to each connection when i migrate my tables?

Mar
11
1 month ago
Activity icon

Replied to Should I Import Facades In Laravel Or Just Append Slash Before Class To Call It?

@michaloravec i'm crying now, why did you do that with me, ok ok i'll import Facades from now so i can be proper programmer, i'll put on my CV that i import Facades when developing Laravel projects, sorry.

Activity icon

Replied to Should I Import Facades In Laravel Or Just Append Slash Before Class To Call It?

Like @jlrdw said, if you have a single usage of it, i dont see any reason to import a Facade just to looks a little better.

Activity icon

Replied to Should I Import Facades In Laravel Or Just Append Slash Before Class To Call It?

Yea i follow the same logic as you.

The only reason i see to import Facades that i can just call using a slash before the classname is to show what classes my php class are using and where they are located for someone who will read the code, but anyways, if someone is reading a Laravel code a suppose that this person already know at least the basic of Laravel and where Facades are located and how it works.

Because as i said, all facades aliases are located at config/app.php

If you know that basic thing you automatically know that if there is some e.g. \DB in my controller its a Facade.

Activity icon

Replied to Should I Import Facades In Laravel Or Just Append Slash Before Class To Call It?

I was expecting a most detailed answer, why should i set this as best answer? I know that i have two options, import or use facades without import, so why choose the answer? Why always import? Because someone told me? Or someone will explain me why?

Activity icon

Started a new Conversation Should I Import Facades In Laravel Or Just Append Slash Before Class To Call It?

I noticed that every laravel Facade i can call using \Hash instead of importing every class

e.g.

use Illuminate\Support\Facades\Hash;

So i wonder what is the best way or best practice to call a facade, import it or i can just using the classname with slash like \Hash

Activity icon

Replied to How Ignore This Error: 'Cannot Declare Class CreateUsersTable, Because The Name Is Already In Use'

yea i noticed that now, thanks for your help, i'm not using the --database flag because it didn't find my migration files that are inside folders, but i tried --path and worked fine.

Obs.: I had to remove the helper function to get this working.

Mar
10
1 month ago
Activity icon

Replied to How Ignore This Error: 'Cannot Declare Class CreateUsersTable, Because The Name Is Already In Use'

But i'm using this helper function on my AppServiceProvider that run all migration files from my folders when i run php artisan migrate:

private function enableMigrateFromDirs() 
{
    $path = database_path('migrations');
    $directories = glob($path . '/*' , GLOB_ONLYDIR);
    $paths = array_merge([$path], $directories);

    $this->loadMigrationsFrom($paths);
}

So i'm getting the same error because i think artisan try to run my migrations from other connection too, maybe there is other way to do that?

Activity icon

Replied to How Ignore This Error: 'Cannot Declare Class CreateUsersTable, Because The Name Is Already In Use'

I'm using

Schema::connection()

on each migration file to migrate, am i doing it wrong?

Activity icon

Started a new Conversation How Ignore This Error: 'Cannot Declare Class CreateUsersTable, Because The Name Is Already In Use'

How can i ignore this error when running migrations?

I'm working with two connections that have a users table in each one, i migrate each one in a different connection, and each one have different models and etc... So i'll not have any conflict, i just woud like to ignore this error.

Here is my folder:

migrations/connection1/create_users_table.php

migrations/connection2/create_users_table.php

Mar
09
1 month ago
Activity icon

Started a new Conversation How To Set Up Laravel App With Subdomains To Work On A CPanel Server?

Here is my test code i'm using:

Route::domain('test.mydomain.com')->group(function() {
	Route::get('/', function() {
		return 'DOMINA TEST.MYDOMAIN.COM';
	});
});

Route::domain('mydomain.com')->group(function() {
	Route::get('/', function() {
		return 'DOMAIN MYDOMAIN.COM';
	});
});

Route::get('/', function() {
	return 'ROOT DOMAIN';
});

I'm currently using cPanel to handle domains and subdomains, but i have no idea how to make it work with Laravel Subdomains, i tried the code above, when i access my main domain mydomain.com it shows "DOMAIN MYDOMAIN.COM" so it works ok, but when i go to test.mydomain.com it just access my subdomain folders, so, how can i make it works?

Maybe i need to put some .htaccess on my test.mydomain.com? Can someone help me?

Feb
20
2 months ago
Activity icon

Awarded Best Reply on Vue Cant Watch Object Property Setted Inside For Loop

REPLY OF CORRECT ANSWER FROM STACKOVERFLOW: https://stackoverflow.com/questions/66296065/vue-cant-watch-object-property-setted-inside-for-loop

By default, watchers are run asynchronously (in the next macro tick) as a performance optimization. I think the motivation is watchers are assumed to only care about the most recent change.

You can configure the watcher to be synchronous by setting sync: true:

watch: {
  obj: {
    sync: true
  }
}

updated fiddle

Activity icon

Replied to Vue Cant Watch Object Property Setted Inside For Loop

REPLY OF CORRECT ANSWER FROM STACKOVERFLOW: https://stackoverflow.com/questions/66296065/vue-cant-watch-object-property-setted-inside-for-loop

By default, watchers are run asynchronously (in the next macro tick) as a performance optimization. I think the motivation is watchers are assumed to only care about the most recent change.

You can configure the watcher to be synchronous by setting sync: true:

watch: {
  obj: {
    sync: true
  }
}

updated fiddle

Activity icon

Started a new Conversation Vue Cant Watch Object Property Setted Inside For Loop

I would like to set a object property inside a for loop and watch for those changes, but somehow Vue simply doesnt listen to all changes on watch prop.

Here is my test code to simplify my issue (https://jsfiddle.net/hn2wepc9/).

If you click on the button it should log 5 lines on console (because loop method), but it only logs 1, i cant understand why, Vue simply doesnt listen to all changes when i use Vue.set() inside a for loop and try to watch these changes.

<div id="app">
  <button @click="loop">Button</button>
</div>
new Vue({
  el: '#app',
  data: () => {
  	return {
    	  obj: {
       	    name: 'John Doe'
        }
     }
  },
  methods: {
  	loop() {
      for (let i = 0; i < 5; i++) {
        Vue.set(this.obj, 'name', 'Dohn Joe ' + i);
      }
    }
  },
  watch: {
  	obj: {
      deep: true,
      handler(newVal, oldVal) {
      	window.console.log(newVal.name + ' - ' + new Date().toLocaleString());
      }
    }
  }
});
Feb
18
2 months ago
Activity icon

Started a new Conversation Is It Possible To Use Computed Properties In Array Of Objects?

For example, i have something like this:

data: () => {
	layers: [
		{name: 'Something', index: 0},
		{name: 'Something again', index: 1},
	]
}

I would like to add a computed property for every name property of my layers array, of course it will be the exctaly same function, i think it would be very useful in many cases but i have been searched and didn't find anything about that for Vue.

So i could call it like so: layers.name.computedName or something like that.

Feb
11
2 months ago
Activity icon

Replied to How Can I Change The Logic Of Laravel User Authentication? Using A Column From A Related Table To Auth The User.

But i would like to do a custom logic, i mean, there is some way to customize the conditional method that allow the users to login? I would like to allow the user to use all the phone numbers he has to try to authenticate, and his password too, something like that. I already read that section from authentication but seems i cant change the attempt() method from laravel auth.

Activity icon

Started a new Conversation How Can I Change The Logic Of Laravel User Authentication? Using A Column From A Related Table To Auth The User.

I have a users table that have many phones from phones table, i would like to authenticate the user using the column from the related table (phones), something like this:

The user input a phone number and password, i would like to compare if the user has the given phone and if the password matches, if true, the user can login.

I tried to overwrite the username() method from LoginController.php like this:

public function username()
{
    return 'phones.number';
}

but it didn't worked, it returns me a 422 error.

How can i make this change, keeping almost the same logic to auth the user but using a related table to compare some data and auth the user?

Jan
18
3 months ago
Activity icon

Started a new Conversation What This Expression Means? "getTodoById: State => Id => { Return Something }"

getTodoById: state => id => {
    return state.todos.find(todo => todo.id === id);
}

I just cant understand what that double arrows "=>" means, i know what arrow functions are, but i found this and i just cant figure out, its first time i see double arrows this way, is it two parameters? state and id? Because when i call this function i only have to specify the id, what is the state means?

Dec
30
4 months ago
Activity icon

Replied to Why I Had To Use $forceUpdate() In Many Things To Work In Vue?

I just realised that Vue Devtools extension was not updating the properties, but the code actually was, jesus christ! So many times i used forceUpdate, but it was just the Vue Devtools, i found a button that force refresh in Vue Devtools now when i press it everything works.

Dec
29
4 months ago
Activity icon

Replied to How To Display Unescaped Inline HTML With Vue?

It was deprecated in Vue 2.0, i'm currently using vue 2.0+

Activity icon

Started a new Conversation How To Display Unescaped Inline HTML With Vue?

I know that i can use v-html directive in a element to display unescaped HTML, but i want to display only the content of the variable and not the content inside a element.

For example: If i do

<div v-html="myVariable"></div>

The content of myVariable will be inside the div, i would like to display the content inline, only the content of my variable.

Dec
26
4 months ago
Activity icon

Started a new Conversation What Is The Best Way To Deal With Monetary Values Programatically?

Here is a perfect example that got me crazy:

The user can input a total price and a integer which the total price will be divided by it, almost all cases will be fine.

But here is the problem:

Lets imagine the user inputs 200 as total price and 3 as the integer, so i have:

200 / 3 = 66.6666666667

I would like to store in database the 66.6666666667 value, if i have a decimal field in my database with scale of 4 it will get the job done (*.xxxx), it even around to the right value by itself, in this case it will be rounded as 66.6667.

So 66.6667 * 3 = 200.0001 (as the decimal value is far from left i can just round and it will be ok, it will match the total price ).

But here is the problem, i would like to let the user input how much he would like to pay for a partial of the total value (that in this case is 66.6667, but the user only can input a value with scale of 2 (*.xx), its very annoying make a input mask where the user inputs a monetary value with scale of 4.

So here is the problem: the user inputs 66.67, on backend it will be 66.6700, because i cant know if it will be 66.6667 or 66.6777.

I store a payment with this value, at the end i sum all the payments:

66.6700 * 3 = 200.01, so this simply breaks the value and there is nothing i can do.

Now i have a total price 200 typed by the user, but because it was divided by 3 and get the sum of the payments at the end, it returns me 200.01.

This is just a example, the user can input 50, and after that 16.67, but for better understanding i said 66.67 as example, at the end it will be 66.6700 and will break some of the monetary maths in my backend.

Can someone help me on how can i workaround with that?

Activity icon

Started a new Conversation Why I Had To Use $forceUpdate() In Many Things To Work In Vue?

I dont have a example in special, but many data variables or templates simply doesnt update when i change something via a button click or via some interaction with the web page, so when this happens i use $forceUpdate() method in my code and it simply works, why this happens? Why i had to use $forceUpdate()? Vue cant just detect that something changed by itself?

Dec
06
5 months ago
Activity icon

Replied to How To Update Many Records From A One To Many Relation?

@tisuchi Here is what i did until now, a method on my Client model:

public function updatePhones(array $requestPhones)
{
    $phoneIds = $this->phones->pluck('id')->toArray();
    $requestPhoneIds = [];

    foreach ($requestPhones as $requestPhone) {
        if (isset($requestPhone['id']) && in_array($requestPhone['id'], $phoneIds)) {
            $requestPhoneIds[] = $requestPhone['id'];

            $this->phones()
                ->where('id', $requestPhone['id'])
                ->update(\Arr::except($requestPhone, ['created_at', 'updated_at']));
        } else {
            $this->phones()
                ->create(\Arr::except($requestPhone, ['created_at', 'updated_at']));
        }
    }

    if (! empty($idsToDelete = array_diff($phoneIds, $requestPhoneIds))) {
        $this->phones()->whereIn('id', $idsToDelete)->delete();
    }
}

Not clean, but working. i think i can refactor this yet.

Activity icon

Replied to How To Update Many Records From A One To Many Relation?

I know about the sync method, but i dont see any reason to do a Many to Many relationship, a Client have one or many Phones, but a Phone only belongs to a Client, unless i make a Many to Many and use as One to Many only to sync the Phones, idk if this is a good practice, what can you tell me about that?

Dec
05
5 months ago
Activity icon

Started a new Conversation How To Update Many Records From A One To Many Relation?

I have this on my Client model:

public function phones()
{
    return $this->hasMany(Phone::class);
}

and this on my Phone model:

public function client()
{
    return $this->belongsTo(Client::class);
}

So a Client can have many Phones, i'm syncronizing the Phones in a dynamic input, so if the user removes a phone and save i would like to update all the Phones from the given Client, updating the Phones that already exists and removing the ones who doesnt are in the array.

How can i do it on the server-side? My front-end is ok, returns a array of phones as it should be.

Dec
03
5 months ago
Activity icon

Started a new Conversation How To Add A Loading Icon To Page Until Every Component Loads Completely?

Is it possible to do it with Vue? I already saw that in many sites but i have no idea how to do it.

Here is a example: https://gisanddata.maps.arcgis.com/apps/opsdashboard/index.html#/bda7594740fd40299423467b48e9ecf6

This is a site that maps the covid 19 around the world, when you open it there is a loading icon and only when the elements are loaded they shows up, so there is no that annoying thing of the user seeing each element of the site loading, it only appear when are almost full loaded.

Nov
30
5 months ago
Activity icon

Started a new Conversation Custom Event Simply Doesnt Work, Parent Element Doesnt Catch Emitted Event.

Here is the fiddle: https://jsfiddle.net/5z4oshwu/2/

HTML:

<div id="app" @test="test()">
  <custom-button @click="$emit('test')">
    button
  </custom-button>
</div>

JS:

Vue.component('custom-button', {
    template: '<button><slot></slot></button>'
});	

new Vue({
  el: '#app',
  methods: {
    test() {
    	alert('test');
    }
  }
});

Nov
24
5 months 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
5 months 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
5 months 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?

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

Nov
20
5 months 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
5 months 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
6 months 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
6 months 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']
	]);
});