gutogirardon

gutogirardon

Member Since 11 Months Ago

Experience Points 310
Experience Level 1

4,690 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 0
Lessons
Completed
Best Reply Awards 0
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.

06 Nov
10 months ago

gutogirardon left a reply on How To Generate A Secure Random Password?

@Snapey Thank you too! I'll read it now!

gutogirardon left a reply on How To Generate A Secure Random Password?

@Artak Thank you very much, I already imagined that I could do so, but sometimes the simple things seem wrong, at least for me I'm newbie.

Thx again! Solved.

gutogirardon left a reply on How To Generate A Secure Random Password?

@cmdobueno I'm not complicating, I have doubts and I didnt find answers on the internet.

Basically, I want to when creating a user, generate a temporary password (or not) and send a email with page where the user can create his password himself

gutogirardon started a new conversation How To Generate A Secure Random Password?

In my system only administrators can create new user accounts.

Administrators write the fields:
1) Name
2) Email
3) Phone
4) Profiles

Then I must add the new account and then notify the user (email) by email.

First problem: I have a field called password in user table, but I believe that leaving it nullable is a bad practice. So when I manually add a user, I must fill this field with a random temporary password or can I leave the field blank (for this I must make the field-table nullable)?

Second problem: I need a simple way, to when creating user, notify the same via email to access the system and create your password (something like password reset).

My store user method

public function store(UserRequest $request)
    {
        $input = $request->all();
        DB::beginTransaction();
        
        //where i can set a random password?
        try {
            $user = User::create($input);
            //before create? how?
            if (isset($input['profile_id'])) $synched = $user->profiles()->sync($input['profile_id']);
            if (isset($input['role_id'])) $synched = $user->roles()->sync($input['role_id']);
            
            //and how i can send a email to user $mail
        } catch (\Exception $e) {
            dd($e);
            DB::rollback();
            //Log::error($e->getMessage());
            return Helper::throwError(Helper::msg("error.save"));
        } catch (\Error $e) {
            DB::rollback();
            //Log::error($e->getMessage());
            return Helper::throwError(Helper::msg("error.save"));
        }
        DB::commit();

        if ($user) {
            return Helper::throwSuccess(Helper::msg("create"), redirect()->route('admin.user.index'));
        } else {
            return Helper::throwError(Helper::msg("error.save"));
        }
    }

My input result

array:4 [▼
  "name" => "User Name Heer"
  "email" => "[email protected]"
  "phone_number" => "22432342342"
  "_token" => "c5CXriDbniJDkeyy94qPaVNZkxV0ASoMBL4cwvdY"
]

Thx!

05 Nov
10 months ago

gutogirardon left a reply on Sweetalert Always Running The Same Form (how To Capture The Correct Id?)

Ok, the action now has the correct destination (img 1). But how do I make it run by pressing the modal button? (img 2)

https://imgur.com/1wTGkIW

https://imgur.com/GUp7IYp

    <script>$('a#delete').on('click', function () {
            let action = $(this).data('action');
            alert(action);
            var userId = $(this).data('id');
            //var CSRF_TOKEN = $('meta[name="csrf-token"]').attr('content');
            //var route  = route('admin.user.remove', userId)

            swal({
                    title: "Você tem certeza?",
                    text: "Você está prestes a DELETAR um registro!", type: "warning",
                    showCancelButton: true,
                    cancelButtonText: "Cancelar",
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "Sim, deletar",
                    closeOnConfirm: true
                },
                function () {
                    // $("#myform").submit();
                    $('#myform').attr('action', action);
                    //alert(userId)

                });
        })</script>

idk how to say thank you for your time and patience.

gutogirardon left a reply on Sweetalert Always Running The Same Form (how To Capture The Correct Id?)

Could you show me how? I tried every way, unsuccessfully


    <script>$('a#delete').on('click', function () {
            var userId = $(this).data('id');
            var CSRF_TOKEN = $('meta[name="csrf-token"]').attr('content');
            //var route  = route('admin.user.remove', userId)

            swal({
                    title: "Você tem certeza?",
                    text: "Você está prestes a DELETAR um registro!", type: "warning",
                    showCancelButton: true,
                    cancelButtonText: "Cancelar",
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "Sim, deletar",
                    closeOnConfirm: false
                },
                function () {
                    // $("#myform").submit();
                    alert(userId)

                });
        })</script>

I feel more and more dumb for things like that :(

gutogirardon left a reply on Sweetalert Always Running The Same Form (how To Capture The Correct Id?)

Thanks for your help, it was really a silly mistake on my part.

<script>$('a#delete').on('click', function () {
            var userId = $(this).data('id');
            var CSRF_TOKEN = $('meta[name="csrf-token"]').attr('content');

            swal({
                    title: "Você tem certeza?",
                    text: "Você está prestes a DELETAR um registro!", type: "warning",
                    showCancelButton: true,
                    cancelButtonText: "Cancelar",
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "Sim, deletar",
                    closeOnConfirm: false
                },
                function () {
//                    $("#myform").submit();
                    alert(userId);
                });
        })</script>

This alert(userId); picks up the correct id. How can I run the laravel route from here?

<a href="#" id="delete" data-id="{{$user->id}}"
                                               class="btn btn-danger btn-round delete-button"
                                               title="Excluir"><i class="material-icons">close</i></a>
                                            <form id="myform" action="{{route('admin.user.remove', $user->id)}}"></form>

gutogirardon started a new conversation Sweetalert Always Running The Same Form (how To Capture The Correct Id?)

Hello, I have a table that receives data from users dynamically. I want to click on the "Delete" option, which opens a modal for confirmation. However, with my current code, I'm ALWAYS getting the id of the first user, even by clicking on the others. Could someone help me with the javascript/ajax

Code

@extends('layouts.admin')

@section("title", "Usuários")

@section("breadcrumb")
    <li class="active">
        Usuários
    </li>
@endsection

@push("script")
    @autowherescript('.btn-filter', '.input-filter')
    @autopagesasync(['.card-body tbody','.card-footer'])
    <script>
        $(document).ready(function () {
            $(document).on("autopageasync", function () {
                components(".card-body tbody");
            });
        });
    </script>
@endpush

@section('container')
    <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.0/sweetalert.css'>
    <div class="container-fluid">
        <div class="row">
            <div class="col-md-12">
                @component("admin.widgets.panel.panel-text")
                    @slot("panel_title")
                        Listagem de Usuários
                    @endslot
                    @slot("panel_header")
                        @component("admin.widgets.table.header-btns")
                            @include("admin.widgets.table.header-btn-create", ["btn_route" => route("admin.user.create")])
                        @endcomponent
                    @endslot
                    @slot("panel_body")
                        <table class="table">
                            <thead>
                            <tr>
                                <th>@autosort("name","Nome")</th>
                                <th>@autosort('email','Email')</th>
                                <th class="w125">@autosort('phone','Telefone')</th>
                                <th class="w100 tc">Opções</th>
                            </tr>
                            <tr>
                                <th>
                                    <input type="text" class="form-control input-filter" name="name"
                                           value="@autowherefilter('name')" placeholder="Nome">
                                </th>
                                <th>
                                    <input type="text" class="form-control input-filter" name="email"
                                           value="@autowherefilter('email')" placeholder="Email">
                                </th>
                                <th>
                                    <input type="text" class="form-control input-filter" name="phone"
                                           value="@autowherefilter('phone')" placeholder="Telefone">
                                </th>
                                <th class="w125 tc">
                                    <button class="btn btn-sm btn-primary btn-filter"><i class="fa fa-search"></i>
                                    </button>
                                </th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($users as $user)
                                <tr class="">
                                    <td>{{ $user->name }}</td>
                                    <td>{{ $user->email }}</td>
                                    <td class="phone">{{ $user->phone_number }}</td>
                                    <td class="td-actions text-center">
                                        @can("authorization","user.update")
                                            <a href="{{ route('admin.user.edit', $user->id) }}"
                                               class="btn btn-primary btn-round"
                                               title="Reiniciar Senha"><i class="material-icons">sync</i></a>
                                        @endcan
                                        @can("authorization","user.update")
                                            <a href="{{ route('admin.user.edit', $user->id) }}"
                                               class="btn btn-primary btn-round"
                                               title="Editar"><i class="material-icons">edit</i></a>
                                        @endcan
                                        @can("authorization","user.delete")
                                            <form id="myform" action="{{route('admin.user.remove', $user->id)}}"></form>
                                            <a id="delete" data-title="Colaborador"
                                               class="btn btn-danger btn-round delete-button"
                                               title="Excluir"><i
                                                        class="material-icons">close</i></a>
                                        @endcan
                                    </td>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                    @endslot
                    @slot("panel_footer")
                        @include("admin.widgets.table.footer", ["pagination" => $users])
                    @endslot
                @endcomponent
            </div>
        </div>
    </div>
    <script src='https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.0/sweetalert.min.js'></script>

    <script>$('a#delete').on('click', function () {
            swal({
                    title: "Você tem certeza?",
                    text: "Você está prestes a DELETAR um registro!", type: "warning",
                    showCancelButton: true,
                    cancelButtonText: "Cancelar",
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "Sim, deletar",
                    closeOnConfirm: false
                },
                function () {
                    $("#myform").submit();
                });
        })</script>

@endsection

p.s: form is "really necessary"?

thx a lot

gutogirardon left a reply on How Check If My User Has Relationships?

Solved my problem. I thought it was an ugly method to do. Thanks for the reply, my friend. <3

gutogirardon started a new conversation How Check If My User Has Relationships?

I want to know if a particular user has relationships, if he has, the destroy method can not be executed.

Model User.php

    public function profiles() {
        return $this->belongsToMany('App\Admin\Profile', 'admin_user_profiles')->withTimeStamps();
    }

UserController.php

public function destroy($id)
    {
        try{
            $user = User::findOrfail($id);

            $res = $user->delete();
            if($res) {
                return Helper::throwSuccess(Helper::msg("delete"));
            } else {
                return Helper::throwError(Helper::msg("error.delete"));
            }
        } catch(\Exception $e) {
            return Helper::throwError(Helper::msg("error.restore"));
        }
    }

What is the most elegant way to do this? Conditional? How?

Thx :*

18 Oct
11 months ago

gutogirardon left a reply on Calculate The Difference Of Hours / Minutes Of Specific Day

I can not change because it is a "challenge" of a course that I am doing.

About your answer, how should I interact by date and then by type?

        $points = Records::where('user_id', '=', Auth::user()->id)
            ->get();

        $groupByDay = $points->sortBy('type');

        $result = $groupByDay
            ->groupBy(function ($result, $key) {
                return $result->date->format('d-m');
            });
        
        dd($result);

Result:

Collection {#265 ▼
  #items: array:3 [▼
    "18-10" => Collection {#293 ▶}
    "17-10" => Collection {#279 ▶}
    "16-10" => Collection {#269 ▶}
  ]
}

@D9705996 Basically I want to get all the data, calculate the difference of those 4 dates and return only one result per date.

gutogirardon left a reply on Calculate The Difference Of Hours / Minutes Of Specific Day

Yes, four records a day. There is no way to group the 4 record of the day and calculate from that?!

        $points = Records::where('user_id', '=', Auth::user()->id)
            //->orderBy('date', 'desc')
            ->get();

        $groupByDay = $points->sortBy('date');        

        $res = $groupByDay
            ->groupBy(function ($result, $key) {
                return $result->created_at->format('d');
            });

Return:

Collection {#269 ▼
  #items: array:2 [▼
    18 => Collection {#285 ▼
      #items: array:4 [▶]
    }
    17 => Collection {#264 ▼
      #items: array:4 [▶]
    }
  ]
}

Now, how could I access each day and calculate the difference with carbon?

gutogirardon left a reply on Calculate The Difference Of Hours / Minutes Of Specific Day

Unfortunately I can't change, but yes, it would be easier.

Currently, records are stored one at a time, following the order.

Input -> Interval -> Return Interval -> Output

My difficulty is to make the result take the 4 types of the specific day. I need to calculate for every day with records.

Calculate the times, the carbon will help a lot.

gutogirardon started a new conversation Calculate The Difference Of Hours / Minutes Of Specific Day

I have the following return:

2018-10-18 02:22:35 O
2018-10-18 02:22:34 OI
2018-10-18 02:22:32 II
2018-10-18 02:22:31 I

Where the first value is a timestamp and the second a type field.

This type field is used to determine the date entry of the value.

I = Input;
II = Interval;
OI = Interval Return;
O = Output;

I want to calculate the time difference of I with O, decreasing with the difference of II and OI.

My biggest problem is being in how to compare the type (knowing which one is the first and the last one) and also how not to mix the days because there are more results.

The goal is to create a table containing day, start time, end time and this time difference for each day.

I accept any suggestion.

I'm grateful.