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

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

Open
manishjesani912 opened this issue Dec 16, 2024 · 1 comment

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

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

2 participants