Suppose I have a table 'table' with columns: col1 and col2. I create it via migration:
public function up()
{
Schema::create('table', function (Blueprint $table) {
$table->increments('id');
$table->string('col1');
$table->string('col2');
}
Is it possible to define the following behaviour at the 'database layer'(without configuring it in the controller or model layers):
When I am inserting a new record in the table, I want the value of col2=col1, if value of col2 is not available.
example:
Table::create(['col1'=>'a']);
id col1 col2
1 a a
Table::create(['col1'=>'a', 'col2'=>'b']);
id col1 col2
2 a b
Hope I've explained clearly what I want to achieve... thank you in advance:)