title: Laravel - Trying to get property 'time_in' of non-object
body: <p><strong>i have an error</strong></p>
  <h2>Trying to get property 'time_in' of non-object (View: C:\xampp\htdocs\AttendanceEmployeeSystem\resources\views\admin\attendance.blade.php)</h2>
  <p>This is my code:</p>
  <hr />
  <p><strong>AttendanceController.php</strong></p>
  <hr />
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers;
  
  use DateTime;
  use App\User;
  use App\Latetime;
  use App\Attendance;
  use Illuminate\Support\Facades\Hash;
  use App\Http\Requests\AttendanceEmp;
  
  
   class AttendanceController extends Controller
  {
  /**
   * Display a listing of the attendance.
   *
   * @return \Illuminate\Http\Response
   */
  public function index()
  {
      return view('admin.attendance')-&gt;with(['attendances'=&gt; Attendance::all()]);
  }
  
  /**
   * Display a listing of the latetime.
   *
   * @return \Illuminate\Http\Response
   */
  public function indexLatetime()
  {
      return view('admin.latetime')-&gt;with(['latetimes' =&gt; Latetime::all()]);
  }
  
  
  
  /**
   * assign attendance to employee.
   *
   * @param  \Illuminate\Http\Request  $request
   * @return \Illuminate\Http\Response
   */
  public function assign(AttendanceEmp $request)
  {
      $request-&gt;validated();
  
      if ($employee = User::whereEmail(request('email'))-&gt;first()){
  
          if (Hash::check($request-&gt;pin_code, $employee-&gt;pin_code)) {
                  if (!Attendance::whereAttendance_date(date(&quot;Y-m-d&quot;))-&gt;whereUser_id($employee-&gt;id)-&gt;first()){
                      $attendance = new Attendance;
                      $attendance-&gt;user_id = $employee-&gt;id;
                      $attendance-&gt;attendance_time = date(&quot;H:i:s&quot;);
                      $attendance-&gt;attendance_date = date(&quot;Y-m-d&quot;);
  
                      if (!($employee-&gt;schedules-&gt;first()-&gt;time_in &gt;= $attendance-&gt;attendance_time)){
                          $attendance-&gt;status = 0;
                      AttendanceController::lateTime($employee);
                      };
                      $attendance-&gt;save();
  
                  }else{
                      return redirect()-&gt;route('attendance.login')-&gt;with('error', 'you assigned your attendance before');
                  }
              } else {
              return redirect()-&gt;route('attendance.login')-&gt;with('error', 'Failed to assign the attendance');
          }
      }
  
  
  
      return redirect()-&gt;route('home')-&gt;with('success', 'Successful in assign the attendance');
  }
  
  /**
   * assign late time for attendace .
   *
   * @return \Illuminate\Http\Response
   */
  public static function lateTime(User $employee)
  {
      $current_t= new DateTime(date(&quot;H:i:s&quot;));
      $start_t= new DateTime($employee-&gt;schedules-&gt;first()-&gt;time_in);
      $difference = $start_t-&gt;diff($current_t)-&gt;format('%H:%I:%S');
  
  
      $latetime = new Latetime;
      $latetime-&gt;user_id = $employee-&gt;id;
      $latetime-&gt;duration   = $difference;
      $latetime-&gt;latetime_date  = date(&quot;Y-m-d&quot;);
      $latetime-&gt;save();
  
  }
  
  
  }
  </code></pre>
  <hr />
  <p><strong>attendance.blade.php</strong></p>
  <hr />
  <pre><code>@extends('layouts.main')
  
  @section('content')
  &lt;!-- Content Wrapper. Contains page content --&gt;
  &lt;div class=&quot;content-wrapper&quot;&gt;
  &lt;!-- Content Header (Page header) --&gt;
  &lt;section class=&quot;content-header&quot;&gt;
      &lt;h1&gt;
          Attendance
      &lt;/h1&gt;
      &lt;ol class=&quot;breadcrumb&quot;&gt;
          &lt;li&gt;&lt;a href=&quot;#&quot;&gt;&lt;i class=&quot;fa fa-dashboard&quot;&gt;&lt;/i&gt; Home&lt;/a&gt;&lt;/li&gt;
          &lt;li class=&quot;active&quot;&gt;Attendance&lt;/li&gt;
      &lt;/ol&gt;
  &lt;/section&gt;
  &lt;!-- Main content --&gt;
  &lt;section class=&quot;content&quot;&gt;
      @include('includes.messages')
  
      &lt;div class=&quot;row&quot;&gt;
          &lt;div class=&quot;col-xs-12&quot;&gt;
              &lt;div class=&quot;box&quot;&gt;
                  &lt;div class=&quot;box-header with-border&quot;&gt;
                      &lt;a href=&quot;/attendance/assign&quot; data-toggle=&quot;modal&quot; class=&quot;btn btn-primary btn-sm btn-flat&quot;&gt;&lt;i class=&quot;fa fa-plus&quot;&gt;&lt;/i&gt; New&lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class=&quot;box-body&quot;&gt;
                      &lt;table id=&quot;example1&quot; class=&quot;table table-bordered&quot;&gt;
                          &lt;thead&gt;
                              &lt;th&gt;Date&lt;/th&gt;
                              &lt;th&gt;Employee ID&lt;/th&gt;
                              &lt;th&gt;Name&lt;/th&gt;
                              &lt;th&gt;Attendance&lt;/th&gt;
                              &lt;th&gt;Time In&lt;/th&gt;
                              &lt;th&gt;Time Out&lt;/th&gt;
                          &lt;/thead&gt;
                          &lt;tbody&gt;
                              @foreach( $attendances as $attendance)
  
                              &lt;tr&gt;
                                  &lt;td&gt;{{$attendance-&gt;attendance_date}}&lt;/td&gt;
                                  &lt;td&gt;{{$attendance-&gt;user_id}}&lt;/td&gt;
                                  &lt;td&gt;{{$attendance-&gt;user-&gt;name}}&lt;/td&gt;
                                  &lt;td&gt;{{$attendance-&gt;attendance_time}}
                                      @if( $attendance-&gt;status == 1 )
                                      &lt;span class=&quot;label label-warning pull-right&quot;&gt;On Time&lt;/span&gt;
                                      @else
                                      &lt;span class=&quot;label label-danger pull-right&quot;&gt;Late&lt;/span&gt;
                                      @endif
                                  &lt;/td&gt;
                                  &lt;td&gt;{{$attendance-&gt;user-&gt;schedules-&gt;first()-&gt;time_in}} &lt;/td&gt;
                                  &lt;td&gt;{{$attendance-&gt;user-&gt;schedules-&gt;first()-&gt;time_out}}&lt;/td&gt;
                              &lt;/tr&gt;
  
                              @endforeach
  
                          &lt;/tbody&gt;
                      &lt;/table&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/section&gt;
  &lt;/div&gt;
  
   @endsection
  </code></pre>
  <p>i dont know if its because the time format or something else ,
  please help !</p>
  <p><a href="https://i.stack.imgur.com/hfrr4.png" rel="nofollow noreferrer">a screenshot of the error</a></p>