Open wrabit opened 4 years ago
#0 /project/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php(64): PDO->prepare('select * from \"...', Array)
#1 /project/vendor/laravel/framework/src/Illuminate/Database/Connection.php(331): Doctrine\\DBAL\\Driver\\PDOConnection->prepare('select * from \"...')
#2 /project/vendor/laravel/framework/src/Illuminate/Database/Connection.php(664): Illuminate\\Database\\Connection->Illuminate\\Database\\{closure}('select * from \"...', Array)
#3 /project/vendor/laravel/framework/src/Illuminate/Database/Connection.php(631): Illuminate\\Database\\Connection->runQueryCallback('select * from \"...', Array, Object(Closure))
#4 /project/vendor/laravel/framework/src/Illuminate/Database/Connection.php(339): Illuminate\\Database\\Connection->run('select * from \"...', Array, Object(Closure))
#5 /project/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2178): Illuminate\\Database\\Connection->select('select * from \"...', Array, true)
#6 /project/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2166): Illuminate\\Database\\Query\\Builder->runSelect()
#7 /project/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2661): Illuminate\\Database\\Query\\Builder->Illuminate\\Database\\Query\\{closure}()
#8 /project/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2167): Illuminate\\Database\\Query\\Builder->onceWithColumns(Array, Object(Closure))
#9 /project/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(539): Illuminate\\Database\\Query\\Builder->get(Array)
#10 /project/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(523): Illuminate\\Database\\Eloquent\\Builder->getModels(Array)
#11 /project/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(488): Illuminate\\Database\\Eloquent\\Builder->get(Array)
#12 /project/app/ThingSheetModel.php(20): Illuminate\\Database\\Eloquent\\Model::all()
#13 /project/vendor/grosv/eloquent-sheets/src/ForgetSheet.php(28): App\\ThingSheetModel->onForget()
#14 /project/vendor/grosv/eloquent-sheets/src/ForgetSheet.php(16): Grosv\\EloquentSheets\\ForgetSheet->triggerCallback('sushi-thing-she...')
So I am hooking into the forget action so in ForgetSheet I am calling an 'onForget' method in the sheet model.
namespace Grosv\EloquentSheets;
use Illuminate\Support\Facades\File;
use function logger;
use function method_exists;
use function str_replace;
class ForgetSheet
{
public function execute($id)
{
File::delete(config('sushi.cache-path').'/'.$id.'.sqlite');
$this->triggerCallback($id);
return response()->noContent();
}
protected function triggerCallback($id)
{
$class = 'App\\' . \Str::studly(str_replace('sushi-', '', $id));
$model = new $class;
if(method_exists($model, 'onForget')) {
$model->onForget();
}
}
}
The problem with this solution is that Sushi doesn't give me any flexibility in naming the file so I can't reliably infer the fully qualified name of the model.