Variables in JavaScript

Variables are simply the name of the storage location. There are two ways we define variables more precisely they are known as the scope of the variable. Scope determines the accessibility (visibility) of these variables. they are:- local variable and global variable.

When variables are defined inside a function then they cannot be used outside of it, these types of variables are called local variables, and when variables are declared outside the function then we can use them anywhere these are global variables.

Tagged : / / /

SASS tutorial for Beginners

SASS is preprocessor of CSS, we can also refer it as CSS with superpower. SASS stands for Syntactically Awesome Style Sheets.

To save the file in SASS format we need to add .scss extension in the file.

Here we will learn how to use SASS in Visual Studio Code.

Initially in VSC we need to make a basic html file naming index.html and a folder for SASS naming sass.

Inside the sass folder we need to create a file naming main.scss.

Before executing the file we need to install an extension in our Visual Studio Code named as “Live Sass Compiler” which is shown below:

Once we install the extension we can see an option Live Sass in the status bar of Visual Studio Code, we need to click on that to make the Sass live.

If the status changes to “watching” automatically we can see that in the Scss folder main.css and main.css.map files are created.

Now whatever code we execute in main.scss it will be imported automatically to the main.css file.

Also we have to pay attention in linking the css script with the html file, as we will not link main.scss file in the html rather we will link main.css file in the html file.

Now we can start styling our file in main.scss and automatically all the codes will be imported in main.css and if it requires any conversion for being compatible with browser it will convert the codes automatically and make it compatible.

  • Key features of Sass which make it better than CSS is we can use :-

– Operators

– Variables

-Nesting

-Mixin

-Parameter

-Partials

It make it convenient for us to execute complicated codes very easily with these features.

Now we will see the features in details:-

  • Operators – We can use operators in Scss as shown below:

And if we see the same code in main.css we will see the actual values without the operators:

  • Variables – We can use variables in scss as shown below:

Here we can see that we have declared a variable named as $bg-color and we have assigned a color to it and we can assign the same variable where we want to use that color.

  • Nesting – We can use nesting in scss as shown below:

Here we can see that inside the class main_header itself we have assigned the values for <h1> and <h2>.

  • Mixin – We can use mixin in scss as shown below:

With the help of mixin feature we can use a set of codes which is suppose to be used number of times in the project, we can assign that set of codes under @mixin file name{} and we can just use the name with @include in the front wherever we want to add those codes.

  • Parameter – We can use parameter in scss as shown below:

In this feature we can use parameters under the mixin feature. In the Line 16 we can see that we have created a mixin named as “name2” in which we have assigned a parameter “$rem” which is assigned in “letter-spacing” and we have called that parameter in the line 31 and 38 by giving it a value of “1rem”.

Similarly we can pass number of parameters to make some changes in the codes which are under the “mixin”.

  • Partials – In partials we can make our scss file less complex by making separate files for variables and mixin and then importing those files in the main scss. By this way we can easily make any changes in the mixin and variable without any complexity.

We need to keep one thing in mind that we have to use “_” while creating the partial files for ‘mixin’ and ‘variables’ so that it does not make any issue with the main scss file.

We can see the example below:

_mixin.scss:

_variable.scss:

main.scss:

Index.html:

main.css:

This is the codes for all the files and we can see the following output:

To know more about SASS you can refer the video given below:

Tagged : / /

How to Create Multiple Role Based Authentication and Access control in Laravel 5.8

 

1st step:-open command prompt on xampp\htdocs directory.

2nd step:-Create laravel project with command given below

3rd step:- move to the project directory on command prompt.

4th step:-Write the command given below for user      Authentication

     php artisan make:auth

5th step:- write the given code in  (database/migration/2014_10_12_000000_create_user_table.php)

6th step:- create model and migration. Write the command given below in command prompt.

           php artisan make:model Role -m

7th step:- write the given code in  (database/migration/ 2020_06_10_060108_create_roles_table)

8th step:- In role model create users() function for relationship. Paste the code in Role.php file given below:-

9th step:- In user model create roles() function for relationship.

Paste the code in User.php file given below:-

10th step:- Now create seeder file for user. File name                UserTableSeeder. Write the command given below in command prompt to create UserTableSeeder:-

php artisan make:seed UsersTableSeeder

   11th step:- Now create seeder file for Role. File name                RoleTableSeeder. Write the command given below in command prompt to create RoleTableSeeder:-

        php artisan make:seed RolesTableSeeder

12th step:-Add insert function in RolesTableSeeder.php file(database/seeds/RolesTableSeeder.php)

Add DB file given below:-

use Illuminate\Support\Facades\DB;

Paste the code given below in RolesTableSeeder.php:-

13th step:-Add insert function in RolesTableSeeder.php file(database/seeds/UsersTableSeeder.php).

Add DB file given below:-

use Illuminate\Support\Facades\DB;

Paste the code given below in UsersTableSeeder.php:-

14th step:-Create Database in mysql.(database name=devopsschool)

15th step:- Go to .env file and set database=devopsschool,username=root

Code for .env file is given below:-

16th step:- Migrate the table to the database. Write the command given below in command prompt:-

php artisan migration

17th step:- Define RoletableSeeder and UserTableSeeder class on Database.php file. The code is given below:-

18th step:- insert datas in tables. Write the code given below in command prompt:

   php artisan db:seed

19th step:- create DashboardController for Admin. Write the code given below in command prompt:

php artisan make:controller Admin/DashboardController

20th step:- create DashboardController for Admin. Write the code given below in command prompt:

php artisan make:controller User/DashboardController

21st step:- create Adminmiddleware for Admin. Write the code given below in command prompt.

php artisan make:middleware AdminMiddleware

22nd step:- create Usermiddleware for User. Write the code given below in command prompt.

php artisan make:middleware UserMiddleware

23rd step:- Use Auth class for authentication in AdminMiddleware.php

24th step:- implement condition in handle() function of AdminMiddleware.php. Code of AdminMiddleware.php is given below:

25th step:- Use Auth class for authentication in UserMiddleware.php.

26th step:- :- Implement condition in handle() function of UserMiddleware.php. Code of UserMiddleware.php is given below:

27th step:-   Implement Condition for Admin and User Login in RedirectIfAuthenticated(app/Http/Middleware/RedirectIfAuthenticated.php). code given below:

28th step:- remove =/home from protected $redirectTo = ‘/home’; from (app/Http/Controllers/Auth/LoginController.php).

29th step:- implement condition in _construct() function in (app/Http/Controllers/Auth/LoginController.php).

 code given below:-

30th step:- remove =/home from protected $redirectTo = ‘/home’; from (app/Http/Controllers/Auth/LoginController.php).

31st step:- implement condition in _construct() function in (app/Http/Controllers/Auth/ResetPasswordController.php)

code given below:-

32nd step:- use AdminMiddleware in Kernal.php file

use App\Http\Middleware\AdminMiddleware;

33rd step:-Define AdminMiddleware in routemiddleware in kernel.php file

'admin' => AdminMiddleware::class,

34th step:- use UserMiddleware in Kernal.php file

use App\Http\Middleware\UserMiddleware;

35th step:- define UserMiddleware in routeMiddleware

'user' => UserMiddleware::class,

36th step:- set Admin middleware and Route. In (route/web.php)

37th step:- set user middleware and route. In (route/web.php)

Code of web.php file is given below:-

Tagged : /