Skip to content

Instantly share code, notes, and snippets.

@ffmit
Last active November 9, 2019 21:14
Show Gist options
  • Save ffmit/f45c9ddbfa44c290afe0203010db72ee to your computer and use it in GitHub Desktop.
Save ffmit/f45c9ddbfa44c290afe0203010db72ee to your computer and use it in GitHub Desktop.
Laravel - Add view with migration
public function up()
{
// Delete the view in case of "php artisan:fresh", to workaround bug
DB::statement('DROP VIEW IF EXISTS userItemlistsView');
// Create views
DB::statement("CREATE VIEW userItemlistsView AS
SELECT
U.NAME AS USER_NAME,
I.NAME AS LIST_NAME
FROM
USERS U,
ITEMLISTS I
WHERE
1 = 1
AND U.ID = I.USER_ID");
}
public function down()
{
// Nothing needed here, see workaround above
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment