leandromatos

leandromatos

Member Since 3 Years Ago

Belo Horizonte, MG

Senior Marketing Developer at Hotmart

Experience Points 156,090
Experience Level 32

3,910 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 1490
Lessons
Completed
Best Reply Awards 11
Best Reply
Awards
  • start-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-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-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist 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.

23 May
1 month ago

leandromatos left a reply on Where To Put Logic In Laravel?

If you need help, we're here.

22 May
1 month ago

leandromatos started a new conversation Which Editor Do You Use To Work?

Tell everyone why you use this editor. Is he more productive for you? If yes, why?

leandromatos left a reply on Where To Put Logic In Laravel?

Hey @gameoverllc, the best place for put any business logic are the service files.

You know about "Solid Principles"? If no, i recommend you reading about it.

Basicly, the solid principles, are principles for help you to code better. The first principle "Single Responsability" defend an separate responsabilities for any file.

An controller for example is reponsable to receive requests and return an response. Only that.

An model is responsable to interact with your database (between service an a model, you maybe can use an repository too, but is not a rule).

An service is reponsable for any other stuff. You can have many service files (each service with your responsability) and you can use it in the controllers for receive an request, manipulate the request and other data, and return a response for controller, and your controller return a response for your view or your browser if you are creating an api.

Sorry for my bad english, i'm brazilian guy and my english is not so good.

I hope was helpfull.

leandromatos left a reply on Generate Invoice Number

Hey @emfinanga, try some like this:

foreach($request->product_name as $Customeraddress => $i) {

    $invoiceNumber = 'PACL-' . date('m') . '/' . str_pad(1, 3, "0", STR_PAD_LEFT);

    Customer::create([
        'customer_id'    => $request->input('clientName'),
        'product_name'   => $request->product_name[$Customeraddress],
        'quantity'       => $request->quantity[$Customeraddress],
        'price'          => $request->price[$Customeraddress],
        'amount'         => $request->amount[$Customeraddress],
        'invoice_number' => $invoiceNumber
    ]);
}
20 May
1 month ago

leandromatos left a reply on How To Store Array Textbox Value

@DUCKZ1209 - You solved this question?

leandromatos left a reply on How To Store Array Textbox Value

@DUCKZ1209 - Duplicate or change the names of variables in your logic bussiness. It’s simple.

19 May
1 month ago

leandromatos left a reply on How To Store Array Textbox Value

Your store method in controller should look like this:

public function store(Request $request)
{
    $books = [];

    foreach($request->book_name as $book_name) {
        $book = new Book();
        $book->book_name = $book_name;
        $book->save();

        array_push($books, $book);
    }
    
    return response()->json($books);
}

leandromatos left a reply on How To Store Array Textbox Value

@DUCKZ1209 - If I understend, you need pass to controller via ajax all names of books in array format inside variable book_name . Thats it?

leandromatos left a reply on How To Store Array Textbox Value

However, for you code better, an tip:

Accord the W3C, the id of html element must be unique.

https://www.w3.org/TR/html5/dom.html#element-attrdef-global-id

You can refactor your code for like this:

@foreach($books as $book) @endforeach
<a type="submit" id="add" name="add" class="btn btn-success">Save</a>

...

leandromatos left a reply on How To Store Array Textbox Value

@DUCKZ1209 - Try this:

<script type="text/javascript">
$.ajaxSetup({
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
});

$("#add").click(function(e) {
    e.preventDefault();

    var books = document.querySelectorAll('input[name="book_name"]');
    var values = [];

    books.forEach(function(book) {
        values.push(book.value);
    });

    $.ajax({
        type: 'POST',
        url: '/books/store',
        data: {
            'book_name': values
        }
    });
});
</script>

leandromatos left a reply on How To Pass A Variable To A Function With Callback?

@MARTINZELTIN - Try this:

$data = 'my data here...';

// create a closure using anonymous function
$doIt = function () use ($data) {

    echo 'Anonymous function! ' . $data;
};

// expected output: Anonymous function!my data here...
$doIt();

leandromatos left a reply on Artisan Db:seed Gives "Unable To Locate Factory With Name [default] ..."

Try to run composer dump-autoload and after run the command for seeding the database.

leandromatos left a reply on Using Queue To Expire Plans

You can create a job queue with a task scheduling.

https://laravel.com/docs/5.8/scheduling#scheduling-queued-jobs

PS: Don't forget to start the scheduler.

leandromatos left a reply on Stark Contrast Between Chrome Vs. Chrome Incognito For Development

@R_DUONG89 - Maybe you was a one or more extensions in regular Chrome making wrong actions. Try to disable all extensions and make another test with your application.

leandromatos left a reply on Redirect Back With Error Not Setting The Key

Hey man, i tried here and error directive works without problem. When i submit the form, the store method on controller returns the expected message!

In my routes file

Route::get('/', '[email protected]');
Route::post('/store', '[email protected]');

In my SomeController

<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\Redirect;

class SomeController extends Controller
{
    public function index()
    {
        return view('index');
    }

    public function store()
    {
        return Redirect::back()->withErrors(['insufficient' => 'You do not have enough coins to proceed']);
    }
}

In my index view

<form method="POST" action="/store">
        @csrf

        @error('insufficient')
            {{ $message }}
        @enderror

        <input type="submit" value="Submit">
 </form>
18 May
1 month ago

leandromatos left a reply on Redirect Back With Error Not Setting The Key

@ZFDEVELOPER - If im not wrong, the blade error directive was only work with session of the validation data.

Check it out https://laravel.com/docs/5.8/blade#validation-errors

leandromatos left a reply on Redirect Back With Error Not Setting The Key

@ZFDEVELOPER - if you give a dump in the error variable, what does it show?

leandromatos left a reply on Redirect Back With Error Not Setting The Key

@ZFDEVELOPER - What the return content of error variable?

leandromatos left a reply on Redirect Back With Error Not Setting The Key

Try

return Redirect::back()->withErrors(['insufficient' => 'You do not have enough coins to proceed']);
and inside your view call this
@if($errors->any())
    {{$errors->first()}}
@endif

leandromatos left a reply on Different Output Files With Different Configs

Anyway, you can read the any variables in your .env, you only need put this line top of your mix file. This is the other approach.

‘’’ require('dotenv').config(); ‘’’

leandromatos left a reply on Different Output Files With Different Configs

How is your scripts was declared in package.json?

leandromatos left a reply on Best Practice: When To Use A Repository.

This situations is very normal. I think you can use services with repositories. In the services you can make requests for the both exrernal api’s and manipulate all data, in the repositories you can interact with your database.

leandromatos left a reply on User Has Coins And Can Subscribe To Plans

Hum, it’s true.

In this case you can get the coins amount value directly of the Plans model inside the controller.

In the controller:

// fake slugs of plans
$plan1 = $request->has('plan1') ? Plan::where('slug', 'plan1')->first()->amount : 0;
$plan2 = $request->has('plan2') ? Plan::where('slug', 'plan2')->first()->amount : 0;
$plan3 = $request->has('plan3') ? Plan::where('slug', 'plan3')->first()->amount : 0;
$plan4 = $request->has('plan4') ? Plan::where('slug', 'plan4')->first()->amount : 0;

$requiredCoins = collect([$plan1, $plan2, $plan3, $plan4])->sum(); 

if($requiredCoins < $userCoins) {
    // the coins of user is smaller of the sum of the plans selected
}

leandromatos left a reply on User Has Coins And Can Subscribe To Plans

@ZFDEVELOPER - Would not it be more interesting for you to add the amount of coins needed for the plan in input value?

leandromatos left a reply on User Has Coins And Can Subscribe To Plans

Um, of course.

You can sum the selected plans, even if they come in separate inputs.

$master = $request->has('master') ? $request->input('master') : 0;
$exclusive = $request->has('exclusive') ? $request->input('exclusive') : 0;
$advanced = $request->has('advanced') ? $request->input('advanced') : 0;

$requiredCoins = collect([$master, $exclusive, $advanced])->sum(); 

if($requiredCoins < $userCoins) {
    // the coins of user is smaller of the sum of the plans selected
}

leandromatos left a reply on User Has Coins And Can Subscribe To Plans

First you need to add up all the values of the selected planes. Maybe the collection sum method can help you. https://laravel.com/docs/5.8/collections#method-sum.

After sum all the values in the selection request, you can compare.

User coins are less than the sum of coins of selected plans

Maybe like this:

$requiredCoins = collect($request->input('plans'))->sum(); 

if($requiredCoins < $userCoins) {
    // the coins of user is smaller of the sum of the plans selected
}
29 Nov
7 months ago

leandromatos started a new conversation Pause Between Jobs In The Queue

Hello everyone, everything good?

I need to put a job in the queue that will run 2K times. However, I need to pause between each request (something between 5 and 10 seconds).

Basically, I am consuming an API that returns me the data and a key to the next page, however, I have a low rate limit, so I need to pause to consume the data on the next page.

Since each job in the queue would be a requisition for the API, how would you do to pause between the firing of each new job? I'm not sure how to pause between requests.

Thanks

25 Nov
7 months ago

leandromatos left a reply on Different Seeds According To The Environment

Thank you! I had forgotten the possibility of using .env ;)

leandromatos started a new conversation Different Seeds According To The Environment

Is there a way to pass a parameter to the DatabaseSeeder file so it can make a call to a specific group of classes?

What I would like to do is separate class groups from their local development, staging, and production databases, which should have their tables populated differently.

01 Sep
10 months ago

leandromatos left a reply on How To Change Number Of Pages Appear On Pagination Slide?

Thanks for sharing your model @jlrdw.

I mixed the default pagination and the new option of slide pagination on Laravel 5.7 that @Cronix sharing with us.

Maybe it will serve as a model for someone else who needs it.

@if ($paginator->hasPages())
    <ul class="pagination__items" role="navigation">
        {{-- Previous Page Link --}}
        @if ($paginator->onFirstPage())
            <li class="pagination__item pagination__item--disabled" aria-disabled="true" aria-label="@lang('pagination.previous')">
                <span aria-hidden="true">
                    &lsaquo;
                </span>
            </li>
        @else
            <li class="pagination__item">
                <a href="{{ $paginator->previousPageUrl() }}" rel="prev" aria-label="@lang('pagination.previous')">
                    <span>
                        &lsaquo;
                    </span>
                </a>
            </li>
        @endif

        {{-- Pagination Elements --}}
        @php
        $linksOnEachSlide     = 5; // Must be an odd number
        $halfLinksOnEachSlide = ($linksOnEachSlide - 1) / 2;
        $startPage            = $paginator->currentPage() - $halfLinksOnEachSlide < 1 ? 1 : ($paginator->currentPage() - $halfLinksOnEachSlide);
        $endPage              = ($paginator->currentPage() + $halfLinksOnEachSlide) > $paginator->lastPage() ? $paginator->lastPage() : ($paginator->currentPage() + $halfLinksOnEachSlide);
        $endPage              = $endPage < $linksOnEachSlide ? $linksOnEachSlide : $endPage;
        $startPage            = $endPage - $linksOnEachSlide < $startPage ? $endPage - ($halfLinksOnEachSlide * 2) : $startPage;
        @endphp

        @foreach(range($startPage, $endPage) as $page)
            @if ($page == $paginator->currentPage())
                <li class="pagination__item pagination__item--active" aria-current="page">
                    <span>
                        {{ $page }}
                    </span>
                </li>
            @else
                <li class="pagination__item">
                    <a href="{{ $paginator->url($page) }}">
                        <span>
                            {{ $page }}
                        </span>
                    </a>
                </li>
            @endif
        @endforeach

        {{-- Next Page Link --}}
        @if ($paginator->hasMorePages())
            <li class="pagination__item">
                <a href="{{ $paginator->nextPageUrl() }}" rel="next" aria-label="@lang('pagination.next')">
                    <span>
                        &rsaquo;
                    </span>
                </a>
            </li>
        @else
            <li class="pagination__item pagination__item--disabled" aria-disabled="true" aria-label="@lang('pagination.next')">
                <span aria-hidden="true">
                    &rsaquo;
                </span>
            </li>
        @endif
    </ul>
@endif

leandromatos left a reply on How To Change Number Of Pages Appear On Pagination Slide?

This option of Laravel 5.7 is Very nice @cronix. Thanks for sharing.

leandromatos started a new conversation How To Change Number Of Pages Appear On Pagination Slide?

The default pagination of Laravel 5.6 has 8 items before three dots (...) and 2 after.

How to change this size of 8 items? The pagination element too large in mobile viewport.

30 Jul
11 months ago

leandromatos started a new conversation Best Approach For Call Queue Worker With Limits

Hello guys.

I need to call a queue worker that extracts data from an external api (to be more specific, it is the api of Instagram). This api has a limit of 200 calls per hour.

What is the best way to run this worker by pausing for not to extrapolate 200 calls per hour?

07 Jun
1 year ago

leandromatos started a new conversation Share Content With Component That Lives In The Parent

Can I share content with another component that lives in the parent?

An example, I want to open a modal that lives at the root of the application, but calling it from within another component, which in this case, is a child of the application.

Maybe by example it will be easier to understand what I want to do.

app.vue

    <content-1></content-1>
    <content-2></content-2>
    <modal></modal>
</app>```


content-1.vue
```<template>
    <button>Toggle Modal</button>
    <modal>
        <!-- modal content that will be "injected" into the modal that lives in app.vue -->
    </modal>
</template>```

content-2.vue
```<template>
    <button>Toggle Modal</button>
    <modal>
        <!-- modal content that will be "injected" into the modal that lives in app.vue -->
    </modal>
</template>```
02 Apr
1 year ago

leandromatos left a reply on Manage The Costs Of Projects (Digital Ocean + Forge + Envoyer)

@Cronix, This site is an application without SEO, i don't need indexing in Google or others sites.

leandromatos left a reply on Manage The Costs Of Projects (Digital Ocean + Forge + Envoyer)

My projects use a lot of features that are much easier to manage with Forge and Envoyer, wokers, queues ... My stack is very well structured with Digital Ocean, swapping would not be an option, even because Forge does not configure a server on Heroku =(

leandromatos started a new conversation Manage The Costs Of Projects (Digital Ocean + Forge + Envoyer)

Good afternoon people.

I have 2 projects in Digital Ocean (configured also in Forge and Envoyer) that seasonally need to be on the air, something between 2 to 3 times a year.

What would be the best way to manage the costs of this project? I would like to let it out of the air for not having expenses, but at the same time did not want to have to configure the servers from scratch every time I need them in the air.

I even read about Digital Ocean snapshots but I can not figure out how they work for sure. Can someone help me?

Thank you

25 Feb
1 year ago

leandromatos left a reply on Http Error 500 In Fresh Install Of Laravel 5.6

I removed vagrant box and add again. Now works again!

leandromatos left a reply on Http Error 500 In Fresh Install Of Laravel 5.6

I just checked the PHP version inside the vagrant box. It is 7.0.5. Strange, because my homestead is in the most current version.

leandromatos left a reply on Http Error 500 In Fresh Install Of Laravel 5.6

@crnkovic If I add this code to my route file, the error continues to occur. It does not reach the request to show the PHP information.

By terminal I checked and my version of PHP is 7.1.5.

leandromatos started a new conversation Http Error 500 In Fresh Install Of Laravel 5.6

Hello guys, I created a fresh Laravel 5.6 project through composer.

As I use Homestead, I then added it to Homestead.yml and/ etc / hosts, so I up the box with vagrant up. Everything as I usually do, normal.

The problem is that when trying to access a project in the browser I get a http error 500 message.

I checked my log and he contain this message:

[2018-02-25 11:48:50] local.ERROR: Parse error: syntax error, unexpected '?', Expecting variable (T_VARIABLE) {"exception": "[object] (Symfony \ Component \ Debug \ \ Exception \ FatalThrowableError (code: 0): Parse error: syntax error, unexpected '?', Expecting variable (T_VARIABLE) at /home/vagrant/Code/laravel56/vendor/symfony/routing/Route.php:53)
[stacktrace]
...

Has anyone gone through this? Do you know how I can solve it?

Note: My Homestead is up to date, it is in the latest version.

28 Nov
1 year ago

leandromatos started a new conversation Improving Teamwork With Linters In Laravel Mix

Something I miss about Laravel Mix is the use of linters by default to standardize the js, css and vue codes, by more than one person.

Has anyone ever experienced this? How to solve? What if Laravel Mix has it natively? Is it a good idea @JeffreyWay?

01 Aug
2 years ago

leandromatos left a reply on Can't Get Email Verification Link On Hotmail , Yahoo

@Amelie89 , Try to use a service for sending e-mails. One good is Sparkpost, you can sending 10K emails/month free.

https://www.sparkpost.com/

leandromatos left a reply on Multiple SASS Files

@osherdo, It seems to me that one of your files have dependencies to other files. You may need to make other imports before, is just what I can imagine.

leandromatos left a reply on Multiple SASS Files

Sorry, import, not include. I edited my comment.

leandromatos left a reply on Multiple SASS Files

@osherdo, Include directly in app.scss file.

Something like:

@include('buttons.scss');
@include(''dropzone.scss');

I always includes all css within the app.scss, thus only need to declare app.scss in the gulpfile.

leandromatos left a reply on Can't Get Email Verification Link On Hotmail , Yahoo

@Amelie89 Which service you use for send emails?

leandromatos left a reply on Get List Item Value Outside Of Loop

In this case e.target need be change to e.currentTarget, maybe works!

leandromatos left a reply on Where Are You All From?

Belo Horizonte, MG, Brasil