Undefined variable: info (View:
> C:\xampp\htdocs\Refrensi\LoginQR\resources\views\home.blade.php)
web.php
Route::post('absen', 'AbsenController@absen');
AbsenController
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Absen;
use Auth;
class AbsenController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function timeZone($location){
return date_default_timezone_set($location);
}
public function index()
{
$this->timeZone('Asia/Jakarta');
$user_id = Auth::user()->id;
$date = date("Y-m-d");
$cek_absen = Absen::where(['user_id' => $user_id, 'date' => $date])
->get()
->first();
if (is_null($cek_absen)) {
$info = array(
"status" => "Anda belum mengisi absensi!",
"btnIn" => "",
"btnOut" => "disabled");
} elseif ($cek_absen->time_out == NULL) {
$info = array(
"status" => "Jangan lupa absen keluar",
"btnIn" => "disabled",
"btnOut" => "");
} else {
$info = array(
"status" => "Absensi hari ini telah selesai!",
"btnIn" => "disabled",
"btnOut" => "disabled");
}
$data_absen = Absen::where('user_id', $user_id)
->orderBy('time_out', 'desc')
->paginate(20);
return view('home', compact('data_absen', 'info'));
}
public function absen(Request $request){
$this->timeZone('Asia/Jakarta');
$user_id = Auth::user()->id;
$date = date("Y-m-d"); // 2017-02-01
$time = date("H:i:s"); // 12:31:20
$note = $request->note;
$absen = new Absen;
// absen masuk
if (isset($request->btnIn)){
//cek double data
$cek_double = $absen->where(['date'=> $date, 'user_id' => $user_id])->count();
if ($cek_double >0 ){
return redirect()->back();
}
$absen->create([
'user_id' => $user_id,
'date' => $date,
'time_in' => $time,
'note' => $note]);
return redirect()->back();
} //absen keluar
elseif (isset($request->btnOut)){
$absen->where(['date' => $date, 'user_id' => $user_id])
->update([
'time_out' => $time,
'note' => $note]);
return redirect()->back();
}
return $request->all();
}
}
Absen.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Absen extends Model
{
//
protected $table = 'absen';
protected $fillable = ['user_id', 'date', 'time_in', 'time_out', 'note'];
}
home.blade.php
<tr>
<td colspan="2" style="text-align:center ">
<div class="panel-heading"></div>
</td>
</tr>
<td>
<button type="submit" class="btn btn-flat btn-primary" name="btnIn" >ABSEN MASUK</button>
</td>
<td>
<button type="submit" class="btn btn-flat btn-primary" name="btnOut" >ABSEN KELUAR</button>
</td>
script ini dari laravel 5.3 dan berjalan dengan baik, namun ketika saya mengaplikasikanya di laravel 5.7 ini tidak berjalan dikarenakan variabel tidak ditemukan.
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2XQqeYW
via IFTTT
Aucun commentaire:
Enregistrer un commentaire