namespace Rvsitebuilder\Manage\Events\SiteConfig;
class SiteSaving
{
use SerializesModels;
public function __construct(Request $request)
{
$this->request = $request;
}
public function broadcastOn()
{
return [];
}
}
namespace Rvsitebuilder\Manage\Events\SiteConfig;
class SiteSaved
{
use SerializesModels;
public function __construct(Request $request)
{
$this->request = $request;
}
public function broadcastOn()
{
return [];
}
}
namespace Rvsitebuilder\Manage\Http\Controllers\Admin;
class AppsConfigController extends Controller
{
public function store(AppsConfigRequest $request)
{
+----------------------------------+
| event(new SiteSaving($request)); |
+----------------------------------+
$newRequest = CustomValidate::customRequestKey($request->all());
$appName = $newRequest['appName'];
foreach ($newRequest as $keyName => $val) {
if (empty($val)) {
continue;
}
if ($keyName != 'appName') {
CoreSetting::updateOrCreate(
['key' => $appName.'.'.$keyName],
['key' => $appName.'.'.$keyName, 'value' => $val]);
}
}
+----------------------------------+
| event(new SiteSaved($request)); |
+----------------------------------+
return response()->json(['message' => __('rvsitebuilder/manage::main.save.success')]);
}
}
You can create is a new listeners and coding something you want in to listeners.
namespace Rvsitebuilder\Manage\Listeners;
class CachingProcess
{
public function handle(SiteSaved $event)
{
if (isset($event->request->appName) && $event->request->appName == 'rvsitebuilder/manage') {
// $event->request->route_cache_enabled come from HTML form and always string.
if ($event->request->route_cache_enabled == 'true') {
Config::set('rvsitebuilder/manage.route_cache_enabled', true);
ServiceCache::guzzleRebuildRoute();
} else {
ServiceCache::clearRoute();
}
// $event->request->route_cache_enabled come from HTML form and always string.
if ($event->request->view_cache_enabled == 'true') {
Config::set('rvsitebuilder/manage.view_cache_enabled', true);
ServiceCache::guzzleRebuildView();
} else {
ServiceCache::clearView();
}
}
}
}
Step 1. Create and open EventServiceProvider.php file.
php artisan event:generate
namespace YourVendor\YourProject;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
protected $listen = [
\Rvsitebuilder\Manage\Events\SiteConfig\SiteSaving::class => [
+ \YourVendor\YourProject\Listeners\YourProcess::class,
],
\Rvsitebuilder\Manage\Events\SiteConfig\SiteSaved::class => [
+ \YourVendor\YourProject\Listeners\YourProcess::class,
],
}
Step 2. Coding something in to your listeners.
namespace YourVendor\YourProject\Listeners;
class YourProcess
{
public function handle(SiteSaved $event)
{
if (isset($event->request->appName) && $event->request->appName == 'rvsitebuilder/manage') {
// coding something
}
}