I am using Relations now, but I am getting an error as
ErrorException in 5ef4934eeff3d728094534ae49b02bc13ec04ae1.php line 122: Undefined variable: a (View: E:\xampp\htdocs\beasiswa\resources\views\beasiswa\daftar_beasiswa.blade.php)
Controller is in BeasiswaController.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Beasiswa;
use App\Databeasiswa;
use Illuminate\Support\Facades\Input;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Http\Controllers\BeasiswaController;
class BeasiswaController extends Controller
{
public function index(){
$data = Beasiswa::all();
return view('beasiswa.daftar_beasiswa')->with('data', $data);
}
Route is defined like this
Route::resource('/beasiswa', 'BeasiswaController');
Route::get('beasiswa', 'BeasiswaController@index');
And this is my Models Beasiswa.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Beasiswa extends Model
{
protected $fillable = [
'nama_bea',
'syarat',
'waktu_pendaftaran',
'status'
];
public function callDatabeasiswa(){
return $this->hasMany('App\Databeasiswa');
}
}
And this is my View on daftar_beasiswa.blade.php
<table class="table table-striped">
<thead>
<tr>
<th style="width: 20px">No</th>
<th>Nama Beasiswa</th>
<th>Periode Pendaftaran</th>
<th style="width: 45px">Edit</th>
<th style="width: 45px">Detail</th>
<th style="width: 45px">Hapus</th>
<th style="width: 45px">Broadcast</th>
</tr>
</thead>
<tbody>
@foreach($data as $a)
<tr>
<td></td>
<td></td>
<td></td>
<td>
<a href="" class="btn btn-info btn-sm"><i class="glyphicon glyphicon-pencil"></i></a>
</td>
<td>
<a href="" class="btn btn-warning btn-sm"><i class="glyphicon glyphicon-eye-open"></i></a>
</td>
<td>
<form action="" method="post">
<input type="hidden" name="_method" value="DELETE"><button type="submit" class="btn btn-danger btn-sm"><i class="glyphicon glyphicon-trash"></i></button>
</form>
</td>
<!-- POST -->
<td>
<!-- BUTTON SEND VIA TELEGRAM -->
<button data-toggle="modal" data-target="#modal-sendtelegram" type="button" class="btn btn-primary btn-sm"><i class="glyphicon glyphicon-send"></i></button>
</td>
</tr>
@endforeach
</tbody>
</table>
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire