Преглед изворни кода

Custom useful links via database / command (#41)

* Small change to the test command

* Custom useful links via database and command
RamonRobben пре 4 година
родитељ
комит
b32352e925

+ 53 - 0
app/Console/Commands/createUsefulLink.php

@@ -0,0 +1,53 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Models\UsefulLink;
+use Illuminate\Console\Command;
+
+class createUsefulLink extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'create:usefullink';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = 'Create a useful link that user can see on the Dashboard';
+
+    /**
+     * Execute the console command.
+     *
+     * @return int
+     */
+    public function handle()
+    {
+        $this->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;
+    }
+}

+ 8 - 3
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
         ]);
     }
 }

+ 20 - 0
app/Models/UsefulLink.php

@@ -0,0 +1,20 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+
+class UsefulLink extends Model
+{
+    use HasFactory;
+
+    protected $table = 'useful_links';
+
+    protected $fillable = [
+        'icon',
+        'title',
+        'link',
+        'message'
+    ];
+}

+ 61 - 0
database/migrations/2021_06_09_213306_create_useful_links_table.php

@@ -0,0 +1,61 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Schema;
+
+class CreateUsefulLinksTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('useful_links', function (Blueprint $table) {
+            $table->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 <small>(You can use the same login details)</small>'
+        ]);
+        \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 <code>php artisan create:usefullink</code></br> Delete links via database (for now)'
+        ]);
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('useful_links');
+    }
+}

+ 11 - 20
resources/views/home.blade.php

@@ -81,26 +81,17 @@
                         </div>
                         <!-- /.card-header -->
                         <div class="card-body">
-                            <div class="alert alert-dismissible">
-                                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
-                                <h5><a class="alert-link text-decoration-none" target="__blank" href="{{env('PTERODACTYL_URL' , 'http://localhost')}}"><i
-                                            class="fas fa-egg mr-2"></i>Pterodactyl Panel</a></h5>
-                                Use your servers on our pterodactyl panel <small>(You can use the same login details)</small>
-                            </div>
-
-                            <div class="alert alert-dismissible">
-                                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
-                                <h5><a class="alert-link text-decoration-none" target="__blank" href="{{env('PHPMYADMIN_URL' , 'http://localhost')}}"><i
-                                            class="fas fa-database mr-2"></i>phpMyAdmin</a></h5>
-                                View your database online using phpMyAdmin
-                            </div>
-
-                            <div class="alert alert-dismissible">
-                                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
-                                <h5><a class="alert-link text-decoration-none" target="__blank" href="{{env('DISCORD_INVITE_URL')}}"><i
-                                            class="fab fa-discord mr-2"></i>Discord</a></h5>
-                                Need a helping hand? Want to chat? Got any questions? Join our discord!
-                            </div>
+                            @foreach ($useful_links as $useful_link)
+                                <div class="alert alert-dismissible">
+                                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
+                                    <h5>
+                                        <a class="alert-link text-decoration-none" target="__blank" href="{{ $useful_link->link }}">
+                                            <i class="{{ $useful_link->icon }} mr-2"></i>{{ $useful_link->title }}
+                                        </a>
+                                    </h5>
+                                    {!! $useful_link->message !!}
+                                </div>
+                            @endforeach
                         </div>
                         <!-- /.card-body -->
                     </div>