myke2424

myke2424

Member Since 1 Year Ago

Experience Points
6,720
Total
Experience

3,280 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
61
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.

Level 2
6,720 XP
Oct
17
5 days ago
Activity icon

Replied to How To Grab All Elements In A Collection

@sinnbeck Yea but first I need to display all duration values instead of the first().

A non well formed numeric value encountered This is what I get when I try your code

Activity icon

Started a new Conversation How To Grab All Elements In A Collection

Currently i'm grabbing the first element for duration using this line:

$duration = $items->first()->duration;

I wan't to be able to grab all the duration values for each corresponding category but i'm not sure how to do it. I tried using $durations = $items->all()->duration but that didn't work.

Here's my entire function:

   $data = $user->times()->whereYear('start_day', 2019)->get();
        $group_months = $data->groupBy(function($entry) {
            return $entry->category;
        })->map(function($items) {
            return $items->groupBy(function($entry) {
                return Carbon::parse($entry->start_day)->format('m');
            })
        ->map(function($items) {
            $duration = $items->first()->duration;
            return $duration;
            });
        });

here's dd($group_months)

Collection {#187 ▼
  #items: array:4 [▼
    "Comp Time Used" => Collection {#292 ▼
      #items: array:3 [▼
        10 => "12:00:00"
        11 => "09:00:00"
      ]
    }

10 represents the month in that collection, but I have three entries under that in my database, so I want my collection to show them all and look like this:

Collection {#187 ▼
  #items: array:4 [▼
    "Comp Time Used" => Collection {#292 ▼
      #items: array:3 [▼
        10 => "12:00:00"
        10 => "08:00:00"
        10 => "11:00:00"
        11 => "09:00:00"
      ]
    }
Activity icon

Replied to Query Builder - How Can I Sum?

@nakov Is there a way to get all the durations instead of using:

$duration = $items->first()->duration;

Because that only grabs the first one.

I tried using this, but it didn't work.

$duration = $items->all()->duration;
Activity icon

Replied to Query Builder - How Can I Sum?

@nakov The durations are all different, I just provided 12 and 12 for an easy example

Activity icon

Replied to Query Builder - How Can I Sum?

@nakov Thank you :) You have been a great help!

Activity icon

Replied to Query Builder - How Can I Sum?

@nakov No, because it doesn't take into account the duration, I edited my post above. Sorry for the confusion, I didn't sleep enough last night.

Activity icon

Replied to Query Builder - How Can I Sum?

@nakov

Ok, that's working, sweet! The only thing now is I need to sum the time entries:

So when I run dd($group_months)

I get

Collection {#322 ▼
  #items: array:1 [▼
    "Comp Time Used" => Collection {#318 ▼
      #items: array:1 [▼
        10 => 2
      ]
    }
  ]
}

For that user I have 2 time entries for October as shown above. I now want to sum those time entries. Each time entry is 12 hours - so I should get 24.00 as the sum

Edit: I should of added this my post too, my bad. I have a 'duration' field in my times_migration, that gets the total difference between start-time and finish-time.

The time format is logged like this: Duration: 12:00:00

So basically I want to add all the duration entries for each month and corresponding category

Activity icon

Replied to Query Builder - How Can I Sum?

@nakov I'm getting 'Undefined variable: entry' when I tested that.

I swapped category_id with category, because that's what i'm grouping them by

Activity icon

Replied to Query Builder - How Can I Sum?

@sinnbeck No I havn't. Right now I'm just storing as categories as "category" in my create_times_migration. I'm only going to have 4 categories.

Does it make more sense to setup a categories table --> add those categories then replace "category" with "category_id" in my times table and add a foreign constraint like:

$table->foreign('category_id')->references('id')->on('categories');
Activity icon

Replied to Query Builder - How Can I Sum?

@nakov Ok my bad, I should have explained this more clearly. So this is what i'm trying to do:

I'm logging time entries for users in my database. Each time entry has an associated 'category'. I have a column in my 'times' table called 'category'

I want to group the data like the following:

January - Vacation time: 20hours - Sick Time: 50 hours - Overtime: 20 hours

February - Vacation time: 10hours - Sick Time: 25 hours - Overtime: 18 hours ect ect.

So all the time entries for january under the category sick-time will be totaled, over-time will be totaled ect.

Activity icon

Replied to Query Builder - How Can I Sum?

@nakov Ok, so that's working and counting the total number of time entries for each month like you provided in your example. How could I now sum those times and display it in my view?

Activity icon

Started a new Conversation Query Builder - How Can I Sum?

I'm logging time entries for users for each month of the year

The times are in the following format: hh:mm:ss

example: 08:32:00

Here's how i'm grouping my months together:

  $data = $user->times()->whereYear('start_day', 2019)->get();
        $group_months = $data->groupBy(function($entry) {
             return Carbon::parse($entry->start_day)->format('m');
      });

How can I sum $group_months, so I can the total time value for each month?

Oct
16
6 days ago
Activity icon

Replied to Routing / Passing Data Help

Dude... You're amazing.

Activity icon

Replied to Routing / Passing Data Help

       $data = DB::table('times')->whereYear('start_day', 2019)->get();
       $group_months = $data->groupBy(function($entry) {
             return Carbon::parse($entry->start_day)->format('m');
      });

Would there be a way to change this so its only for the specific user like how we did previously?

Activity icon

Replied to Routing / Passing Data Help

Thank you!

Activity icon

Replied to Routing / Passing Data Help

You definitely helped, ty! This might be asking too much but i'm trying to figure out how to pass all this data into a table I created in bootstrap.

My table looks like this: https://imgur.com/a/nnrhV1x

So for example I'de go to reports/1 (report for user_id = 1) and the table would look something like this: https://imgur.com/a/t2BNdJR

I'm not worried about the balances, carry-over, allotment ect. Right now I just want to fill the months columns with the appropriate data from my times table for the correct category (Sick-time, comp-time,over-time,personal,vacation) I'm not even sure how to approach this, i'm not the greatest with sql queries.

Even if you can't help with the code, some advice on how to approach this would be greatly appreciated!

If you want to see the table format, i can post the code below

Activity icon

Replied to Routing / Passing Data Help

Yea this makes way more sense, I feel stupid now :p

Thanks a lot for your help and patience lol!

Activity icon

Replied to Routing / Passing Data Help

Ok so that's getting the proper times except I want it so if i go to reports/1, Ide have access to all the times that are tied to the user_id.

So example: Lets say I have my user_id = 1 and I have two entries in times table with a user_id of 1

If I go to reports/1 and used dd($time), I'de have two arrays for the two separate time entries.

Activity icon

Replied to Routing / Passing Data Help

Hmm its still not working properly.

If I go to http://localhost:8000/reports/1 I want to be able to access all data from times for the user_id of 1

http://localhost:8000/reports/2 would access all data from times for the user_id of 2

Right now if I go to reports/any number ->and do the for loop it shows the all the data for every user

Activity icon

Replied to Routing / Passing Data Help

Lets say I want to show all the 'start_time" in an h1 for a user_id = 1 in my show.blade.php how would I do it with your setup?

Usually I just pass $times in then do $times->duration, but since i'm passing $data to the view how it would work?

Activity icon

Replied to Routing / Passing Data Help

It does contain a user_id column already. I'll test out your code

Activity icon

Replied to Routing / Passing Data Help

Right now my user table looks like:

Schema::create('users', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->boolean('is_admin')->nullable();
            $table->string('name');
            $table->string('email')->unique();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();

So you're saying I should add a times_id into the table, then add your code?

Activity icon

Started a new Conversation Routing / Passing Data Help

I'm creating a report table for each user in my database that logs dates/times. Here's my controller:

 public function create()
    {
        $user = auth()->user();

        return view('report.create', compact('user'));
    }

 public function show($id) 
    {
        $data = Time::findOrFail($id);
      
        return view('report.show', compact('data'));  
    }

So right now if I go to /reports/1, it'll only give me access to the times data with an id of one. However, I want it so if I go to reports/1, i'll have access to all the times data for the user with a user_id of 1.

I tried doing the following, but it didn't work and gave me a 404 on every /# page.

 public function show(Time $time) 
    {
        $data= Time::findOrFail($time->user_id)
      
        return view('report.show', compact('data'));  
    }

Here's my routes for 'reports':

Route::resource('reports', 'ReportController');

And here's my times DB migration that i want to use the data from:

 Schema::create('times', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('user_id');
            $table->date('start_day');
            $table->text('category');
            $table->time('start_time');
            $table->time('finish_time');
            $table->time('duration');
            $table->text('notes');
            $table->timestamps();

            $table->foreign('user_id')->references('id')->on('users');
Activity icon

Started a new Conversation Filling Up A Bootstrap Table With Sql Data

Hey, I was wondering how to do this:

I have a table built in boostrap that looks like this: https://imgur.com/a/nnrhV1x

My db table looks like this:

      Schema::create('times', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('user_id');
            $table->date('start_day');
            $table->text('category');
            $table->time('start_time');
            $table->time('finish_time');
            $table->time('duration');
            $table->text('notes');
            $table->timestamps();

            $table->foreign('user_id')->references('id')->on('users');

I want to fill up the table with my database entries for the specifics months of the year.

I'm passing the months and year to view in my controller like this:


    public function show($id) 
    {

        $data = DB::table('times')->whereYear('start_day', 2019)->get();
        $group_months = $data->groupBy(function($entry) {
             return Carbon::parse($entry->start_day)->format('m');
        });

        return view('report.show', compact('group_months'));
        
    }
Activity icon

Replied to How Can I Querie Months And Dates?

Good to know ty!

Activity icon

Replied to How Can I Querie Months And Dates?

Ok i'll try that, I appreciate your help! Thank you

Activity icon

Replied to How Can I Querie Months And Dates?

Can you give me some advice on how to approach this:

I've built a table using bootstrap and i want to generate the table with the times data according to each months.

The table looks like this: https://imgur.com/a/nnrhV1x

My Times DB Migration looks like this:

        Schema::create('times', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('user_id');
            $table->text('start_day');
            $table->text('category');
            $table->time('start_time');
            $table->time('finish_time');
            $table->time('duration');
            $table->text('notes');
            $table->timestamps();

            $table->foreign('user_id')->references('id')->on('users');

As you can see from the table, I want to select the data from the database to fill it up. I'm new to laravel and trying to figure out how to do this.

My table view looks like this:

    <table class="table table-striped table-sm">
                <thead>
                  <tr>
                    <th scope="col">Month</th>
                    <th scope="col">Overtime Hours</th>
                    <th scope="col">Compensation Hours</th>
                    <th scope="col">Vacation</th>
                    <th scope="col">Personal Hours</th>
                    <th scope="col">Sick Hours</th>
                  </tr>
                </thead>
                <tbody>
                  <tr>
                    <th scope="row">Carry Over</th>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                  </tr>
                  <tr>
                    <th scope="row">Allotted</th>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                  </tr>
                  <tr>
                    <th scope="row">Starting Total</th>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                  </tr>
                  <tr>
                    <th scope="row">Jan</th>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                  </tr>
                  <tr>
                    <th scope="row">Feb</th>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                  </tr>
                  <tr>
                    <th scope="row">Mar</th>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                  </tr>
                  <tr>
                    <th scope="row">Apr</th>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                  </tr>
                  <tr>
                    <th scope="row">May</th>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                  </tr>
                  <tr>
                    <th scope="row">Jun</th>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                  </tr>
                  <tr>
                    <th scope="row">Jul</th>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                  </tr>
                  <tr>
                    <th scope="row">Aug</th>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                 </tr>
                 <tr>
                    <th scope="row">Sep</th>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <th scope="row">Oct</th>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <th scope="row">Nov</th>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <th scope="row">Dec</th>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <th scope="row">Yearly Total</th>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <th scope="row">Balance in Hours</th>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <th scope="row">Balance in Days</th>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
                </tbody>
     </table>
</div>
Activity icon

Started a new Conversation How Can I Querie Months And Dates?

I'm new to laravel and not really sure how to do this.

I record dates in my database as 'start_day' in my times table. an example entry will look like: 2019-10-03

Right now all I have is:

$months = DB::table('times')->where('start_day', '=', 2019)

I want to be able to select data for each month of the year.

Oct
09
1 week ago
Activity icon

Started a new Conversation Need Assistance With DB Table Design / Passing Data To View.

I need some assistance with the format of my DB times_table and advice on how I could pass the data to show method to fill out the following table. I'm not really sure how to structure this.

Table: https://i.imgur.com/HuFBhlL.png

Here's my form: https://i.imgur.com/HR0Jsvy.png

Here's my table for the form: times_db_table: https://i.imgur.com/uUEVR6S.png

I made the table using CSS grid - here's the code for the table (show.blade.php)

<div class="container">
    <div class="wrapper">
                <div>Month</div>
                <div>Overtime Hours</div>
                <div>Compensation Hours</div>
                <div>Vacation</div>
                <div>Personal Hours</div>
                <div>Sick Hours</div>

                <div>Carry Over</div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>


                <div>Allotted</div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>

                <div>Starting Total</div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>

                <div>Jan</div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>


                <div>Feb</div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>

                <div>March</div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>

                <div>April</div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>

                <div>May</div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>

                <div>Jun</div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>

                <div>Jul</div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>

                <div>Aug</div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>

                <div>Sep</div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>

                <div>Oct</div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>

                <div>Nov</div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>

                <div>Dec</div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>

                <div>Yearly Total</div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>

                <div>Balance in Hours</div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>

                <div>Balance in Days</div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>

    </div>
</div>

Here's my controller for Time

  public function create()
    {
        $user = auth()->user();

        return view('timetracker.create', compact('user'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {

        $attributes = request()->validate([
            'start_day'=> 'required',
            'category' => 'required',
            'start_time'=> 'required',
            'finish_time'=> 'required',
            'duration' => 'required',
            'notes'=> 'required'
        ]);

        $attributes['user_id']= auth()->id();

        // dd(request($attributes));

        Time::create($attributes);

       

        return redirect('/timetracker');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show(Time $time)
    {
        return view('timetracker.show', compact('time'));
    }
Sep
26
3 weeks ago
Activity icon

Replied to How Can I Import This Vue Component

Not sure, where would I look for this in my project directory?

Activity icon

Replied to How Can I Import This Vue Component

app.js:37940 [Vue warn]: Property or method "config" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.

(found in ) warn @ app.js:37940 app.js:37940 [Vue warn]: Property or method "date" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.

(found in ) warn @ app.js:37940 app.js:37940 [Vue warn]: Unknown custom element: <flat-pickr> - did you register the component correctly? For recursive components, make sure to provide the "name" option.

(found in )

Activity icon

Replied to How Can I Import This Vue Component

Ok I commented that line out. Any idea why the component isn't rendering?

Activity icon

Started a new Conversation How Can I Import This Vue Component

I'm trying to use this datepicker vue component inside my Laravel 6 application. I'm not sure what i'm doing wrong, I was able to get the example component working but when I try this component nothing shows up on the screen. I've installed it through npm and the component is in my package.json

Here's my app.js

/**
 * First we will load all of this project's JavaScript dependencies which
 * includes Vue and other libraries. It is a great starting point when
 * building robust, powerful web applications using Vue and Laravel.
 */

require('./bootstrap');

window.Vue = require('vue');

/**
 * The following block of code may be used to automatically register your
 * Vue components. It will recursively scan this directory for the Vue
 * components and automatically register them with their "basename".
 *
 * Eg. ./components/ExampleComponent.vue -> <example-component></example-component>
 */

// const files = require.context('./', true, /\.vue$/i)
// files.keys().map(key => Vue.component(key.split('/').pop().split('.')[0], files(key).default))
Vue.component('flat-pickr', require('./components/Date.vue'));

Vue.component('example-component', require('./components/ExampleComponent.vue').default);

/**
 * Next, we will create a fresh Vue application instance and attach it to
 * the page. Then, you may begin adding components to this application
 * or customize the JavaScript scaffolding to fit your unique needs.
 */

const app = new Vue({
    el: '#app',
});

Here's the date component

<template>
  <div>
    <flat-pickr v-model="date"></flat-pickr>
  </div>
</template>

<script>
  import flatPickr from 'vue-flatpickr-component';
  import 'flatpickr/dist/flatpickr.css';
  
  export default {    
    data () {
      return {
        date: null,       
      }
    },
    components: {
      flatPickr
    }
  }
</script>

and here's my code inside my view

        <div id="app">
             <flat-pickr v-model="date" :config="config" placeholder="Select a date" name="birthdate"></flat-pickr>
        </div>