Reputation: 2053
Hope you're doing well, I actually have a php function who's Create a new integer (4-byte) column on the table, instead I would like my function create a string column on my MariaDB table.
Thanks (if you need more infos I stay around all the day long)
/**
* Create a new integer (4-byte) column on the table.
*
* @param string $column
* @param bool $autoIncrement
* @param bool $unsigned
* @return \Illuminate\Support\Fluent
*/
public function integer($column, $autoIncrement = false, $unsigned = false)
{
return $this->addColumn('integer', $column, compact('autoIncrement', 'unsigned'));
}
Here's the code reffering to the code under this post:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateConsultantsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('consultants', function (Blueprint $table) {
$table->increments('id');
$table->integer('business_id')->unsigned()->nullable();
$table->foreign('business_id')
->references('id')->on('businesses');
$table->string('trigram')->unique();
$table->date('availability')
->nullable();
$table->integer('years_experience')->nullable();
Upvotes: 2
Views: 1345
Reputation: 1006
So, with Laravel it's pretty easy.
Here you can see how to generate a migration for doing this approach
https://laravel.com/docs/5.5/migrations#generating-migrations
So let's say you'd like to add a shortname field to a users - table
php artisan make:migration add_shortname_to_users_table --table=users
Open the 2017_12_04_104053_add_shortname_to_users_table.php
(the date before will be another)
So, at last just update the up - method
$table->string('shortname');
Run your normal migration and you're done
Upvotes: 2