RareAdmin documentation version 1.0
First of all, Thank you so much for purchasing this script. You are awesome!
This documentation is to help you regarding each step of set-up and customization. Please go through the documentation carefully to understand how this script is made and how to edit this properly. Basic Laravel knowledge is required to use this script. You may learn basics from Laravel DOCS.
You will need the following sofwares to customize this template.
This script is based on the Laravel framework and therefore its installation is identical to the installation of Laravel itself.
composer install
.env
file and set your database credentials:
DB_CONNECTION = mysql DB_HOST = 127.0.0.1 DB_PORT = 3306 DB_DATABASE = DATABASE_NAME DB_USERNAME = DATABASE_USERNAME DB_PASSWORD = DATABASE_PASSWORD
php artisan migrate
php artisan db:seed
php artisan key:generate
php artisan serve
With the db:seed command, we also created the first superadmin user, who has permissions to set up new sections in the admin panel and also manage all columns and permissions. So let's log in under his account:
E-mail: superadmin@demo.com Password: password
After logging in, you will see the first main section - Dashboard. Here you will see the first two main Entities (Roles and Users).
With the db:seed command, we also created three Roles (user, client and superadmin). Each role has its own permissions. For example, a user role can only View Entity Users, but clients can not only view Users, but also manage (Edit and Create) users, but a client role cannot Delete users. All these rules can be managed with superadmin account in the Permissions section of the Superadmin menu.
If you have prepared the models and run the migrations, we can continue to Automatically Discover Models or Manually bind Entities to RareAdmin panel.
Basic usageLet's say we want to manage cities through our admin panel. The city has a name, short information, a longer description, GPS coordinates, a thumbnail and an activated/deactivated status. All we need to do is create a model and migration:
php artisan make:model City -mLaravel will create two new files in our project: A city model and a new migration file.
*RAREADMINDIR*/app/Models/City.php
to the following:
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; class City extends Model { protected $guarded = ['id']; }
*RAREADMINDIR*/database/migrations/0000_00_00_000000_create_cities_table.php
to the following:
<?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('cities', function (Blueprint $table) { $table->id(); $table->text('name')->nullable(); $table->text('short_desc')->nullable(); $table->text('long_desc')->nullable(); $table->decimal('lat', 11, 8)->nullable(); $table->decimal('lng', 11, 8)->nullable(); $table->text('thumbnail')->nullable(); $table->boolean('active')->default(false); $table->timestamps(); }); } /** * Reverse the migrations. */ public function down(): void { Schema::dropIfExists('cities'); } };and then run:
php artisan migrate
Note: If you can't see the images after creating a new record, make sure you don't forget to run the laravel artisan command to publish the storage directory: php artisan storage:link
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; class City extends Model { protected $guarded = ['id']; //we will add this method public function user() { return $this->belongsTo(User::class); } }
<?php ... class User extends Model { ... //we will add this method public function cities() { return $this->hasMany(City::class); } ... }
php artisan make:migration add_user_id_to_cities_table --table=cities
*RAREADMINDIR*/database/migrations/0000_00_00_000000_add_user_id_to_cities_table.php
to the following:
<?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::table('cities', function (Blueprint $table) { $table->unsignedBigInteger('user_id')->nullable(); $table->foreign('user_id')->references('id')->on('users'); }); } /** * Reverse the migrations. */ public function down(): void { Schema::table('cities', function (Blueprint $table) { $table->dropForeign('cities_user_id_foreign'); $table->dropColumn('user_id'); }); } };and then run:
php artisan migrate
php artisan make:model Category -m
*RAREADMINDIR*/app/Models/Category.php
:
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; class Category extends Model { protected $guarded = ['id']; public function cities() { return $this->belongsToMany(City::class); } }Add these lines of code to
*RAREADMINDIR*/app/Models/City.php
:
<?php ... class City extends Model { ... //we will add this method public function categories() { return $this->belongsToMany(Category::class); } ... }and
*RAREADMINDIR*/database/migrations/0000_00_00_000000_create_categories_table.php
:
<?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('categories', function (Blueprint $table) { $table->id(); $table->text('name')->nullable(); $table->timestamps(); }); Schema::create('category_city', function (Blueprint $table) { $table->unsignedBigInteger('category_id')->nullable(); $table->foreign('category_id')->references('id')->on('categories'); $table->unsignedBigInteger('city_id')->nullable(); $table->foreign('city_id')->references('id')->on('cities'); }); } /** * Reverse the migrations. */ public function down(): void { Schema::dropIfExists('category_city'); Schema::dropIfExists('categories'); } };
As mentioned above, using RareAdmin requires minimal knowledge of how Laravel Relations works. With RareAdmin you can define and manage any type of relationship in any way. RareAdmin currently supports:
With Laravel Observer, you can handle model events such as save or update.
Quick Example. Let's say you want to set the user's name to uppercase and send an email every time a user's role changes:
<?php namespace App\Observers; use App\Models\User; use Illuminate\Mail\Message; use Illuminate\Support\Facades\Mail; class UserObserver { /** * Handle the User "created" event. */ public function created(User $user): void { if (strlen($user->name) > 1) { $user->name = ucfirst($user->name); $user->saveQuietly(); } } /** * Handle the User "updated" event. */ public function updated(User $user): void { if ($user->isDirty('role_id')) { Mail::raw('Role changed!', function (Message $message) use ($user) { $message->to($user->email); }); } } /** * Handle the User "deleted" event. */ public function deleted(User $user): void ... }
Code released under the MIT License.
For more information about copyright and license check MIT License.