Ronald Torres
Ronald Torres

Reputation: 121

Can i add database table manually in laravel?

can i add database table in my Laravel application by creating model file and database in phpmyadmin manually? Will everything work fine? Thanks in advance.

Reason: My application is already hosted in the net and i don't know how to execute artisan commands in cpanel.

Upvotes: 1

Views: 2775

Answers (5)

arash peymanfar
arash peymanfar

Reputation: 63

if you import a table to your database ,for access it with a model first create related model ,for example if you import the car table ,create car model in terminal then in your model

    <?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Car extends Model
{
    protected $table = 'car';
}

with protected $table = 'car' you attach the car table to car model , and you're done

Upvotes: 0

Mohsen
Mohsen

Reputation: 4235

Yes, add what columns you need in Schema::create method of the table and then add columns manually to database as migration create them and its works!

Upvotes: 0

Poria Sobhanlo
Poria Sobhanlo

Reputation: 29

Yes But when two or more programmers are writing together, they are not recommended. GIT can help us better. Even in the database context

Upvotes: 0

skylerfenn
skylerfenn

Reputation: 354

When a production environment doesn't allow artisan commands, you can pull the production database down, run the migrations locally, and then upload the database back.

Alternatively, you definitely can create your tables manually, but it's quite helpful to use migrations. They allow you to avoid manually adding tables in each environment -- less room for errors.

I'd recommend Laravel Valet to get things running locally if you have a Mac. It's quite simple to use. https://laravel.com/docs/5.5/valet

Upvotes: 0

Vivek
Vivek

Reputation: 76

Yes you can add database table to your laravel application using model and migrations. Please refer this : https://laracasts.com/discuss/channels/general-discussion/makemodel-also-creates-a-migration

Upvotes: 1

Related Questions