Closed MaciejSuchanski closed 5 months ago
Not specifically an inertia question, more of a Laravel question.
Define which connection to use in your Eloquent model.
class MyModel extends Eloquent {
protected $connection = 'db2';
}
Just like in normal Laravel controller that returns a view, get your data and pass it as a parameter on the render function.
$data = MyModel::query()
->where('foo', 'bar')
->get();
return Inertia::render('Folder/View', [
'data' => $data
]);
Thanks for helping here @ntaylor-86
I have 2 databases and by default a return Inertia::render takes the first one, i need to be able to pick the second one both are setup with different names in .env and config/database.php. In normal laravel return i would do: return \DB::connection('db2') ->table('clients')....
How to do it in inertia? For example on this from pingcrm: public function index() { return Inertia::render('Organizations/Index', [ 'filters' => Request::all('search', 'trashed'), 'organizations' => Auth::user()->account->organizations() ->orderBy('name') ->filter(Request::only('search', 'trashed')) ->paginate(10) ->withQueryString() ->through(fn ($organization) => [ 'id' => $organization->id, 'name' => $organization->name, 'phone' => $organization->phone, 'city' => $organization->city, 'deleted_at' => $organization->deleted_at, ]), ]); }