Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return type void #1367

Closed
samuelecarpene opened this issue Sep 5, 2017 · 3 comments
Closed

Return type void #1367

samuelecarpene opened this issue Sep 5, 2017 · 3 comments
Labels

Comments

@samuelecarpene
Copy link

I updated to v8 of datatables but i have an erorr using orderColumn.

I'm using datatables to show list of users with role.
When click on column header for ordering some data i receive this error

Type error: Return value of Yajra\DataTables\QueryDataTable::applyOrderColumn() must be an instance of Yajra\DataTables\void, none returned

DataTable class

class UsersDataTable extends DataTable
{

public function dataTable($query)
   {
       $dataTable = new EloquentDataTable($query);

       return $dataTable
         ->rawColumns(['action', 'conc', 'active'])
         ->orderColumn('role', 'role_user.role_id $1')
       ;
}


public function query(User $model)
   {
       $query = $model->newQuery()
           ->join('role_user', 'users.id', '=', 'role_user.user_id')->select(['users.*', 'role_user.role_id'])
           ->where('users.id', '!=', Auth::user()->id)
           ->withTrashed();
       return $this->applyScopes($query);
   }
}

I think the problem is the return void in the function definition (https://github.com/yajra/laravel-datatables/blob/8.0/src/QueryDataTable.php#L596) because return type void is implemented in php 7.1 as described here (https://wiki.php.net/rfc/void_return_type#php_rfcvoid_return_type).
If i remove the return type all work correctly.

I checked all code and it is the only one present so i think you can remove to keep compatibility with php 7.0.

Thank you.

  • Operating System Ubuntu 16.04
  • PHP Version 7.0.22
  • Laravel Version 5.4.36
  • Laravel-Datatables Version 8.0.1
@yajra
Copy link
Owner

yajra commented Sep 6, 2017

@samuelecarpene thanks for reporting. Must be added by phpstorm while refactoring the code. Will release a patch for this. Thanks!

yajra added a commit that referenced this issue Sep 6, 2017
yajra added a commit that referenced this issue Sep 6, 2017
[8.0] Remove void return type. Fix #1367
@yajra
Copy link
Owner

yajra commented Sep 6, 2017

Patch released on v8.0.2. Thanks!

@yajra
Copy link
Owner

yajra commented Sep 6, 2017

BTW, you can also remove return $this->applyScopes($query); and just return the $query directly. Apply scopes are automatically applied on the process.

@yajra yajra added the bug label Sep 6, 2017
@github-actions github-actions bot locked and limited conversation to collaborators Oct 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants