From b32352e92535574b1cd5ecaf3561469fc0aa70c0 Mon Sep 17 00:00:00 2001 From: RamonRobben Date: Thu, 10 Jun 2021 00:16:34 +0200 Subject: [PATCH] Custom useful links via database / command (#41) * Small change to the test command * Custom useful links via database and command --- app/Console/Commands/createUsefulLink.php | 53 ++++++++++++++++ app/Http/Controllers/HomeController.php | 11 +++- app/Models/UsefulLink.php | 20 ++++++ ...06_09_213306_create_useful_links_table.php | 61 +++++++++++++++++++ resources/views/home.blade.php | 31 ++++------ 5 files changed, 153 insertions(+), 23 deletions(-) create mode 100644 app/Console/Commands/createUsefulLink.php create mode 100644 app/Models/UsefulLink.php create mode 100644 database/migrations/2021_06_09_213306_create_useful_links_table.php diff --git a/app/Console/Commands/createUsefulLink.php b/app/Console/Commands/createUsefulLink.php new file mode 100644 index 00000000..e65c57a5 --- /dev/null +++ b/app/Console/Commands/createUsefulLink.php @@ -0,0 +1,53 @@ +alert('You can add Icons to your useful links. Go to https://fontawesome.com/v5.15/icons?d=gallery&p=2 and copy an Icon name.'); + + $icon = $this->ask('Specify the class(es) of the font-awesome icon you want to use as the icon. (e.x: ad, fa fa-briefcase, fab fa-discord)', ''); + $title = $this->ask('What do you want the title to be of this message?', 'Default Useful Link Title'); + $message= $this->ask('Now please type the message you want to show. Tip: You can use HTML to format!'); + $link = $this->ask('Please fill in a valid Link. Users can click the title to go to the link', 'https://bitsec.dev'); + + $usefulLink = UsefulLink::create([ + 'icon' => $icon, + 'title' => $title, + 'link' => $link, + 'message' => $message + ]); + + $this->alert('Command ran successful inserted useful link into database'); + + $this->table(['Icon', 'Title', 'Link', 'Message'], [ + [$icon, $title, $link, $message] + ]); + + return 1; + } +} diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 8c042869..2657d60d 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -2,9 +2,11 @@ namespace App\Http\Controllers; +use App\Models\UsefulLink; use Illuminate\Contracts\Support\Renderable; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\DB; class HomeController extends Controller { @@ -19,14 +21,17 @@ class HomeController extends Controller //set cookie as extra layer of defense against users that make multiple accounts setcookie('4b3403665fea6' , base64_encode(1) , time() + (20 * 365 * 24 * 60 * 60)); - $useage = 0; + $usage = 0; foreach (Auth::user()->Servers as $server){ - $useage += $server->product->price; + $usage += $server->product->price; } + $useful_links = DB::table('useful_links')->get(); + return view('home')->with([ - 'useage' => $useage + 'useage' => $usage, + 'useful_links' => $useful_links ]); } } diff --git a/app/Models/UsefulLink.php b/app/Models/UsefulLink.php new file mode 100644 index 00000000..12d422f7 --- /dev/null +++ b/app/Models/UsefulLink.php @@ -0,0 +1,20 @@ +id(); + $table->string('icon')->default(''); + $table->string('title')->default('Default Title'); + $table->string('link')->default('https://bitsec.dev'); + $table->string('message')->default('Default Message'); + $table->timestamps(); + }); + + \App\Models\UsefulLink::create([ + 'icon' => 'fas fa-egg', + 'title' => 'Pterodactyl Panel', + 'link' => env('PTERODACTYL_URL' , 'http://localhost'), + 'message' => 'Use your servers on our pterodactyl panel (You can use the same login details)' + ]); + \App\Models\UsefulLink::create([ + 'icon' => 'fas fa-database', + 'title' => 'phpMyAdmin', + 'link' => env('PHPMYADMIN_URL' , 'http://localhost'), + 'message' => 'View your database online using phpMyAdmin' + ]); + \App\Models\UsefulLink::create([ + 'icon' => 'fab fa-discord', + 'title' => 'Discord', + 'link' => env('DISCORD_INVITE_URL'), + 'message' => 'Need a helping hand? Want to chat? Got any questions? Join our discord!' + ]); + \App\Models\UsefulLink::create([ + 'icon' => 'fas fa-link', + 'title' => 'Useful Links', + 'link' => '_blank', + 'message' => 'Want to make your own links that show here? Use the command php artisan create:usefullink
Delete links via database (for now)' + ]); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('useful_links'); + } +} diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index 43e786f5..ce1bda01 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -81,26 +81,17 @@
-
- -
Pterodactyl Panel
- Use your servers on our pterodactyl panel (You can use the same login details) -
- -
- -
phpMyAdmin
- View your database online using phpMyAdmin -
- -
- -
Discord
- Need a helping hand? Want to chat? Got any questions? Join our discord! -
+ @foreach ($useful_links as $useful_link) +
+ +
+ + {{ $useful_link->title }} + +
+ {!! $useful_link->message !!} +
+ @endforeach