I am trying to use if/else on a submit button given that if an employee time in is null a Sign In button will be shown otherwise Sign Out button is displayed. Below is my set_attendance form. The if/else does not work as expected. Could you please help how to make it work.
<table class="table table-bordered table-striped">
<thead>
<tr>
<th> {{ __(' SL') }}</th>
<th> {{ __(' Employee Name') }}</th>
<th> {{ __('Action') }}</th>
</tr>
</thead>
<tbody>
@foreach($attendances as $key => $attd)
<tr>
<td>{{$key+1}}</td>
<td>{{ $attd['name'] }}</td>
<td>
<form action="{{ route('attendance.timeclock') }}" method="post" name="department_add_form">
{{ csrf_field() }}
<input type="hidden" name="id" id="id" value="{{ $attd['id'] }}">
@if($timein[1]['timein'] == Null)
<button type="submit" class="btn btn-primary btn-flat"><i class="icon fa fa-plus"></i> {{ __('Sign IN') }}</button>
@else
<button type="submit" class="btn btn-primary btn-flat"><i class="icon fa fa-plus"></i> {{ __('Sign Out') }}</button>
@endif
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
Below is my timeclockcreate method in a controller
public function timeclockcreate(Request $request){
$id = $request->input('id');
$data['attendances'] = User::all()->toArray();
$data['timein'] = User::query()
->leftjoin('attendances', 'attendances.user_id', '=', 'users.id')
->select('attendances.*', 'users.*')
->orderBy('users.name', 'ASC')
->get()
->toArray();
return view('fms.attendances.set_attendance',$data)->with('id', $id)->with('message', 'Inserted successfully.');
}
My attendance table
public function up()
{
Schema::create('attendances', function (Blueprint $table) {
$table->increments('id');
$table->integer('created_by');
$table->integer('user_id')->unsigned();
$table->time('timein')->nullable();
$table->time('timeout')->nullable();
$table->date('logdate');
$table->string('status');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->timestamps();
});
}