-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cache): Added button for clearing cache / close #84
- Loading branch information
1 parent
4d9a96c
commit d859471
Showing
13 changed files
with
233 additions
and
55 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
namespace Anibalealvarezs\Projectbuilder\Controllers\Config; | ||
|
||
use Anibalealvarezs\Projectbuilder\Models\PbCurrentUser; | ||
use Anibalealvarezs\Projectbuilder\Traits\PbControllerTrait; | ||
use Anibalealvarezs\Projectbuilder\Utilities\PbCache; | ||
use Exception; | ||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Artisan; | ||
|
||
class PbCacheController | ||
{ | ||
use PbControllerTrait; | ||
|
||
/** | ||
* Sort model elements | ||
* | ||
* @param Request $request | ||
* @return RedirectResponse | ||
*/ | ||
public function clear(Request $request): RedirectResponse | ||
{ | ||
if (app(PbCurrentUser::class)->hasPermissionTo('clear cache')) { | ||
try { | ||
PbCache::clearAll(); | ||
} catch (Exception $e) { | ||
return $this->redirectResponse( | ||
request: $request, | ||
flashMessage: 'Cache could not be cleared: ' . $e->getMessage(), | ||
withInput: false, | ||
); | ||
} | ||
} else { | ||
return $this->redirectResponse( | ||
request: $request, | ||
flashMessage: 'You are not authorized to clear the cache', | ||
withInput: false, | ||
); | ||
} | ||
|
||
return $this->redirectResponse( | ||
request: $request, | ||
flashMessage: 'Cache cleared successfully', | ||
flashStyle: 'success', | ||
withInput: false, | ||
); | ||
} | ||
|
||
/** | ||
* Sort model elements | ||
* | ||
* @param Request $request | ||
* @return RedirectResponse | ||
*/ | ||
public function clearLaravel(Request $request): RedirectResponse | ||
{ | ||
if (app(PbCurrentUser::class)->hasPermissionTo('clear laravel cache')) { | ||
try { | ||
Artisan::call('cache:clear'); | ||
} catch (Exception $e) { | ||
return $this->redirectResponse( | ||
request: $request, | ||
flashMessage: 'Laravel\'s cache could not be cleared: ' . $e->getMessage(), | ||
withInput: false, | ||
); | ||
} | ||
} else { | ||
return $this->redirectResponse( | ||
request: $request, | ||
flashMessage: 'You are not authorized to clear the Laravel\'s cache', | ||
withInput: false, | ||
); | ||
} | ||
|
||
return $this->redirectResponse( | ||
request: $request, | ||
flashMessage: 'Laravel\'s cache cleared successfully', | ||
flashStyle: 'success', | ||
withInput: false, | ||
); | ||
} | ||
|
||
} |
This file contains 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
This file contains 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
Oops, something went wrong.