Fix Email Issues in CyberPanel with SMTP Relay Setup Free Method. First Create a email using your Cyberpanel Under Emai Tab Create Email Second go to the SSL tab and click …
You’ve probably seen many examples of password strength indicators around the web. They let users know the password they’re using is weak and indicate how the strength changes when it’s modified. …
Inside this tutorial, we will create an admin panel in a very short time. Admin panel using Voyager composer package. This article is very interesting to learn admin panel development step …
Inside this tutorial, we will create an admin panel in a very short time. Admin panel using Voyager composer package. This article is very interesting to learn admin panel development step by step.
How to Create Admin Panel using Voyager in Laravel 8
$ composer create-project --prefer-dist laravel/laravel blog
After following these steps we can install a Laravel application into the system.
By using composer we will install voyager. Open the project into the terminal and run this command.
$ composer require tcg/voyager
We need to create a database. For the database, we will use MySQL. We have 2 options available to create a database. Either we can use PhpMyAdmin Manual interface Or we can use a command to create.
In this article, I am going to create a Blog project using Laravel 8 step by step Complete Laravel blog project step by step Part3 if you found In the previous …
In this article, I am going to create a Blog project using Laravel 8 step by step
Complete Laravel blog project step by step Part3
if you found In the previous articles, we have created an Admin login and there have been some login errors. we are trying to log in with an encrypted password but we cant. So, First, we rectify the login functionality
AdminController.php
public function submit_login(Request $request)
{
$request->validate([
'username'=>'required',
'password'=>'required'
]);
$userCheck=Admin::where(['username'=>$request->username,'password'=>$request->password])->count();
if($userCheck>0){
$adminData=Admin::where(['username'=>$request->username,'password'=>$request->password])->first();
session(['adminData'=>$adminData]);
return redirect('admin/dashboard');
}else{
return redirect('admin/login')->with('error',"Invalid Username and Password");
}
Login functionality is working properly. now create a CategoryController with resource controller run the below code
php artisan make:Controller CategoryController -r
Controller created successfully.
Resource controller has been created by default seven method index, create, store, show, edit, update, destroy which was created by the -r flag
CategoryController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class CategoryController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
Open web.php file and import CategoryController and create resource route like below
use App\Http\Controllers\CategoryController;
Route::resource("category",CategoryController::class);
Then run the command
php artisan route:list
You can see all function names and his URI is listed which was created with the -r flag resource controller.
Now we will code under the index function and make a route for the same is given below. Note: We don’t need to create each and every route because by default resource controller make itself
public function index()
{
return view('backend.category.index');
}
before creating the function make a folder name category under the backend folder and a category folder create a file named index.blade.php
Creat route for assessing this page as given below
Note: For assessing the resource controller we need to follow these rules Resources should be defined after the Route:: and “admin/category” is the Url, CategoryController is the class. We don’t need to define route every time like we want to submit form data that time we need to pass URI and make code under the create function
Now we will create a form for the Category and will insert data into the database.
Create a category folder under the backend folder and create a file name add.blade.php and paste the below code
POST is the method for submitting the data and we use enctype=”multipart/form-data” because we can’t save the file or image without “multipart/form-data” and we set the action in the same URL
Now under the store function, we pass the Request parameter and $request getting the form value. Validate function validated that the title is required. Now we are saving the data into the database so we create an object $category= new Category, and $request variable receives the form value. For the image uploading, we simply set hidden filed if the image is not set by the user then by default image field save into the database with no image value. if the image uploaded by the user image will be saved into the public folder as name imgs, getClientOriginalExtension(); is the default function it helps to identify which image format uploaded by the user. time() PHP function for the getting the time.
Now we will create a layout for the admin panel.
Create a folder name layout under the resources→views folder and create a file name layout.blade.php
@yield(‘content’)
we change content only navbar sidebar and footer will be the same. so with the help of layout, we can set simply using extend the layout.
In this article, I am going to create a Blog project using Laravel 8 step by step Complete Laravel blog project step by step Part2 Now in this article, I am …
In this article, I am going to create a Blog project using Laravel 8 step by step
Complete Laravel blog project step by step Part2
Now in this article, I am going to create AdminController and setup, Admin Panel
php artisan make:controller AdminController
Now we will create a login function for Admin login in AdmnController
public function login()
{
return view('backend.login');
}
Now we have to create a login file for the admin login, So, go to the resource folder and under the view, folder create a folder named backend and under the backend folder create login.blade.php file
Now we have to create a route for Admin login, So, go to the routes→web.php file and create a route
First import AdminController
use App\Http\Controllers\AdminController;
then make route like below
Route::get("/admin/login",[AdminController::class,'login']);
Note: /admin/login is the URL and login is the method which is defined in AdminController
First, we have to upload js and CSS files or folders for the Admin Login. we have copied the folder and pasted it to the backend folder under the public folder
public→backend→your files or folder JS and CSS
Now we have to link or load the JS & CSS with the special helper like below. We can access static files like below. Static files are should be in the public folder.
Now we will create model for Admin with migration on below command
php artisan make:model Admin -m
Once successfully create model and database migration table paste the below code in up function
public function up()
{
Schema::create('admins', function (Blueprint $table) {
$table->id();
$table->string('username');
$table->string('password');
$table->timestamps();
});
}
php artisan migrate
Let’s create the seeder for the Admin model
We can manually insert the data into the admin table but we can’t insert passwords with the encrypted format. with the help of seeder, we can insert the demo data
php artisan make:seeder AdminsTableSeeder
Seeder created successfully.
Now insert the admin data, So, go to the seeder folder under the database→seeders and open newly created AdminsTableSeeder.php file
First, we need to import DB and Hash Facades like below
use Illuminate\Support\Facades\DB; /* DB Access */
use Illuminate\Support\Facades\Hash; /* Password hashing */
public function run()
{
DB::table('admins')->insert([
'username'=>'admin',
'password'=>Hash::make('123456789')
]);
}
Once complete run the below command
php artisan db:seed --class=AdminsTableSeeder
Now we will create a login functionality So, go to the AdminController and paste the below code and first, you have to import Admin Model
use App\Models\Admin;
public function submit_login(Request $request)
{
$request->validate([
'username'=>'required',
'password'=>'required'
]);
$userCheck=Admin::where(['username'=>$request->username,'password'=>$request->password])->count();
if($userCheck>0){
$adminData=Admin::where(['username'=>$request->username,'password'=>$request->password])->first();
session(['adminData'=>$adminData]);
return redirect('admin/dashboard');
}else{
return redirect('admin/login')->with('error',"Invalid Username and Password");
}
function dashboard(){
return view('backend.dashboard');
}
}
Details of code
submit_login is a function name
Request as a parameter for the getting from form values
Validate will check both username and password field is required
Now we run the query and check the username and password is matched or not which came from submitting the login form.
and used aggregate function count. if the data is greater than 0 again we run the same Query with first() because the username may be the same for another user. it will check the username then his password and save the data in session as adminData.
Now we create a dashboard function and simply return to the dashboard.
Now we have to create a route both for submitting and dashboard as like below
Note: We are using the POST method for submitting the data.POST method is secure rather than GET because GET method passes the data in URL.
@csrf generate a hidden token without csrf we cant submit the form data.@csrf is Laravel default functionality we can also disable csrf for a specific route.
input name set by username for username and password for password and finally set input type to submit.
Now if the username and password is matching from your database you can login and redirect to the dashboard page.
In this article, I am going to create a Blog project using Laravel 8 step by step Complete Laravel blog project step by step Part1 Laravel Blog Application from scratch #Technologies …
You can see categories table has been created with the columns which we had to define earlier
Note: if note required timestamp columns simply need to add code on the model
protected $timestamp=false;
Model Name Category
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Category extends Model
{
use HasFactory;
protected $timestamp=false;
}
Now similarly we will do Post and Comment Model
php artisan make:model Post -m
Go to the migration folder and open the newly created post table and paste the below code
public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->integer('cat_id');
$table->string('title');
$table->string('thumb');
$table->string('full_img');
$table->text('detail');
$table->string('tags');
$table->timestamps();
});
}
php artisan migrate
php artisan make:model Comment -m
Model created successfully.
Created Migration: 2021_10_15_093715_create_comments_table
Go to the migration folder and open the newly created comments table and paste the below code
public function up()
{
Schema::create('comments', function (Blueprint $table) {
$table->id();
$table->integer('user_id');
$table->integer('post_id');
$table->text('comment');
$table->timestamps();
});
}
In this article, I am going to show how to create a file upload API using Laravel 8 and MySQL. API will test using Postman Open your project folder with a …
In this article, I am going to show how to create a file upload API using Laravel 8 and MySQL. API will test using Postman
Open your project folder with a code editor.
Open your Phpmyadmin and create a table name products, or paste the below code in SQL query
CREATE TABLE `products` (
`id` int NOT NULL,
`ProductName` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
`file_path` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
`description` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
`price` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
`updated_at` datetime NOT NULL,
`created_at` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
Once create successfully go to your code editor and create a controller and model
Then go to your ProductController file and create a function addProduct and import Product models which were created in the previous step
Jump on your ProductController file and paste the below code.
namespace App\Http\Controllers;
// use App\Models\File; use Validator;
use Illuminate\Http\Request;
use App\Models\Product;
class ProductController extends Controller
{
//
function addProduct(Request $req)
{
$product = new Product;
// $req->file('file')->store('products');
$product->ProductName=$req->input('name');
$product->price=$req->input('price');
$product->description=$req->input('description');
$product->file_path=$req->file('file')->store('products');
$product->save();
return $product;
}
}
Note: $product->file_path=$req->file(‘file’)->store(‘products’); if you have not products folder then it will create folder automatically. (file) is your key
Once create a function now you are ready to move on the api.php file under routes→api.php.Now you have to create a Route for addProduct ProductController.php
api.php
<?php
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\UserController;
use App\Http\Controllers\ProductController;
/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});
Route ::post('/addproduct',[ProductController::class,'addProduct']);
POST method is secure for data sending. it’s not showing data on the URL
Laravel 8 tutorial – API authentication with Sanctum Create Laravel Project Then go to your project folder and open it with any code editor setup database in .env file Install Laravel …
create a controller nad /login route in the routes/api.php file:
Create a Controller
php artisan make:controller UserController
Paste the below code in your UserController.php file
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\User;
use Illuminate\Support\Facades\Hash;
class UserController extends Controller
{
//
function index(Request $request)
{
$user= User::where('email', $request->email)->first();
// print_r($data);
if (!$user || !Hash::check($request->password, $user->password)) {
return response([
'message' => ['These credentials do not match our records.']
], 404);
}
$token = $user->createToken('my-app-token')->plainTextToken;
$response = [
'user' => $user,
'token' => $token
];
return response($response, 201);
}
}
Go to routes→api.php import user model and login routes
use App\Http\Controllers\UserController;
Route::post("login",[UserController::class,'index']);
Then Run your project
php artisan serve
Test with postman, Result will be below
Now we need if the user logged in then the user can add product
<?php
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\UserController;
use App\Http\Controllers\DeviceController;
/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
return $request->user();
});
Route::group(['middleware' => 'auth:sanctum'], function(){
//All secure URL's
Route ::post('/addproduct',[DeviceController::class,'addProduct']);
});
Route::post("login",[UserController::class,'index']);
What we did in this code, we had already created DeviceController, model, and import it to api.php file. To secure our API we put it under Route middleware
How to install LEMP stack (Linux, Nginx, MySQL, PHP) on Ubuntu 20.04 VPS In this tutorial, we will install the LEMP stack on the ubuntu 20 based server. LEMP consists of …
How to install LEMP stack (Linux, Nginx, MySQL, PHP) on Ubuntu 20.04 VPS
In this tutorial, we will install the LEMP stack on the ubuntu 20 based server. LEMP consists of Linux, Nginx(pronounced as Engine-x), MySQL for database, and PHP as a backend programming language. Together you can use this combination to host a set of high-performing sites on a single server. I will assume that you have finished the initial server setup as described here on your ubuntu server before installing the LEMP stack on Ubuntu 20.04.
If you are already using some other web server like apache2, it is recommended that you uninstall it or rebuild your server from scratch using the console provided by your hosting provider. DigitalOcean gives a convenient way to achieve this in its dashboard.
Let’s install the LEMP stack now. Follow the steps below:
Step 1 – Update the server’s package index
Update the server’s package index by executing the command below:
Once Droplet and Server Installed run the following command
sudo apt update
Step 2 – Install Nginx Install Nginx using the command below:
sudo apt install nginx
Step 3 – Allow Nginx through the firewall Allow Nginx through the firewall using the command below:
sudo ufw app list
sudo ufw allow 'Nginx Full'
You should get a listing of the application profiles:
Available applications:
Nginx Full
Nginx HTTP
Nginx HTTPS
OpenSSH
You can now go to your server’s IP address to check if Nginx is installed successfully. You should see a page like this:
Step 4 – Installing MySQL
Let’s install MySQL using the command below:
sudo apt install mysql-server
This command will install MySQL, and you will be able to see the console by entering “sudo mysql” in the terminal.
sudo mysql
Step 5 – Installing PHP
The last component in the LEMP stack is PHP. Let’s install it using the command below:
sudo apt install php-fpm php-mysql
If you want to host a PHP website, you will have to copy your files to ‘/var/www/html’ and modify the file located at ‘/etc/nginx/sites-available/default’ to look something like this:
these are the additional lines added inside the “location ~ \.php$ {” block
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
Create a simple index.php under /var/www/html
Here is a sample index.php site for you to try out:
<?php
phpinfo();
?>
You will now be able to use PHP with Nginx. Thanks for reading..!
In this article, I am going to show how to integrate Whatsapp into ReactJs App How to integrate Whatsapp in ReactJs App. Paste the below code Now we add some CSS …
In this article, I am going to show how to integrate Whatsapp into ReactJs App
How to integrate Whatsapp in ReactJs App.
Create React Project
npx create-react-app you-app
Make a folder name components under the src root
Make a file named Whatsapp.js or you can give any name
Removing .php Extension from URL For example, You need to change the URL from http://test.com/test.php tohttp://test.com/test1. Edit the .htaccess file and add the following settings. Now, If the user accessed /test …
Removing .php Extension from URL For example, You need to change the URL from http://test.com/test.php to http://test.com/test1. Edit the .htaccess file and add the following settings.
RewriteEngine On RewriteCond %{REQUEST_FILENAME}
!-f RewriteRule ^([^.]+)$ $1.php [NC,L`]
Now, If the user accessed /test in the browser, it will show the from /test.php.But still, if any user typed the completed URL as http://test.com/test1.php, this will not redirect. Now you need to add some more rules to the .htaccess file.
Removing .html Extension from URL For example, you need to convert your URL from http://test.com/test.html to http://example.com/test. Edit .htaccess file and add the following setting
RewriteEngine On RewriteCond %{REQUEST_FILENAME}
!-f RewriteRule ^([^.]+)$ $1.html [NC,L]
Now, If the user accessed /demo in the browser, it will show the content from /test.html. Now, You may need to redirect users which typed complete URL as http://test.com/test1.html to the new URL http://test.com/test
Support for password authentication was removed on August 13,2021. Please use a personal access token instead. Set Token authentication for Git operations. From 13th August 2021 password authentication was removed, So …
Support for password authentication was removed on August 13,2021. Please use a personal access token instead.
Set Token authentication for Git operations. From 13th August 2021 password authentication was removed, So in this article, I will show how to set Token Authentication
Log in to your GitHub account and follow the next steps:
In the upper-right corner of any page, click your profile photo, then click Settings. Settings icon in the user bar
In the left sidebar, click Developer settings. Developer Plolicysettings
In the left sidebar, click Personal access tokens. Personal access tokens
Click Generate new token. Generate a new token button
Give your token a descriptive name. Token description field
To give your token an expiration, select the Expiration drop-down menu, then click a default or use the calendar picker. Token expiration field
Select the scopes or permissions, you’d like to grant this token. To use your token to access repositories from the command line, select repo.
Selecting token scopes
Click Generate token. Generate token button
Copy safe your Newly created token as you will use this as your password every time you want to perform a push.
**** Note: Treat your tokens like passwords and keep them secret. When working with the API, use tokens as environment variables instead of hardcoding them into your programs.