mercredi 7 novembre 2018

How to get specific data from an alternative db in a Laravel 5.7 app with multiple DBs

I got a Laravel 5.7 app that uses 2 DB, apart from the original one with users.

For testing, I'm trying to get data from one of the alternatives, called postal_codes.

My controller:

use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class PostsController extends Controller
{
    public function index(){

        $propiedades = DB::connection('postalcodes')
        ->select('SELECT * FROM postal_code')
        ->get();

        // Saca todos los posts de la bd
        // $posts = Post::all();

        return view('admin.posts.index', compact('propiedades'));
    }

    public function create(){
        return view('admin.posts.create');
    }

    public function store(Request $request){


        // return $request->all();
        $post = new Post;

Though, I get an error on:

    $propiedades = DB::connection('postalcodes')
    ->select('SELECT * FROM postal_code')
    ->get();

Specifically in the ->get() part.

The error says: Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR) Call to a member function get() on array

What am I doing wrong?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire