3

I`m developing an Attendance Management system.so that my supervisor ask me to develop following view to get attendance time and date value.

enter image description here Few requirements i need.

  1. All the records need to be saved in the database based on Trainee Id.according to that view if one having above ID check the box and then press the mark button that time value and Trainee id must be saved in the database as on time.

  2. Then if once mark it Date value also need to be saved in the database.

  3. Then again check it and press the mark button it must go their as Off time.only 2 records need to be allowed otherwise their can be many on off values.

can anyone suggest me the relevant controller function for that?

here is the relevant above view

<table class="table table-striped">
      <thead>

       <th>Trainee ID</th>
        <th>Name with Initials</th> 
        <th>Time</th>
        <th>Mark Here!</th>
      </thead>

      <tbody>
        @foreach($items as $item)

    <tr>

     <td>{{ $item->trainee_id }}</td>
      <td>{{ $item->name_with_initials }}</td>


        <td>
        <label><input type="checkbox" value="">&nbsp; Time</label>
      </td>

        <td>
        <a class="btn btn-info" href="Bankdetails/{{ $item->trainee_id }}">Mark Here</a>
      </td>
  </tr>
        @endforeach

      </tbody>

</table>
James Z
  • 12,209
  • 10
  • 24
  • 44
Dasun
  • 602
  • 1
  • 11
  • 34
  • Your question is incredibly vague. For this to have a chance of getting a great answer your question needs to be clarified. Furthermore you have not provided any information as too what you have tried to get this working. – milo526 Jun 24 '17 at 17:58
  • Your question really is vague, but I'll provide some guesses to break it down 1. I'm guessing you have a trainees table with Model Trainee, 2. You have an attendance table with model Attendance that has columns similar to these ; `date, trainee_id, time_on, time_off` 3.The Attendance has a `hasMany` relationship with Trainee Am I right? If not then provide those details – hazelcodes Jun 25 '17 at 01:33

4 Answers4

5

Laravel has the Carbon dependency attached to it.

Carbon::now(), include the Carbon\Carbon namespace if necessary.

Edit (usage and docs)

Say I want to retrieve the date and time and output it as a string.

$mytime = Carbon\Carbon::now();
echo $mytime->toDateTimeString();

This will output in the usual format of Y-m-d H:i:s, there are many pre-created formats and you will unlikely need to mess with PHP date time strings again with Carbon.

Documentation: https://github.com/briannesbitt/Carbon

String formats for Carbon: http://carbon.nesbot.com/docs/#api-formatting

Leo
  • 7,274
  • 5
  • 26
  • 48
4

try this

public function store(Request $request)
    {
      $request['time']=date("Y-m-d h:i:s a", time());
        attendance::create($request->all());
                return view('traineeattendance.attendanceo');
    }
Exprator
  • 26,992
  • 6
  • 47
  • 59
0

You might want to use Carbon function here

Refer some docs: https://github.com/briannesbitt/Carbon

Jaskaran Singh Puri
  • 729
  • 2
  • 11
  • 37
0

Example:

use DateTime;

class DashboardController extends Controller
{
    public function index(Request $request)
    {
        $dt = new DateTime();
        $startDate = $dt->format('Y/m/d h:i:s a');
        dd($startDate );
    }

}

Output:

"2023/05/31 08:42:45 am"
Sejal Varu
  • 22
  • 6