pascal83's avatar

Create model for existing table

Hello to all,

I check some discussions but i did not find any example...

I'm new to Laravel and i want integrate Laravel to my existing web site. My website have over 100 tables with a lot of rows....

Let's take a look at my existing table profiles, how do I create a model to query/update/insert/delete rows in my existing table profiles. My table has more than 50 fields ....

I know how to create a new model for a new table : php artisan make:model NewTable...

But for my existing table profiles... should i do php artisan make:model Profiles

Thanks a lot !!!

Have a great day!

0 likes
4 replies
richard's avatar
richard
Best Answer
Level 21

Yes, you can create a create a model php artisan make:model Profile and then create its controller to handle CRUD operations. (Rememer the name of the model should be singular, not plural so that automatically the name of the table becomes the pluraliza name.) That is, Model: User, Table: users Model: Order, Table: orders etc

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Profile extends Model
{
    protected $guarded = [];
}


2 likes
pascal83's avatar

Hello Richard,

Nice !! Thanks a lot !! I will test it...

One more question... in Controller... i will create function to store, update fields, delete....

But in the Modal file.... i do nothing in it ? Except for the Protected $fillable and $Hidden ? Thanks a lot !

Pascal

richard's avatar

Depends on what you want to do with the data. You may want to custom setters and getters, add relationships, etc. It all depends on your workflow mate....

pascal83's avatar

Ok Thanks a lot !!! Have a great day !!!

Pascal

Please or to participate in this conversation.