jcadima
9/2/2017 - 7:57 PM

Laravel Dates with Carbon

Laravel Dates with Carbon

http://carbon.nesbot.com/docs/#api-humandiff

http://carbon.nesbot.com/docs/#api-commonformats

http://itsolutionstuff.com/post/how-to-get-days-difference-between-two-dates-in-laravelexample.html

<?php

    public function view($id)
    {
        $taskfiles = TaskFiles::where('task_id', $id )->get() ;
        $task_view = Task::find($id) ;

        $from = \Carbon\Carbon::createFromFormat('Y-m-d H:s:i', $task_view->created_at);
        $to = \Carbon\Carbon::createFromFormat('Y-m-d H:s:i', '2017-09-05 9:30:34'); // add here the due date from create task
        $diff_in_days = $from->diffInDays($to);

        // $task_view->project->project_name   will output the project name for this specific task
        // to populate the right sidebar with related tasks
        $projects = Project::all() ;
        return view('task.view')
            ->with('task_view', $task_view) 
            ->with('projects', $projects) 
            ->with('taskfiles', $taskfiles)
            ->with('diff_in_days', $diff_in_days );
    }