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?
Try This:
$propiedades = DB::connection('postalcodes')
->table('postal_code')
->get();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.