Skip to content

Instantly share code, notes, and snippets.

@MehulBawadia
Created June 16, 2017 05:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MehulBawadia/3f8bd2e0853859e63092775b67509db9 to your computer and use it in GitHub Desktop.
Save MehulBawadia/3f8bd2e0853859e63092775b67509db9 to your computer and use it in GitHub Desktop.
Reboot the Laravel Application from scratch
<?php
/**
* Reboots the entire application from the scratch.
*
* Removes the all the records from the database table,
* except the migrations table.
*
* Deletes the directories (if provided)
*
* Flushes the values/data stored in application's
* session storage and cache storage.
*
* It can be also be done using YourController@method,
* no such hard and fast rules to use it only in the routes file.
*
* @author IamCrazyD <mehulbawadia@gmail.com>
* @package \ (Root)
* @version 1.0.0
*/
Route::get('/reboot', function() {
$allTables = collect(DB::select('SHOW TABLES'));
$allTables->each(function($table, $key) {
$name = 'Tables_in_' . env('DB_DATABASE');
if ($table->$name != 'migrations') {
DB::table($table->$name)->truncate();
}
});
// delete the directory if needed as it
// may or may or may not be required
File::deleteDirectory(public_path('/email-attachments'));
File::deleteDirectory(public_path('/images/emails'), true);
session()->flush();
cache()->flush();
return redirect('/');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment