mercredi 23 janvier 2019

How to insert value that is not repeating - Laravel

How can I insert value that is not repeating. Im working on a time keeping system, right now the problem is when I add time and add time again that is the same day the time is repeating. how can I insert time that is not repeating even when I add time again? thank you so much here is my code. Is it possible to do that?

my current data is this and my final output must be that employee_no 10310 must only be one and not repeating data. it should not repeat and not insert id 3.

enter image description here

Controller

public function insertSchedule(Request $request)
{
    $employeeTimeSet = new Schedule;
    $employeeTimeSet->employee_no = $request->input('hidEmployeeno'); 
    $employeeTimeSet->last_name = $request->input('hidEmployeeLast'); 
    $employeeTimeSet->first_name = $request->input('hidEmployeeFirst'); 
    $employeeTimeSet->date_today = $request->input('dateToday'); 
    $employeeTimeSet->time_in = $request->input('timeIn'); 
    $employeeTimeSet->time_out = $request->input('timeOut'); 
    $employeeTimeSet->save();

    $notification = array(
        'message' => 'Employee Time Set!',
        'alert-type' => 'success'
    );
    return redirect('/admin/employeemaintenance/createSchedule')->with($notification, 'Employee Time Set');
}

and here is my View

    {!! Form::open(['action' => 'Admin\EmployeeFilemController@insertSchedule', 'method' => 'POST']) !!}
    <div class="row">
            <div class="form-group col-md-12">

                <small>Employee No. and Name: </small><b><i>  : , </i></b>

                <input type="hidden" name="hidEmployeeno" value='<?php echo $employee->employee_no ?>'>
                <input type="hidden" name="hidEmployeeLast" value='<?php echo $employee->last_name ?>'>
                <input type="hidden" name="hidEmployeeFirst" value='<?php echo $employee->first_name ?>'>
                <hr>

            </div>

    </div>


<table class="table">
        <thead>
          <tr>
            <th>DATE TODAY</th>
            <th>TIME IN</th>
            <th>TIME OUT</th>
            <th>ACTION</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td><b><?php  echo date("F-d-Y");  ?></b></td>
      <!---Date Hidden-->  <input type="hidden" name="dateToday" value='<?php echo date("F-d-Y") ?>'>
            <td><input type="time" name="timeIn" class="form-control col-md-10"></td>
            <td><input type="time" name="timeOut" class="form-control col-md-10"></td>
            <td> </td>

          </tr>
        </tbody>
      </table>
      {!! Form::close() !!}

and my database table

 public function up()
{
    Schema::create('schedules', function (Blueprint $table) {
        $table->increments('id');
        $table->string('employee_no')->nullable();
        $table->string('last_name')->nullable();
        $table->string('first_name')->nullable();
        $table->string('date_today')->nullable();
        $table->string('time_in')->nullable();
        $table->string('time_out')->nullable();
        $table->timestamps();
    });
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire