DavyC

Member Since 1 Month Ago

Experience Points
1,120
Total
Experience

3,880 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
9
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 1
1,120 XP
May
06
1 week ago
Activity icon

Started a new Conversation Let An End-user (=the Customer) Create A New HTML Page Including Some Pictures And Text In Existing Website

Hi all,

I might have a very strange question. In a very simple website I have, my customer would like to get the possibility to upload images and text to become a new web page.

So he want to tell "new page", add a title, some text and upload x (unknown how many) images.

Is there a possible laravel function or system for this, not needing too much time to tweak?

I know this is looking like a CMS functionality, but the site is not big enough to convert it to a CMS.

Thanks in advance for any help.

Davy

May
04
1 week ago
Activity icon

Replied to How To Calculate Time Difference Plus Sum This Based On Grouping

Hi Ravish,

it's very strange: I received an email with a new answer from you, but it does not appear here on the page.

You're proposal of the new solution did work like expected !!! Thank you so much for the help. It is much appreciated.

So solution was:

Time::select(
			'times.*',
			DB::raw('sum(TIMESTAMPDIFF(minute, stop, start)) AS total_time'),
		)
         ->groupBy('user_id')
        ->get();
May
03
1 week ago
Activity icon

Replied to How To Calculate Time Difference Plus Sum This Based On Grouping

Thanks again for your time. Unfortunately I now get this message:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'minutes' in 'field list' (SQL: select times.*, TIMESTAMPDIFF(minute, start, stop) AS minutes, sum(minutes) as total_time from times group by user_id)

May
02
1 week ago
Activity icon

Replied to How To Calculate Time Difference Plus Sum This Based On Grouping

Thanks for the try.

This gives back :

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'minutes' in 'field list' (SQL: select times.*, TIMESTAMPDIFF(minute, stop, start) AS minutes, sum(minutes) as total_time from times group by user_id)

Activity icon

Replied to How To Calculate Time Difference Plus Sum This Based On Grouping

Dear,

thanks for your help. Unfortunately this statement returns the error "Argument 2 passed to Illuminate\Database\Query\Builder::selectRaw() must be of the type array, string given".

Apr
30
2 weeks ago
Activity icon

Started a new Conversation How To Calculate Time Difference Plus Sum This Based On Grouping

Hello all,

I have a database with time worked for an employee. It has a userid, start time and stop time.

I want to make an array (to be exported to excel) but only show 1 line per employee only, in which the time worked is summed.

So assume this:

user_id	start						stop
1				8/04/2021 18:38	9/04/2021 14:50
6				8/04/2021 18:38	NULL
2				9/04/2021 14:54	9/04/2021 14:54
1				9/04/2021 14:54	9/04/2021 14:54
6				13/04/2021 15:01	13/04/2021 16:01

How can I get an array, only showing like this:

user_id	total_time
1				20:12:10
2				00:00:11
6				01:00:00

How can I achieve this?

I tried :

        $times = Time::orderBy('user_id', 'ASC')
            ->groupBy(function($sum){
                return Carbon::parse('stop')->diffInSeconds(Carbon::parse('start'))
            ->get();
            });

But I think I'm starting completely the wrong way.

Thanks in advance for this newbie.

Apr
09
1 month ago
Activity icon

Replied to Maatwebsite/Excel : I Need Some Help With The Map Function

I thought of testing simply like this:

<?php

namespace App\Exports;

use App\Time;
use Carbon\Carbon;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;

use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use Maatwebsite\Excel\Concerns\WithColumnFormatting;

class Times2Export implements FromCollection, WithMapping, WithHeadings, ShouldAutoSize, WithColumnFormatting
{

    public function collection()
    {
        return new Collection([
            [1,2,3],
            [4,5,6]
        ]);

        //return Time::all()->sortBy("car_id");
    }

But then I get

Class 'App\Exports\Collection' not found
Activity icon

Replied to Maatwebsite/Excel : I Need Some Help With The Map Function

Hey BobbyBouwmann,

I like your answer, thanks for it.

I noticed I did not fully copy the code of the export.

<?php

namespace App\Exports;

use App\Time;
use Carbon\Carbon;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;

use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use Maatwebsite\Excel\Concerns\WithColumnFormatting;

class Times2Export implements FromCollection, WithMapping, WithHeadings, ShouldAutoSize, WithColumnFormatting
{

    public function collection()
    {
        return Time::all()->sortBy("car_id");
    }

   public function headings(): array
    {
        return [
            'Dossiernummer',            
            'Auto',
            'Taak',
            'Werknemer',
            'Starttijd',
            'Stoptijd',
            'Duur',
        ];
    }

    /**
    * @var Time $time
    */
    public function map($time): array
    {
        $dt = Carbon::parse($time->stop)->diffInSeconds(Carbon::parse($time->start));
        $duur = (is_null($time->stop)) ? 0 : $dt;

        return [
            $time->car->dossiernr,
            $time->car->brand . " " . $time->car->type . " (" . $time->car->license . ")",
            $time->task->name,
            $time->employee->name,
            $time->start,
            $time->stop,
            '=' . $duur . '/86400',
        ];
    }


    public function columnFormats(): array
    {
        return [
            'G' => NumberFormat::FORMAT_DATE_TIME4,
        ];
    }

}

When looking on the page you pasted, I see this:

namespace App\Exports;

use App\Invoice;
use Maatwebsite\Excel\Concerns\FromCollection;

class InvoicesExport implements FromCollection
{
    public function collection()
    {
        return new Collection([
            [1, 2, 3],
            [4, 5, 6]
        ]);
    }
}

I cannot really find what should be the [1,2,3], [4,5,6] in my case then.

Sorry I'm a newbie and maybe it is a stupid question, but a small hint could probably help.

Thanks in Advance,

Davy

Activity icon

Replied to Maatwebsite/Excel : I Need Some Help With The Map Function

Thanks very much for your response. But that's exactly the page I used as info for this test.

Do you mean an extra "GroupBy"? And how would I need to incorporate that please? I never know how many lines will be for each car.

Apr
08
1 month ago
Activity icon

Started a new Conversation Maatwebsite/Excel : I Need Some Help With The Map Function

Hi all,

in my project, I'm exporting a sorted Collection to Excel, using the Maatwebsite/Excel functionality. It is working fine for the moment.

The result is a collection of cars with tasks/times. A car can have 1+ tasks/times. After each car I would like to have an empty line containing a COUNT of the time worked on it.

I started to try the following, but the result is not what I expected. So I think I'm misunderstanding the map function. Can somebody tell me if my idea is totally off and indeed I'm misunderstanding it?

It seems it always goes into the "else" part (or at least it looks like that).

PS the "0" or "1" I'm returning in last columns is only for test.

public function map($time): array
    {
        $dt = Carbon::parse($time->stop)->diffInSeconds(Carbon::parse($time->start));
        $duur = (is_null($time->stop)) ? 0 : $dt;

		$car = $time->car->brand . " " . $time->car->type . " (" . $time->car->license . ")";

        if (!isset($lastcar)){
            $lastcar = $car;
        }

        if ($lastcar != $car) {
            return [
                [
                    '-',
                    '-',
                    '1',
                ],
                [
                    $time->car->brand . " " . $time->car->type . " (" . $time->car->license . ")",
                    $time->task->name,
                    $time->employee->name,
                    $time->start,
                    $time->stop,
                    '=' . $duur . '/86400',
                    '0',
                ]
                ];
        }
        else {
            return [
                $time->car->brand . " " . $time->car->type . " (" . $time->car->license . ")",
                $time->task->name,
                $time->employee->name,
                $time->start,
                $time->stop,
                '=' . $duur . '/86400',
                '1',
            ];
        }

        if (isset($totTime[$car])) {
                $totTime[$car]['totaltime'] = $totTime[$car]['totaltime'] + $dt;
            }
            else {
                $totTime[$car]['totaltime'] = $dt;
            }

        $lastcar = $car;
    }

Is it uberhaupt possible to run an if/else in the map function?

In case this is totally stupid, what would be the best to get this exported please ?

Thanks in advance.

Br,

Davy