Skip to content

Commit

Permalink
site settings initiated
Browse files Browse the repository at this point in the history
  • Loading branch information
Raza9798 committed Aug 29, 2024
0 parents commit 5a16fac
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vendor
27 changes: 27 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "intelrx/sitesettings",
"description": "Application global properties",
"require": {
"php": "^8.3"
},
"license": "MIT",
"autoload": {
"psr-4": {
"Intelrx\\Sitesettings\\": "src/"
}
},
"authors": [
{
"name": "raza9798",
"email": "[email protected]"
}
],
"minimum-stability": "dev",
"extra": {
"laravel": {
"providers": [
"Intelrx\\Sitesettings\\SitesettingsProvider"
]
}
}
}
20 changes: 20 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions src/Console/Commands/configCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Intelrx\Sitesettings\Console\Commands;

use Illuminate\Console\Command;
use Intelrx\Sitesettings\SitesettingsProvider;

class configCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'config:settings';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Setups the site settings';

/**
* Execute the console command.
*/
public function handle()
{
// dd('configssssssss');
}
}
13 changes: 13 additions & 0 deletions src/Models/SiteSettings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Intelrx\Sitesettings\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class SiteSettings extends Model
{
use HasFactory;

protected $fillable = ['key', 'value'];
}
45 changes: 45 additions & 0 deletions src/SiteConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Intelrx\Sitesettings;

use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\ValidationException;
use Intelrx\Sitesettings\Models\SiteSettings;

class SiteConfig extends Controller
{
/**
* Handle the incoming request.
*/
public static function store($key, $value)
{
SiteSettings::create([
'key' => $key,
'value' => $value
]);
}

public static function get($key)
{
$data = SiteSettings::where('key', $key)->first();
return $data ? $data->value : null;
}

public static function update($key, $value)
{
$data = SiteSettings::where('key', $key)->first();
if ($data) {
$data->value = $value;
$data->save();
}
}

public static function delete($key)
{
$data = SiteSettings::where('key', $key)->first();
if ($data) {
$data->delete();
}
}
}
31 changes: 31 additions & 0 deletions src/SitesettingsProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Intelrx\Sitesettings;

use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\ServiceProvider;
use Intelrx\Sitesettings\Console\Commands\configCommand;

class SitesettingsProvider extends ServiceProvider
{
/**
* Register services.
*/
public function register(): void
{
$this->loadMigrationsFrom(__DIR__ . '/database/migrations');
}

/**
* Bootstrap services.
*/
public function boot(): void
{
if ($this->app->runningInConsole()) {
$this->commands([
]);
}
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('site_settings', function (Blueprint $table) {
$table->id();
$table->string('key')->unique();
$table->text('value')->nullable();
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('site_settings');
}
};

0 comments on commit 5a16fac

Please sign in to comment.