Categories
Laravel

Laravel 8 Target class [TableSeeder] does not exist

Today I am getting this error when I am trying to refresh seed with php artisan migrate:refresh –seed command. Database Seeder class is called another seeder class with $this->call(CmsPagesSeeder::class); But geeting error Target class [CmsPagesSeeder] does not exist.

Finally I have apply follwing solution and now working fine with command php artisan migrate:refresh –seed or php artisan db:seed or php artisan db:seed –class=CmsPagesSeeder

Laravel 8 Seeders and Factories are now need to add namespace at the top of class file.

Example:

STEP: 1

Rename directory database/seeds to database/seeders

STEP: 2

Open composer.json file and change on autoload section.

STEP: 3

Open Database Seeder file database/seeders/DatabaseSeeder.php and add namespace Database\Seeders; on top of page.

STEP: 4

Open your others seeders file and add namespace Database\Seeders; to all seeders class.

STEP: 5
Done! Now run following commands you can see now DB seeder is working fine.

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please LIKE and SHARE

Categories
Magento 2

Magento 2 – Admin form UI Component ImageUploader Field.

In this article today I will disuse about Magento 2 – admin form UI Component imageUploader field. This article is include all steps UI Components tutorial for image upload from your custom module. UI Component imageUploader xml form field, Show image in edit form, Save image info in database.

Below example code is based on a custom module “Extendfeature_RequestQuote” this is my custom module.

Best article for frontend custom form image uploader
Magento 2 – File or image upload via frontend custom module form and Controller

Step 1: Add UI Component imageUploader field

Please add/create following UI component imageUploader code in your UI form located in Extendfeature/RequestQuote/view/adminhtml/ui_component/form.xml file. My image uploader field name is “filesubmission” show field as “File Attachment” in admin form.

Step 2: Create image-preview.html template file

Please add/create image preview template with following code located in Extendfeature/RequestQuote/view/adminhtml/web/template/image-preview.html file.

Step 3: Crate image upload admin Controller file

Now create a adminhtml image upload Controller Filesubmission.php for image upload in Extendfeature\RequestQuote\Controller\Adminhtml\Requestquote\Filesubmission.php file with following code.

Step 4: Crate image upload Model

Now we create a image upload Model ImageUploader.php, in this we added more methods related upload image into pub/media/requestaquote directory, here “requestaquote” is IMAGE_UPLOAD_DIRECTORY name. Please create a model file with following code.

Step 5: Define Image Uploader configuration in di.xml file

Define Image Uploader configuration in your module di di.xml file with following code, File located in Extendfeature/RequestQuote/etc/di.xml.

Magento 2 - Admin form UI Component ImageUploader Field

Step 6: Image name save into the database field

To save image name into the database field please add follow below code into Save controller Extendfeature/RequestQuote/Controller/Adminhtml/Requestquote/Save.php file inside execute method.

Step 7: Display image after save records in edit form

Now add following code into DataProvider like Extendfeature/RequestQuote/Model/Requestquote/DataProvider.php File to display image after save records inside public function getData() method.

Now, Execute below commands via SHELL and enjoy image uploader function in your UI form.

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please SHARE this post.

Categories
WordPress

How to Create WordPress Custom Post Types?

In this post today I will disuse How to Create WordPress Custom Post Types and displaying with Shortcode and page template. Each new developer need to learn how to easily create custom post types in WordPress site. Also WordPress regular blog posts use Categories and Tags to create an organization structure. In this article I also disuse how to crate separate Categories and Tags for custom post types.

Working With Custom Post Types

So your new custom post types need to effectively create and use, you will need to be familiar with the following:

  • Creating custom Post Types
  • Creating custom Taxonomies
  • Creating custom Tags

Creating Custom Post Types

Let’s start and register custom post type in your theme functions.php file by method register_post_type. It will be located in public_html/wp-content/themes/YOUR_THEME_NAME/functions.php Open this file via editor and add following code to register custom post type.

For more information I will shortly describe some args details in below.

  • labels The labels option should be an array defining the different labels that a custom post type can have. I have separated this out above just to make the arguments for registering a post type clearer.
  • description A short explanation of our custom post type, what it does and why we are using it.
  • public This option controls a bunch of things in one go. Setting this to true will set a bunch of other options (all to do with visibility) to true.
  • menu_position Defines the position of the custom post type menu in the back end. Setting it to “7” places it below the “posts” menu.
  • supports This option sets up the default WordPress controls that are available in the edit screen for the custom post type. By default, only the title field and editor are shown.
  • has_archive If set to true, rewrite rules will be created for you, enabling a post type archive at http://yoursite.com/posttype/ (by default)

Our current custom post types Faqs associated with a custom taxonomy called genres. I also set hierarchical to false If you would like your custom post type to behave like Pages, then you can set this value to true.

Category for Custom Post Type

Now we are going to register taxonomy for custom post type named “Faq Categories” after register_post_type method in functions.php file by register_taxonomy method. This categories we only use for Faq post types.

Registering categories for custom post type is done, We added some labels and set hierarchical option to true. This enables custom “category style” to taxonomies. When we set it to false (this is the default), taxonomy will be like the default tags.

Displaying Custom Post Types by Shortcode

Now I am going to create a shortcode [faqs] to displaying custom post type post items. Please added following code in your theme functions.php in theme public_html/wp-content/themes/YOUR_THEME_NAME/functions.php.

We can pass tow parameter via shortcode “category” Example: [faqs category=”7″] (7) is category ID, Second one is “class” Example: [faqs class=”sidebar-categories”] is CSS class.

Displaying Custom Post Types in Template

Also we can listed custom post via template file, open a template file via editor from your theme public_html/wp-content/themes/YOUR_THEME_NAME/ directory. By querying the database, you can retrieve post items from a custom post type.

So in this post we are completed 3 (three) part, 1. Create Custom Post Types, 2. Categories for Custom Post Types, 3. Displaying Custom Post Items by Shortcode and Template.

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please SHARE this post.

Categories
WordPress

How to Add New Custom Widget Area?

In this post today I will discus How to Add New Custom Widget Area in WordPress theme. Each new developer need to learn WordPress basics, Also need to know how customize your WordPress site.

After creating new themes developer to customize WordPress themes, So need to know how to create custom Widget area and display Widget area in WordPress theme.

Registering a Custom Widget Area:

Let’s start and registering a widget area add following code in your theme functions.php file by method register_sidebar. It will be located in public_html/wp-content/themes/YOUR_THEME_NAME/functions.php Open this file via editor and add following code to registering new Widget area.

After register a new widget area, WordPress automatically display it as an option under Appearance => Widgets in WordPress admin section. My custom Widget name is “Single Page Top Sidebar” and ID is “sidebar_single_top”.

Registering a Custom Widget Area

Display Your Specific Custom Widget Area:

WordPress not automatically display your newly created Widget area on frontend theme. Because we have not yet told to WordPress where to display newly created Widget area. I have create new widget are for post single page sidebar top place widget area.

Now I need to edit the public_html/wp-content/themes/YOUR_THEME_NAME/singular.php file via editor in your theme and add following code in DIV with .sidebar class to display your custom widget area.

Registering a Custom Widget Area

You can create Widget area for any page section like Header, Sidebar, Page Content and Footer with using PHP WordPress conditions.

Example:
is_front_page()
is_single()
is_page()
is_category()
is_singular()

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please SHARE this post.

Categories
WordPress

WordPress – How to Create a Child Theme?

In this post today I will discus, How to Create a Child Theme? Every new developer first need to learn the WordPress basics. Also need to know how customize your WordPress site. Create new child themes is great starting point for developer to customize WordPress themes.

Why Developer Need to Create a Child Theme?

Child themes are considered the best way to customize or extend function your WordPress default or paid themes. A child theme inherits all the features and appearance of its parent theme. Developer can customize without affecting parent theme function.

This allows a developer to easily update parent theme function without losing parent theme new changes. Developer can easily update update parent theme if release new version for parent theme.

Developer Basic Requirements

A developer need to understanding of CSS/HTML/PHP basic, so a developer can make easily own changes. If developer is good at copying and pasting code snippets from other sources, then that would work too. I am recommend a developer to practice on local development environment. Developer can move all local change to live WordPress site. Because on local server developer can dummy content for testing purposes to child theme development.

Creating Your First Child Theme

Now you can chose one of the default WordPress theme can be used as a parent theme. Example: twentytwenty Developer need to open /wp-content/themes/ in your WordPress installation directory and create a new directory (twentytwenty-child) for your child theme. You can name this directory anything you want but good format is like (twentytwenty-child) name.

wordpress-create-child-theme-directory

Go to /wp-content/themes/twentytwenty-child/ directory and create stylesheet file named (style.css) and open with text editor like Notepad or VSCode and your stylesheet must contain the below required header comment at the very top of the file.

Following information is required for child theme:
Theme Name: Needs to be unique to your theme name.
Template: The name of the parent theme directory. The parent theme in our example is the Twenty Twenty theme, so the Template will be twentytwenty. The parent theme folder name is case-sensitive. If you provide with Template – TwentyTwenty, then it will not work.

Now developer need to something change on functions.php file, it’s necessary to add parent theme styles by (parent-style) on child theme and custom stylesheet called by (child-style).

Now developer need to something change on functions.php file, If you want to set logo without cropping logo. Login into wp-admin and go to Appearance => Customize after than click on “Site Identity” try to change logo, select a logo and press Skip Cropping button with following code.

wordpress-create-child-theme-cropping

Activate child theme:

Child theme is ready for active. Please go to WordPress admin and go to menu Appearance => Themes you can find new theme “Twenty Twenty Child” mouse over on new theme and click on “Active” button.

wordpress-create-child-theme-active

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please SHARE this post.

Categories
Magento 2

Magento 2 – File or image upload via frontend custom module form and Controller

Today I will discuse how to File or image upload via frontend custom module form and Controller. Open your module form.phtml file and make sure that the form attribute method to post method=”post” and also make sure that the form attribute enctype like enctype=”multipart/form-data”.

Also make sure that INPUT field type attribute type=”file”, I have use file field name “filesubmission”.

Now open you costom module Controller php file VENDOR\MODULE\Controller\Index\Post.php and use some library class for DirectoryList, UploaderFactory and Filesystem in top of file below namespace.

Now add some protected on top of Controller class before __construct() method.

Now update your Controller method public function __construct() like below.

Now add code for fileupload in your Controller method public function execute(). You can see I do not use $_FILES Global Variable in Magento because it does not meet with Magento standards. Instead of $_FILES Variable please use $this->getRequest()->getFiles();

Here filesubmission is the input name and also the field name of database table.
Upload image file will be saved at pub/media/requestaquote directory.
And $data[‘filesubmission’] = $imagePath; the value of $imagePath; that will be saved in the database field.

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please SHARE

Categories
Magento 2

Magento 2 – How to validate at least one checkbox in custom module form?

Today I will discuses, How to validate at least one checkbox in custom module form? Open your module form .phtml file and add the validation component on form tag, as a attribute like data-mage-init.

How to validate at least one checkbox in custom module form?

Add attribute on the form tag: data-mage-init='{“validation”:{}}’

Add some validation rules to your custom module form checkbox fields like data-validate=”{required:true, ‘validate-one-required-by-name’:true}”, Please see example checkbox form html code with validate-one-required-by-name below.

After form validate screen.

List of Magento 2 form validation rules

List of some Magento 2 validation rules you can use and their error message. You can find all methods yourself by looking in lib/web/prototype/validation.js on line 415

List of Magento 2 supported all form validation rules, jQuery validation rules

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please SHARE

Categories
Magento 2

Magento 2 – How to enable/disable WYSIWYG Editor?

In Magento 2 WYSIWYG Editor is an useful feature that allows users to directly see the appearence of the end result, helps users save a lot of time and produce greater results. In this tutorial, I will show you, How to enable/disable WYSIWYG Editor?

How to enable/disable WYSIWYG Editor?

Please follow this tutorial step by step how to enable/disable WYSIWYG Editor.

Step 1: Login into store admin and go to: STORES => Configuration page.

STORES => Configuration

Step 2: In the Configuration page go to General => Content Management to view WYSIWYG Options section.

Step 3: Enable WYSIWYG Editor is set to enable by default. Uncheck box “Use system value” and choose other option Disabled by default as shown in below picture.

 Enable WYSIWYG Editor

Click on “Save Config” button to save new changes.

Step 4: Finally, you need to clear cache by menu SYSTEM => Cache Management => Select All => Refresh => Submit

That’s all about How to enable/disable WYSIWYG Editor Magento 2 admin. Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please LIKE and SHARE this post.

Categories
Magento 2

Magento 2 – Set page title by layout XML or Controller

By default URL showing as title but thats not good look that appears on the title bar when created a new custom module. There are 2 (two) ways of Set page title by layout XML or Controller.

1. From frontend view layout module_controller_action.xml by head and title tag.

2. From frontend view layout module_controller_action.xml by referenceBlock page.main.title and set setPageTitle argument tag.

Set page title by PHP Controller

Also we can set page title by PHP controller file controllerName.php in method public function execute()

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please LIKE and SHARE

Categories
Laravel

Laravel 7.x Generate Database Seeding

Laravel: Generate Seeders

Laravel includes with a simple method of seeding your database with test data using seed classes. All seed classes are stored in the database/seeds directory. We can set any name for Seed classes, but we should follow some sensible convention, such as ProductsTableDataSeeder, etc. By default, a DatabaseSeeder class is defined for you. Using default class, you may use the call method to run other seed classes, allowing you to control the seeding order.

Creating a new module

We can creating a simple module by run the following command to create a module. Replace MODULE_NAME by your desired name.

Also we can create multiple modules in one command like below.

How to Generate Seeders?

We can generate a seeder by the Artisan command make:seeder. All of generated seeders class will be placed in the database/seeds directory:

Calling default DatabaseSeeder with Additional Seeders

Default the DatabaseSeeder class, you may use the call method to execute additional seed classes. Using the call method allows you to break up your database seeding into multiple files so that no single seeder class becomes overwhelmingly large. Enter the name of the seeder classes you want to run:

Laravel: Running Seeders

Once you have done generate your seeder, you may need to regenerate Composers autoloader using the dump-autoload command.

To seed your database now you may use the Artisan command db:seed. By default, the db:seed command runs the DatabaseSeeder class, which may be used to call other seed classes.

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please LIKE and SHARE