Consume data from an existing table in Laravel

0

I have a base of use of Laravel, however I have always used this by creating the tables by migrations.

I know how to consume data from a database in php too, but in this case I have to build the class for it.

I'm trying to make an application with Laravel that will consume data from an existing database, in this case what is the correct way to use this data in the application? Do I create the same migration if I were to create the existing database?

    
asked by anonymous 08.11.2017 / 19:19

2 answers

-1

You do not need to create migration only model

This tool can help you: link

    
09.11.2017 / 15:55
1
migrations are required if you are going to create or modify tables in the database.

To manipulate these tables, you can Query Builder , that is, without the need for a Model , for example:

$users = DB::table('users')->get();
$user = DB::table('users')->where('name', 'John')->first();
DB::table('users')->where('id', 1)->update(['votes' => 1]);

If you need Model in your application, it should be noted that Model of Laravel has default settings, for example, the table name, which column is primary key, and whether the table has the columns created_at and updated_at . Tables created out of defaults are required to be specified. When in doubt, check out the Eloquent documentation.

<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Pessoas extends Model{
    protected $table = 'pessoas';
    protected $primaryKey = 'id_pessoa';
    public $timestamps = false;
}
    
11.11.2017 / 01:58