bitsoftsol / laravel-administration
Laravel administration is the autometically building the crud for web and apis when developer will create model and use the LaravelAdmin or LaravelAdminAPI Traits. Developer can build model and schema also using laravel administration interface.
Installs: 3
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Language:Blade
Requires
- php: ^8.1
- darkaonline/l5-swagger: ^8.4
- laravel/framework: ^10.0
- laravel/ui: ^4.2
- yajra/laravel-datatables-oracle: ^10.8
README
About Laravel Administration
Laravel Administration is a powerful package designed to simplify the development of Laravel applications by automating common CRUD (Create, Read, Update, Delete) operations. With this package, you can create models effortlessly and enjoy automatic route generation, views, and controller logic.
Features
- Automatic CRUD operations.
- RESTful API generation.
- Easy-to-use schema builder for advanced customization.
- User authentication and role management.
- MIT-licensed open-source software.
Installation Guide
To get started with Laravel Administration, follow these steps:
-
Create a Laravel Project:
composer create-project laravel/laravel LaravelAdministration
-
Install LaravelAdministration Package:
Install the LaravelAdministration package using Composer:
composer require bitsoftsol/laravel-administration
-
Add LaravelAdminServiceProvider:
Open the
config/app.php
file and add the LaravelAdministration service provider to theproviders
array:'providers' => [ // ... Bitsoftsol\LaravelAdministration\LaravelAdminServiceProvider::class, ],
-
Publish Vendor Files:
Run the following Artisan command to publish vendor files: Select the
LaravelAdminServiceProvider
when prompted.php artisan vendor:publish
-
Install Frontend Assets:
Run the following commands to build assets:
npm install npm run dev
-
Set Database Connection:
Configure your database connection by setting the database name in your
.env
file. -
Run Migrations:
Execute the database migrations and seed data:
php artisan migrate --seed
-
Enable Authentication Routes:
Add the following line inside your
routes/web.php
file:Auth::routes();
-
Serve Your Project:
Serve your Laravel project:
php artisan serve
-
Access Laravel Administration:
Open your browser and access the URL
(host)/admin
(e.g.,http://127.0.0.1:8000/admin
). -
Login Credentials:
Use the following credentials to log in:
- Username: admin@bitsoftsol.com
- Password: bitsoftsol123
-
Create a Superuser:
To create a superuser for your Laravel application, follow these steps:
-
Open your terminal and navigate to the root directory of your Laravel project.
-
Run the following command:
php artisan createsuperuser
-
The createsuperuser
command will prompt you to provide the following information:
- Username: Choose a unique username for the superuser.
- Email: Enter the email address associated with the superuser.
- Password: Set a secure password for the superuser.
- Confirm Password: Re-enter the password for confirmation.
- After successfully providing the required information, the superuser account will be created.
- You can now use the provided username and password to log in as the superuser and access the admin privileges.
- Creating a superuser allows you to manage and control various aspects of your Laravel application with elevated permissions.
-
Congratulations!:
If you can log in and access the Laravel Administration dashboard, congratulations! You have successfully installed Laravel Administration.
Usage Guide
In this section, we will guide you through performing automatic CRUD operations for the Seller
model using Laravel Administration.
-
Generate the Seller Model:
Run the following Artisan command to create the
Seller
model along with its migration file:php artisan make:model Seller -m
-
Define Seller Table Fields:
Inside the generated migration file, define the
Seller
table fields, includingname
,email
,city
,country
, andprofile_image
. -
Add LaravelAdmin and LaravelAdminAPI Traits:
Inside the generated migration file, define the
Seller
table fields, includingname
,email
,city
,country
, andprofile_image
. Enhance the functionality of yourSeller
model by importing theLaravelAdmin
andLaravelAdminAPI
traits.-
Import the
LaravelAdmin
Trait at the top of theSeller
model class:use Bitsoftsol\LaravelAdministration\Traits\LaravelAdmin;
-
Import the
LaravelAdminAPI
Trait on top of theSeller
model class:use Bitsoftsol\LaravelAdministration\Traits\LaravelAdminAPI;
-
Add these two lines inside the
Seller
model class to include the traits:use LaravelAdmin; use LaravelAdminAPI;
-
-
Define Fillable Fields:
In the
Seller
model class, ensure that you add the field names to thefillable
array:protected $fillable = [ "name", "email", "city", "country", "profile_image" ];
-
Run Migrations:
Execute the migration to create the
sellers
table in your database:php artisan migrate
-
Access the Admin Panel:
Open your web browser and visit
http://127.0.0.1:8000/admin
. This is where you can manage your sellers with CRUD operations. -
Congratulations!
You are now able to perform CRUD operations on the
Seller
model without the need for extensive coding.This guide empowers you to efficiently manage your sellers in your Laravel application.
Postman Guide
To use CRUD APIs for the Seller
model, follow these steps:
-
Import the Postman Collection:
Import the provided Postman collection to access the CRUD APIs efficiently. You can download it from here: Postman Collection - Laravel Administration.
-
Import the Environment Variables:
Import the environment variables configuration into Postman for seamless testing. You can download it from here: Postman Environment - Laravel Administration.
-
Set the Host Variable:
In Postman, configure the
host
variable to match your application's URL, typically something likehttp://127.0.0.1:8000
. -
Access the Login API:
Make a POST request to the following API endpoint to log in:
- API Endpoint:
(host)/api/admin/login
- Credentials:
- Username: admin@bitsoft.com
- Password: bitsoft123
After a successful login, you will receive an authentication token.
- API Endpoint:
-
Set the Token Environment Variable:
Once you receive the authentication token upon login, set it as the
(token)
environment variable in Postman for subsequent API requests. -
Fetch the Model ID:
Retrieve the
model_id
for theSeller
model from the following API endpoint:- API Endpoint:
{{host}}/api/admin/crud/models
Set the obtained
model_id
as the(model_id)
environment variable in Postman. - API Endpoint:
-
Access CRUD APIs for the Seller Model:
You can now access the CRUD APIs for the
Seller
model using the environment variables:- Listing of Seller API:
{{host}}/api/admin/crud/{{model_id}}
- Detail of Seller API:
{{host}}/api/admin/crud/{{model_id}}/2
(where 2 represents the seller's ID) - Store Seller API:
{{host}}/api/admin/crud/{{model_id}}
- Update Seller API:
{{host}}/api/admin/crud/{{model_id}}
(include the seller's ID in the form-data within the body tab of Postman) - Delete Seller API:
{{host}}/api/admin/crud/{{model_id}}/3
(where 3 represents the seller's ID)
- Listing of Seller API:
-
Congratulations!
You can now perform CRUD operations on the
Seller
model without the need for additional coding. Enjoy the convenience of Laravel Administration for managing your sellers efficiently.
Schema Builder
In the Laravel Administration application, you can effortlessly create the Seller
model and its associated migration file using the Schema Builder. Here's how:
-
Access the Schema Builder:
- Navigate to
(host)/admin/crud-schema/create
in your web browser, replacing(host)
with your application's URL.
- Navigate to
-
Enter the Model Name:
- On the provided page, input 'Seller' as the model name.
-
Submission:
- Click the 'Submit' button to initiate the generation of the
Seller
model and its corresponding migration file in your project.
- Click the 'Submit' button to initiate the generation of the
Upon successful creation, you'll be redirected to the Schema Builder list. Here, you can find the 'Seller' model in the list.
Managing Your Schema
-
Deleting Schema:
- To remove the 'Seller' model and its migration file from your project, click the 'Delete' button.
-
Defining Schema Fields:
- By clicking the 'Create Schema' button, you'll access a view where you can define the fields of the 'Seller' migration, including the ability to add more fields. If you wish to include image fields in the migration, ensure you suffix column names with '_image.'
-
LaravelAdmin Trait:
- On the 'Create Schema' view, you can select whether to use the 'LaravelAdmin' Trait by ticking the checkbox. If chosen, the trait will be automatically imported when defining seller field names.
Editing Schema
After creating the schema, you'll find an 'Open Editor' button in the 'Seller' row within the Schema Builder listing. Clicking this button will redirect you to a Visual Code Editor view, allowing you to edit the 'Seller' migration and model files.
-
LaravelAdminAPI and LaravelAdmin Traits:
- In the live editor, you can use the 'LaravelAdminAPI' Trait if required, and include the 'LaravelAdmin' Trait if desired. These traits will enable you to access CRUD routes for the Seller model, both through web and API interfaces.
-
Defining Fillable Fields:
- Set the fields of the 'sellers' table in the
fillable
array. These fields will be displayed in the Seller listing view.
- Set the fields of the 'sellers' table in the
Migration
After editing the model and migration files, you can click on the 'Migrate' button to apply the changes to your table. Once the seller table is migrated, you will no longer be able to open the editor or perform migrations, but you can still delete.
CRUD Operations
-
LaravelAdmin Trait:
- If you have included the 'LaravelAdmin' Trait in your Seller model, you can access Seller CRUD operations via the 'CRUD' tab on the web interface.
-
LaravelAdminAPI Trait:
- If you have included the 'LaravelAdminAPI' Trait in your Seller model, you can access Seller CRUD operation APIs using the Postman Collection.
Congratulations!, you've now completed the LaravelAdministration documentation. You're all set to make the most of this powerful tool for Laravel development. Happy coding!