Okay, I actually got this one figured out.
This was a part of a migration process. The finalized code looks like this. The update code knows to handle the output of DB::raw() as a literal value, and that's great because it lets you use the rest of the Eloquent system except for that point.
Though, you can't use Post::raw() for some reason, so you do have to manually import the DB facade.
use App\Post;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB as DB;
class AddPostBumpedLast extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('posts', function(Blueprint $table)
{
$table->timestamp('bumped_last')->nullable()->default(null)->after('reply_last');
});
Post::withTrashed()
->whereNull('bumped_last')
->update([
"bumped_last" => DB::raw("`reply_last`"),
]);
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('posts', function(Blueprint $table)
{
$table->dropColumn('bumped_last');
});
}
}
I'll move this to code review.