1
I have a table in my comic called lostanimals_, created without using Migrations.
I created a class in the basement for her:
namespace App;
use Illuminate\Database\Eloquent\Model;
class AnimalPerdido extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'id', 'id_usuario', 'lat', 'lng', 'id_tipo_pet', 'raca', 'id_sexo', 'data', 'possui_identificador', 'id_cores', 'informacoes_adicionais'
];
}
I created a controller to return all data from this table:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App/AnimalPerdidoController;
class AnimalPerdidoController extends Controller
{
//Retorna todos os cadastros
public function index()
{
$animaisPerdidos = AnimalPerdido::->get();
return response()->json($animaisPerdidos);
}
}
And on my route:
Route::get('animalperdido', 'AnimalPerdidoController@index');
How can I speak pro How my lost animal table will use this model/controller?
Sought in the documentation? Which part was in doubt?
– Woss
Inside your Controller, put:
use App\AnimalPerdido;
this will be enough for your controller to identify your model.– Alan Sousa
So, my question I posted on the question.. I would like to know how the Variable will apply the controller/model that I created in the table that already exists in the database, because I am not using Migrations... How would he find which table he will perform?
– veroneseComS
So my question is more to know how my controller will know that it has to fetch the data in the lost animals_table as it was not used Migrations.
– veroneseComS
Only declaring a protected property $table = 'lost animals' is sufficient?
– veroneseComS