Skip to content
New issue

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

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

Already on GitHub? # to your account

laravel yajra datatable equivalent relation with multiple database search not working #3205

Closed
manishjesani912 opened this issue Dec 16, 2024 · 4 comments
Labels

Comments

@manishjesani912
Copy link

manishjesani912 commented Dec 16, 2024

Manager.php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Manager extends Model
{
    protected $connection = 'moodlemanager';
    protected $table = 'managers';
    protected $fillable = ['moodle_id'];

    public function moodleUser()
    {
        return $this->hasOne('App\MoodleUser', 'id', 'moodle_id');
    }
}

MoodleUser.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class MoodleUser extends Model
{
    protected $connection = 'moodle';
    protected $table = 'mdl_user';
    protected $fillable = ['username', 'firstname', 'lastname'];

    public function Manager()
    {
        return $this->hasOne('App\Manager', 'id', 'moodle_id');
    }
}

DashboardController

<?php

namespace App\Http\Controllers\Dashboard;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Requests;
use App\Manager;
use App\MoodleUser;

class DashboardController extends Controller
{

   //Datatable ajax response function
    public function index(Request $request)
    {
        $data = Manager ::select'*')
            ->with(['MoodleUser ']);

         return Datatables::of($data)
                   ->editColumn('MoodleUser ', function ($data) {
                      $actions = $data->MoodleUser->userName;
                      return $actions;
                  })
                 ->make(true);

    }
}

I have two models with different database connection. I load datatable with relation it's working fine with loading but when search it's not working got error SQLSTATE[42S02]: Base table or view not found: 1146 Table

Please give me any suggestion.

Thanks.

  • Operating System
  • PHP Version 8.1
  • Laravel Version 9
  • Laravel-Datatables Version 10
@razorext2
Copy link

check the variable name in

MoodleUser.php

it must be $connection, not $conection

@yajra
Copy link
Owner

yajra commented Jan 8, 2025

Searching on two different connections is fully not supported especially if they point to different databases.

However, if the 2 databases have read access between each other, you can use a query builder.

For example in Oracle, you can query 2 different DB/Schema and table by including the schema name in the SQL.

select leads.id, leads.name, users.name user
from
  db1.users,
  db2.leads
where
  leads.user_id = users.id

Copy link

github-actions bot commented Feb 8, 2025

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the stale label Feb 8, 2025
Copy link

This issue was closed because it has been inactive for 7 days since being marked as stale.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 2, 2025
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants