Created
June 16, 2017 05:06
-
-
Save MehulBawadia/3f8bd2e0853859e63092775b67509db9 to your computer and use it in GitHub Desktop.
Reboot the Laravel Application from scratch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 <[email protected]> | |
* @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