I have tried passing just JSON data using Laravel response()->json but Editor keeps giving an error incorrect JSON format. Also when I load the page with the server code for Editor not included in a class, it shows all the JSON data I need. I just can't get it to work in a function and pass to JS. Any help will do.
Thanks.
PS. I am learning Laravel and MVC on the fly. So don't bash me to hard :D
Oooo and one more thing. When using parent::db() it gives this error:
Call to a member function transaction() on null
Code is below.
This is my model EmployeesData.php
class EmployeesData extends Editor
{
public function allEmployees(){
$editor = Editor::inst(parent::db(), 'somename' )
->fields(
Field::inst( 'firstname' ),
Field::inst( 'middlename' ),
Field::inst( 'lastname' )
)
->process( $_POST )
->json();
}
}
This is my controller EmployeesDataAjax.phpuse App\EmployeesData;
class EmployeesDataAjax extends Controller
{
public function getEmployees() {
$employees = new EmployeesData();
return $employees->allEmployees();
}
}
This is my view index.blade.php<script>
$(function(){
var editor = new $.fn.dataTable.Editor( {
ajax: '/employees-data',
table: '#employees-table',
fields: [
{ label: 'First Name', name: 'firstname' },
{ label: 'Last Name', name: 'lastname' }
// etc
]
});
$('#employees-table').DataTable( {
ajax: '/employees-data',
dom: 'Bfrtip',
columns: [
{ data: 'firstname' },
{ data: 'lastname' }
// etc
],
select: true,
buttons: [
{ extend: 'create', editor: editor },
{ extend: 'edit', editor: editor },
{ extend: 'remove', editor: editor }
]
} );
});
</script>
Lastly, this is my routeRoute::get('/employees-data', 'EmployeesDataAjax@getEmployees');
from Latest question asked on Laravel tag.
via kooliebwoy