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

Quick Starter - Installing Laravel & DataTables #81

Open
bashiirmahad opened this issue Jan 22, 2023 · 2 comments
Open

Quick Starter - Installing Laravel & DataTables #81

bashiirmahad opened this issue Jan 22, 2023 · 2 comments

Comments

@bashiirmahad
Copy link

bashiirmahad commented Jan 22, 2023

In the below method I want to return joined tables data. is there any documentation to refere please

public function query(User $model): QueryBuilder
    {
        return $model->newQuery();
    }

The example of the joint

$users = DB::table('users')
        ->join('businesses', 'users.business_id', '=', 'businesses.id')
        ->select('users.id','users.name', 'users.email', 'businesses.company_name as business')
        ->get();
        return $users->newQuery();
@yajra
Copy link
Owner

yajra commented Jan 27, 2023

Sorry, no documentation atm but I will be working on a new demo site soon.

Anyways, join should be the same with how the query builder works:

    public function query(User $model): QueryBuilder
    {
        return $model->newQuery()
                     ->join('businesses', 'users.business_id', '=', 'businesses.id')
                     ->select('users.id', 'users.name', 'users.email', 'businesses.company_name as business');
    }

@nawt12
Copy link

nawt12 commented Mar 15, 2023

I Have a eloquent solution hope useful

UserDatatable.php
`

...
public function dataTable(QueryBuilder $query): EloquentDataTable
    {
        return (new EloquentDataTable($query))
 //Relationship Code
            ->addColumn('UserName', function (User $user) {
                return $user->UserDetail->UserName;
});
    }


....

  /**
     * Get the dataTable columns definition.
     */
    public function getColumns(): array
    {
        return [
            Column::make('id'),
            Column::make('UserName')->title('Name')
];
    }

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants