File manager - Edit - /var/www/payraty/hris/script.php
Back
<?php $folder = __DIR__ . '/app/Models'; // Change to your models directory $bootedMethod = <<<EOD protected static function booted() { static::addGlobalScope(new OrganisationScope); static::creating(function (\$model) { if (Auth::check()) { \$model->organisation_id = Auth::user()->organisation_id; } }); } EOD; // Get all PHP files in the folder $files = glob($folder . '/*.php'); foreach ($files as $file) { $contents = file_get_contents($file); // Check if the file already has a booted() method if (strpos($contents, 'function booted()') === false) { // Add use statement for Auth and OrganisationScope if not present if (strpos($contents, 'use Illuminate\Support\Facades\Auth;') === false) { $contents = preg_replace( '/<\?php\s+namespace\s+.*?;/s', '$0' . "\n\nuse Illuminate\Support\Facades\Auth;\nuse App\\Scopes\\OrganisationScope;", $contents ); } // Insert the booted method before the last closing bracket of the class $contents = preg_replace('/}\s*$/', $bootedMethod . "\n}", $contents); // Save the updated content back to the file file_put_contents($file, $contents); echo "Updated: $file\n"; } else { echo "Skipped (booted exists): $file\n"; } } echo "Done.\n";
| ver. 1.4 |
Github
|
.
| PHP 8.3.30 | Generation time: 0 |
proxy
|
phpinfo
|
Settings