All About Laravel View Controller And Route - FreeCodeBlog

Last updated: Nov 16, 2021

Want to make a laravel project? You need to know about laravel view, controller and route to create a laravel project. You can create a laravel project without using laravel view, controller and route. So let's start to learn about laravel view, controller and route file.

 

All About Laravel View Controller And Route
All About Laravel View Controller And Route

 

It doesn't matter which Laravel version you want to use to create the Laravel project. You must know about laravel controller, view and route usage to create laravel project. First you need to install laravel so let see how to install any kind of laravel version tutorial.

 

1. Controller.

Want to use controller in laravel? First you need to create a controller to use it in the Laravel project. You can manually create a controller in the Laravel App Controller folder. You can also create laravel controller using the PHP artisan command. You can use the controller created command for all supported Laravel versions. This controller created command will create a controller in laravel app controller folder automatically. Want to create a Api controller in a subfolder in the laravel controller folder? You can also create a controller in a subfolder in the Laravel Controller folder.

 

/*
| App>Http>Controllers
*/
php artisan make:controller WelcomeController
/*
| App>Http>Controllers/Api
*/
php artisan make:controller Api/WelcomeController

 

API Controller VS Web Controller.

Technically there is no difference between creating an API or a web controller here. You can create an API or web controller anywhere under the Controllers folder. There is a difference between using an API and a web controller. You should use an API controller when you want to use your Laravel website information in Android applications.

 

2. View.

Want to use HTML code in laravel? You can use laravel view to return a PHP blade file to use HTML, php, css, javascript, vue js, bootstrap, tailwind css code in blade file. You can return laravel view file from controller file or web route file.

 

/*
| App>Http>Controllers/WelcomeController.php
*/
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class WelcomeController extends Controller
{
    public function index()
    {
        return view('welcome');
    }
}
/*
| routes/web.php
*/
<?php
use Illuminate\Support\Facades\Route;
Route::get('/', function () {
return view('welcome');
})->name('welcome');

 

 

3. Route.

You must use route to make a website URL. You can use controller and view files in laravel route file.

 

<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\WelcomeController;
Route::get('/', [WelcomeController::class, 'index'])->name('welcome');

 

Thanks.

Post Tags
Post Writer
masum7323
Masum Biswas (@masum7323)

My name is Masum Biswas. I'm a full stack developer. I live in Bangladesh and I love to write tutorials and tools that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, MySQL, VueJS, Tailwind CSS and Bootstrap from the early stage.

Follow Me On
Related Posts
Deploy Laravel Via Ftp On Shared Hosting Cpanel

Deploy laravel via ftp on cpanel! Want to deploy laravel on shared hosting cpanel via ftp? Yes. But why? Because I can't access cpanel public_HTML... Read More

Install Laravel Jetstream User Authentication First Party Package

You can easily install laravel jetstream user authentication on laravel 8 for a single page application. Laravel jetstream provides the implementat... Read More

The Best Way To Upload Laravel Projects To Shared Hosting Cpanel

We can easily upload laravel projects to shared hosting (cpanel) using git version control. Git version control (Private Repository) is the best wa... Read More

Laravel Eloquent One To One Relationship Example Tutorial

One to One model relationship is very simple and basic. you have to make sure that one of the table has a key that references the ID of the other t... Read More

How To Make A Space Remover Online Tool In Laravel 8 With Vue 2 And Api

Make a space remover online tool in laravel 8 with Vue 2 and API to remove space from any kind of text. Some times you may want to remove extra spa... Read More