Everyone hello, first thing I want to do is to show the data from the hotels table attached to the rooms table to the single listing page.
I am getting this error
Exception Message:Call to undefined method App\Hotel::map()
RoomController.php
public function apiRoom() {
$hotels = Room::with('hotel');
return Datatables::eloquent($hotels)
->addColumn('hotel', function (Room $htl) {
return $htl->hotel->map(function ($hotellist) {
return str_limit($hotellist->hotel_name);
});
});
$rooms = Room::all();
return Datatables::of($rooms)
->addColumn('action', function ($rooms) {
return '<a onclick="editForm('.$rooms->id.')" data-toggle="tooltip" data-original-title="Edit"> <i class="fa fa-pencil text-inverse m-r-10"></i> </a>'.
'<a onclick="deleteData('.$rooms->id.')" data-toggle="tooltip" data-original-title="Close"> <i class="fa fa-close text-danger"></i> </a>';
})->make(true);
room-list.blade.php
var table = $('#room-table').DataTable({
processing: true,
serverSide: true,
ajax: "",
columns: [
{data: 'id', name: 'id'},
{data: 'hotel', name: 'hotel.hotel_name'},
{data: 'room_name', name: 'room_name'},
{data: 'bonus_sum', name: 'bonus_sum'},
{data: 'action', name: 'action', orderable: false, searchable: false}
]
});
Model File Room.php
class Room extends Model {
protected $primaryKey = 'id';
protected $fillable = ['hotel_id', 'room_name', 'bonus_sum'];
public function Hotel() {
return $this->belongsTo('App\Hotel', 'hotel_id');
}
}
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2zA7mDO
via IFTTT
Aucun commentaire:
Enregistrer un commentaire