Creating view files in Laravel is a common and necessary job for generating web pages with dynamic content. The Artisan command-line tool from Laravel makes the process of producing view files more efficient and consistent.
In this tutorial, we will walk you through the process of building view files in Laravel 10 using the Artisan command. You will obtain the knowledge and skills needed to improve your web development workflow and streamline your view file production process.
Throughout this article, we will look at how to use Artisan commands to create views. We’ll go over things like making blade templates and specifying view locations.
Read More: Laravel 10 retry() Helper Function Example Tutorial
Laravel 10.23 was recently released, and it features a noteworthy improvement: the addition of a new Artisan command option for producing Blade files.
Straightforward command in Laravel 10 to create view file:
php artisan make:view <view_name>
Let’s get started.
Laravel Installation
Open terminal and run this command to create a laravel project.
composer create-project laravel/laravel myblog
It will create a project folder with name myblog inside your local system.
To start the development server of laravel –
php artisan serve
URL: http://127.0.0.1:8000
Assuming laravel already installed inside your system.
Example #1: Laravel 10 Create Blade File Command
Here, the below command will help you to create “dashboard.blade.php” file. So, let’s run this command
php artisan make:view dashboard
Output
INFO View [resources/views/dashboard.blade.php] created successfully.
If you open file resources/views/dashboard.blade.php, you will see a div with some comment message,
<div>
<!-- When there is no desire, all things are at peace. - Laozi -->
</div>
Read More: Laravel 10 How To Encrypt Decrypt Values in Database
Once you have created a view, you may return it from one of your application’s routes or controllers using the global view helper:
Route::get('/', function () {
return view('greeting', ['name' => 'James']);
});
Example #2: Laravel 10 Create Blade File (Inside Directory)
Here, the below command will help you to create “product.blade.php” file inside admin folder. So, let’s run this command
php artisan make:view admin.product
Output
INFO View [resources/views/admin/product.blade.php] created successfully.
Help Manual of make:view command,
You can get more details about it from it’s official documentation.
That’s it.
We hope this article helped you to learn about Laravel 10 Create View File Using Artisan Command Example Tutorial in a very detailed way.
Online Web Tutor invites you to try Skillshike! Learn CakePHP, Laravel, CodeIgniter, Node Js, MySQL, Authentication, RESTful Web Services, etc into a depth level. Master the Coding Skills to Become an Expert in PHP Web Development. So, Search your favourite course and enroll now.
If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.