尝试从数据表中删除行时,尝试在Laravel中获取非对象的属性

I think I know why the error is happening, I just am not sure how to fix it.

I have a datatable that has a edit and delete button for each row. The table contains the correct data. When I press the delete button for a row, I send the user to a delete confirm view. The error happens in the delete view.

This is the line that errors

<form id="deleteForm" class="form-horizontal" method="post" action="@if (isset($guestlist)){{ URL::to('entir/guests/' . $guestlist->id . '/delete') }}@endif" autocomplete="off">

I believe the issue is due to the $guestlist not being a object.

So in the controller I use the following function to get the data

public function getData()
{
   $guestlists = Guestlist::select(array('guestlists.id',  DB::raw('CONCAT(guestlists.first_name, " ", guestlists.last_name) AS g_name'),'guestlists.start_date', 'guestlists.end_date', 'guestlists.notes', 'guestlists.vendor'));

   return Datatables::of($guestlists)->add_column('actions', '<a href="{{{ URL::to(\'entir/guests/\' . $id . \'/edit\' ) }}}" class="iframe glyphicon glyphicon-edit"> </a>
       <a href="{{{ URL::to(\'entir/guests/\' . $id . \'/delete\' ) }}}" class="glyphicon glyphicon-remove"> </a>                            
        ')
        ->remove_column('id')            
        ->make();
}

Here is the function to call the delete view

public function getDelete($guestlist)
{       
       return View::make('site/entir/guests/delete', compact('guestlist'));

}

If I add dd($guestlist); before the return I can see that it does not contain the row data.

For example, lets say the row has a first name, last name and a few other fields. The id of this row is 10. When I review the output of the dd(); I only see this

string '10' (length=2)

I would have expected the object guestlist and all the row data. I am not sure why this is happening. I am using a laravel starter site (https://github.com/andrewelkins/Laravel-4-Bootstrap-Starter-Site) and I replicated what the author did for his datatable with delete button. When I add dd(); to his delete user function I see his object and the row data... I am puzzled.

Thanks

Your query doesn't fetch any data. Append ->get() to it.

Guestlist::select(array('guestlists.id',  DB::raw('CONCAT(guestlists.first_name, " ", guestlists.last_name) AS g_name'),'guestlists.start_date', 'guestlists.end_date', 'guestlists.notes', 'guestlists.vendor'))->get();

http://laravel.com/docs/5.0/queries

If you need the results in an array, append ->get()->toArray().