{"id":116229,"date":"2024-09-25T13:08:08","date_gmt":"2024-09-25T13:08:08","guid":{"rendered":"\/tutorials\/?p=116229"},"modified":"2025-07-01T08:13:13","modified_gmt":"2025-07-01T08:13:13","slug":"laravel-tutorial","status":"publish","type":"post","link":"\/tutorials\/laravel-tutorial","title":{"rendered":"Laravel tutorial: Everything you need to know to get started with this framework"},"content":{"rendered":"<p>Laravel is an open-source PHP framework known for its user-friendly, elegant syntax, and active community. It is popular among PHP developers for building various web applications, such as online stores, social media platforms, and content management systems.<\/p><p>This Laravel tutorial will explain all about this framework, including its benefits, installation process, and important terms. You will also learn more advanced concepts like PHP Artisan command and error handling.<\/p><p>\n\n\n\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-getting-started-with-laravel\">Getting started with Laravel<\/h2><p>Frameworks like Laravel provide pre-built tools and resources that allow developers to create an application without writing all the code from scratch. For example, you can install the Bagisto package to add eCommerce functionality, like inventory management.<\/p><p>Laravel is widely popular due to the following features. We will cover them in more detail in the following sections:<\/p><ul class=\"wp-block-list\">\n<li><strong>Elegant syntax<\/strong> &ndash; Laravel lets you use simpler PHP code that is more efficient and readable to streamline the development process.<\/li>\n\n\n\n<li><strong>MVC architecture<\/strong> &ndash; The Model-view-controller model in Laravel provides a clearer structure for your application components.<\/li>\n\n\n\n<li><strong>PHP Artisan<\/strong> &ndash; A command-line tool that simplifies complex tasks during development, like database updates or component creation.<\/li>\n\n\n\n<li><strong>Eloquent ORM<\/strong> &ndash; Eloquent object-relational mapping provides a more straightforward database communication through the object-oriented approach.<\/li>\n<\/ul><p>You can <a href=\"\/tutorials\/how-to-install-laravel-on-ubuntu\">install Laravel on Ubuntu<\/a>, CentOS, and other popular Linux distributions. Before doing so, however, you must configure several software components, including PHP runtime, Composer, and Apache. If you want a simpler installation process, purchase a <a href=\"\/vps\/laravel-hosting\">Hostinger Laravel VPS hosting plan<\/a>. Then, complete the onboarding process, and have Laravel set up automatically in 15 minutes or so.<\/p><figure class=\"wp-block-image size-large\"><a class=\"hgr-tutorials-cta hgr-tutorials-cta-vps-hosting\" href=\"\/vps-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/public\" alt=\"\" class=\"wp-image-77934\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=768,fit=scale-down 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><p>Additionally, you must set up an integrated development environment on your local computer to write your application&rsquo;s code. To <a href=\"\/tutorials\/how-to-deploy-laravel\">deploy a Laravel app<\/a> to your VPS, you need<strong> Git <\/strong>or automation software like <strong>Jenkins<\/strong>.<\/p><p>\n\n\n<div><p class=\"important\"><strong>Important!<\/strong> Depending on your Laravel version, several concepts might might be different. For this tutorial, we will focus on <strong>Laravel 11.X<\/strong>.<\/p><\/div>\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-understanding-the-mvc-architecture\">Understanding the MVC architecture<\/h2><p>One of the most important concepts in Laravel is its MVC architecture. Simply put, this model enables developers to divide an application into three components for easier code management, prioritization, and concern isolation.<\/p><p><strong>Model components<\/strong><\/p><p>The model component represents your application&rsquo;s business logic and storage. It is responsible for database operations, including writing and fetching specific information from the back end based on the user&rsquo;s request.<\/p><p>Laravel relies on Eloquent ORM to handle model-related operations, which uses the object-oriented approach. This makes manipulating data much faster and more flexible than using SQL.<\/p><p><strong>View components<\/strong><\/p><p>The view layer defines the area of your application that users can see on their device&rsquo;s screen and interact with. It covers elements like drop-down menus, text boxes, and form fields.<\/p><p>To simplify the view component development process, Laravel provides a Blade engine that lets you incorporate PHP into HTML templates. This feature enables you to create reusable code and display data from the back-end more easily.<\/p><p><strong>Controller components<\/strong><\/p><p>The controller connects the previous two components in your Laravel application. It fetches the data request from the model layer and presents the processed information on the front end to the view component.<\/p><p>You can use various methods to tell the controller to interact with the data differently. For example, <strong>index<\/strong> retrieves records from the database while <strong>store<\/strong> inserts new resources.<\/p><h2 class=\"wp-block-heading\" id=\"h-creating-routes-and-urls\">Creating routes and URLs<\/h2><p>When a user accesses your application, they send a request which a controller will handle. Route directs the incoming request through a specific URL to reach the appropriate controller and return data to the view layer.<\/p><p>You can create multiple Laravel routes based on the request&rsquo;s HTTP methods, like GET, POST, PUT, DELETE, and PATCH. By default, they are located in <strong>web.php<\/strong> inside the <strong>routes<\/strong> folder of your Laravel project directory.<\/p><p>To create a route, call the <strong>Route <\/strong>helper function or <a href=\"https:\/\/laravel.com\/docs\/11.x\/facades\" target=\"_blank\" rel=\"noopener\">facade<\/a> by adding the following line at the top of your <strong>web.php<\/strong> file:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">use Illuminate\\Support\\Facades\\Route;<\/pre><p>Then, specify your route. For example, the following will handle users who send the <strong>GET<\/strong> HTTP request to the <strong>domain.tld\/welcome<\/strong> URL:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Route::get('\/welcome', function () {\n   \/\/Write your controller logic here;\n});<\/pre><p>If you want to set up a route for a specific controller, you can also call its facade and add the route like the following:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">use App\\Http\\Controllers\\HomeController;\n\nRoute::get('\/home', [HomeController::class, 'index']);<\/pre><p>In the example, we route requests with the<strong> GE<\/strong>T method from <strong>domain.tld\/home<\/strong> to the <strong>HomeController<\/strong> controller, which will handle it using the<strong> INDEX <\/strong>method. The<strong> ::class<\/strong> syntax allows you to use the controller without specifying its full facade path.<\/p><p>Laravel can process requests through middleware before passing them to controllers for additional processing, like logging or authentication. Consider this example:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Route::get('\/welcome', function () {\n    return view('welcome');\n})-&gt;middleware('log.request');<\/pre><p>Remember, you must create the middleware through PHP Artisan. We will explain how to do so in the later section about advanced Laravel techniques.<\/p><h2 class=\"wp-block-heading\" id=\"h-working-with-controllers\">Working with controllers<\/h2><p>Controllers group requests with the same logic into a class. It makes the processing more efficient since you can do so in bulk using a single handler.<\/p><p>For example, you create a HomeController to process all requests coming from the \/home URL. By default, controllers are located in <strong>app\/Http\/Controllers<\/strong>. To set one up, run the following PHP artisan command:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">php artisan make:controller ControllerName<\/pre><p>Then, define the methods of handling requests inside the new controller file. For example, the following handle <strong>GET<\/strong> requests sent through the <strong>product\/id <\/strong>route:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">namespace App\\Http\\Controllers;\n\nuse App\\Models\\Product;\nuse Illuminate\\Http\\Request;\n\nclass ProductController extends Controller\n{\n    \/\/ GET \/product\/{id}\n    public function show($id)\n    {\n        $product = Product::find($id);\n        \n        if (!$product) {\n            abort(404); \/\/ Return a 404 error if the product is not found\n        }\n\n        return view('products.show', compact('product')); \/\/ Return a view with the product data\n    }\n}<\/pre><p>To handle common create, read, update, and delete (CRUD) operations, you can set up a resource controller with a set of predetermined methods. Here&rsquo;s the command:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">php artisan make:controller ControllerName --controller<\/pre><h2 class=\"wp-block-heading\" id=\"h-creating-views-with-blade-templating-engine\">Creating views with Blade templating engine<\/h2><p>The <a href=\"https:\/\/laravel.com\/docs\/11.x\/blade\" target=\"_blank\" rel=\"noopener\">Blade templating engine<\/a> enables seamless PHP integration into HTML using a simpler syntax. It helps you create view components for your application more easily.<\/p><p>To build a view using Blade, create a file with the <strong>.blade.php<\/strong> extension inside your Laravel project&rsquo;s <strong>resources\/views<\/strong> directory.<\/p><p>The code structure is the same as that of HTML but with additional syntaxes for PHP. For example, you can insert a variable like so:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;h1&gt;{{ $title }}&lt;\/h1&gt;<\/pre><p>In the above example, Laravel passes the value of<strong> <\/strong>the <strong>$title<\/strong> PHP variable to the view component, displaying it to users.<\/p><p>You can also add directives that manipulate your HTML elements using PHP functions. For instance, <strong>@if<\/strong> lets you display specific content if a condition is met, like the following:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">@if($user-&gt;'Username')\n  &lt;h1&gt;Glad to see you, Username!&lt;\/h1&gt;\n@endif<\/pre><p>To improve code reusability, Blade offers a template inheritance feature that lets you create a master layout and add smaller components called <strong>child views<\/strong> separately. You can do so using the <strong>@extends<\/strong>, <strong>@section<\/strong>, and <strong>@yield<\/strong> directives.<\/p><p>For example, we have a master template with the following code:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;title&gt;@yield('websitetitle')&lt;\/title&gt;<\/pre><p>The <strong>@yield <\/strong>directive is a placeholder for content from a child view marked with <strong>@section<\/strong>. For instance, the following will insert <strong>Your Awesome Website <\/strong>into the title tag:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">@section('websitetitle', 'Your Awesome Website') <\/pre><p>Lastly, add the <strong>@extends<\/strong> directive to the child view to tell the master template which file it should use to extend its content.<\/p><h2 class=\"wp-block-heading\" id=\"h-managing-database-with-eloquent-orm\">Managing database with Eloquent ORM<\/h2><p><a href=\"https:\/\/laravel.com\/docs\/11.x\/eloquent\" target=\"_blank\" rel=\"noopener\">Eloquent ORM<\/a> enables your application to interact with the database tables more efficiently using shorter code than traditional SQL. Instead of directly manipulating data directly using tables, Laravel assigns a model to simplify CRUD operations.<\/p><p>You can create a new Eloquent model anywhere within your Laravel project&rsquo;s <strong>app<\/strong> folder since the <strong>Composer.json<\/strong> file will automatically locate it. If you don&rsquo;t specify a directory, the web application framework will use the default <strong>app\/Models<\/strong> directory. To create a new model, run the PHP Artisan command like this. Replace <strong>Name<\/strong> with your desired model name:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">php artisan make:model Name<\/pre><p>By default, Laravel assumes the corresponding table is the plural form of your model name. For instance, the following command will assign the <strong>Post<\/strong> model to the <strong>posts <\/strong>database column.<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">php artisan make:model Post<\/pre><p>Now, let&rsquo;s write Eloquent code inside your controller for CRUD operation. For instance, the following will retrieve accounts from the <strong>User<\/strong> model with the <strong>Active<\/strong> status:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$activeUsers = User::where('status', 'active')-&gt;get();<\/pre><p>Normally, we need the following for the same operation using SQL:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$activeUsers = DB::select('SELECT * FROM users WHERE status = ?', ['active']);<\/pre><p>Laravel also lets you establish relationships between records in different Eloquent models for more efficient data organization. Here are the supported connections:<\/p><ul class=\"wp-block-list\">\n<li><strong>One-to-one<\/strong> &ndash; A record is associated with another record in a different model. For example, a username with their user ID.<\/li>\n\n\n\n<li><strong>One-to-many <\/strong>&ndash; A record connects to multiple values from a model. For instance, an eCommerce user with their order invoices.<\/li>\n\n\n\n<li><strong>Many-to-many <\/strong>&ndash; multiple records relate to several records from another table. An example of this relationship is products and tags.<\/li>\n<\/ul><p>Laravel also has a migration feature that helps maintain consistency between databases in different environments or versions. It also lets you create columns in a new model with a single execution.<\/p><p>To create a migration file for a table, run the following command:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">php artisan make:migration create_example_table<\/pre><p>You can also create a migration file while setting up a model by adding the -m or &ndash;migration option like so:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">php artisan make:model Post --migration<\/pre><p>Laravel will create a migration file within the database\/migrations directory. Inside it, specify two commands &ndash;<strong> up()<\/strong> and <strong>down()<\/strong>.The <strong>up() <\/strong>function defines the changes to make when you run the <strong>PHP Artisan migrate<\/strong> command, while <strong>down()<\/strong> specifies the method to revert the modifications. Here&rsquo;s an example of the full code:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\nuse Illuminate\\Database\\Migrations\\Migration;\nuse Illuminate\\Database\\Schema\\Blueprint;\nuse Illuminate\\Support\\Facades\\Schema;\n\nclass CreatePostsTable extends Migration\n{\n    \/**\n     * Run the migrations.\n     *\n     * @return void\n     *\/\n    public function up()\n    {\n            Schema::create('posts', function (Blueprint $table) {\n            $table-&gt;id(); \/\/ Auto-incrementing primary key\n            $table-&gt;string('title'); \/\/ Column for post title\n            $table-&gt;text('body'); \/\/ Column for post content\n            $table-&gt;timestamps(); \/\/ Created and updated timestamps\n        });\n    }\n\n    \/**\n     * Reverse the migrations.\n     *\n     * @return void\n     *\/\n    public function down()\n    {\n        Schema::dropIfExists('posts');\n    }\n}<\/pre><p>If you execute the following command, the functions within <strong>up() <\/strong>will run, creating the <strong>id<\/strong>, <strong>string<\/strong>, <strong>text<\/strong>, and <strong>timestamp<\/strong>s columns inside the <strong>posts <\/strong>table.<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">php artisan migrate<\/pre><p>To revert the changes, run the following command. It will execute the<strong> down()<\/strong> function, removing the newly created posts table:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">php artisan migrate:rollback<\/pre><p>Commonly, developers and system administrators migrate the database if they need to modify the schemas, whether it is during testing, deployment, or setting up a new environment.<\/p><h2 class=\"wp-block-heading\" id=\"h-implementing-authentication-and-authorization\">Implementing authentication and authorization<\/h2><p>Implementing a proper authentication and authorization mechanism is crucial for your web application&rsquo;s integrity and safety. Since building this system manually is complicated, Laravel provides a toolkit that lets you develop it more easily.<\/p><p><strong>Laravel authentication<\/strong><\/p><p>Laravel uses <strong>guards <\/strong>to define the user authentication method and providers to retrieve the account information from a persistent storage, like a database. The authentication logic is located inside the <strong>config\/auth.php<\/strong> file. Here&rsquo;s what it might look like:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">'guards' =&gt; [\n    'web' =&gt; [\n        'driver' =&gt; 'session',\n        'provider' =&gt; 'users',\n    ],\n'providers' =&gt; [\n    'users' =&gt; [\n        'driver' =&gt; 'eloquent',\n        'model' =&gt; App\\Models\\User::class,\n    ],\n],<\/pre><p>In the example above, we use a guard to authenticate requests to our web application using a cookie-based session method. It utilizes a provider called <strong>users<\/strong>, which uses the Eloquent ORM mechanism to retrieve the account&rsquo;s records from the <strong>user<\/strong> model.<\/p><p>Laravel also offers <strong>Jetstream<\/strong> and <a href=\"https:\/\/laravel.com\/docs\/11.x\/starter-kits\" target=\"_blank\" rel=\"noopener\"><strong>Breeze <\/strong>starter kits<\/a>, which provide a ready-to-use authentication system. We recommend installing them to get a basic understanding of the code implementation, which can help you set up custom logic later on.<\/p><p><strong>Laravel authorization<\/strong><\/p><p>Laravel authorization uses two components &ndash; <strong>gates<\/strong> and <strong>policies<\/strong>. Gates check if a user has permission to take a specific action. Meanwhile, policies define an authorization logic for collective actions within the same model.<\/p><p>Gates are suitable for one-off actions, while policies are useful for authorizing more complicated processes. Depending on your Laravel applications, you might use one or both.<\/p><p>Register a gate using the <strong>boot <\/strong>method inside<strong> App\/Providers\/AppServiceProvider<\/strong>. For example, the following compares the user ID of an account who wants to edit a post and its author:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">use App\\Models\\Post;\nuse App\\Models\\User;\nuse Illuminate\\Support\\Facades\\Gate;\n\npublic function boot(): void\n{\n    Gate::define('update-post', function (User $user, Post $post) {\n        return $user-&gt;id === $post-&gt;user_id;\n    });\n}<\/pre><p>Then, you can call the gate to your controllers or Blade templates and specify the response based on the authorization result. For example, you can set your application to return a message when encountering validation errors.Meanwhile, create a policy using the PHP Artisan command. For example, the following will create the<strong> PostPolicy<\/strong> policy:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">php artisan make:policy PostPolicy<\/pre><p>Then, register it using the<strong> boot<\/strong> method inside <strong>AuthServiceProvider.php<\/strong>. In this example, we assign the policy to the <strong>Post<\/strong> model:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">namespace App\\Providers;\n\nuse App\\Models\\Post;\nuse App\\Policies\\PostPolicy;\nuse Illuminate\\Foundation\\Support\\Providers\\AuthServiceProvider as ServiceProvider;\nuse Illuminate\\Support\\Facades\\Gate;\n\nclass AuthServiceProvider extends ServiceProvider\n{\n    protected $policies = [\n        Post::class =&gt; PostPolicy::class, \/\/ Registering the policy for the Post model\n    ];\n\n    public function boot(): void\n    {\n    \/\/ Specify gate here\n    }\n}<\/pre><p>Now you can write the authorization logic inside your new policy&rsquo;s file, which in our case is <strong>PostPolicy.php<\/strong>. To apply it, call the function to your controller and specify the response.<\/p><h2 class=\"wp-block-heading\" id=\"h-handling-forms-and-validation\">Handling forms and validation<\/h2><p>Laravel&rsquo;s ability to efficiently communicate and authorize databases enables you to create forms easily.<\/p><p>For example, let&rsquo;s create a form that collects usernames and email addresses. To start, create a view component using Blade. Here&rsquo;s what the code might look like:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;!DOCTYPE html&gt;\n&lt;html lang=\"en\"&gt;\n&lt;head&gt;\n    &lt;meta charset=\"UTF-8\"&gt;\n    &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"&gt;\n    &lt;title&gt;Simple Form&lt;\/title&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n    &lt;h1&gt;Submit Your Info&lt;\/h1&gt;\n\n    @if (session('success'))\n        &lt;div style=\"color: green;\"&gt;{{ session('success') }}&lt;\/div&gt;\n    @endif\n\n    @if ($errors-&gt;any())\n        &lt;div style=\"color: red;\"&gt;\n            &lt;ul&gt;\n                @foreach ($errors-&gt;all() as $error)\n                    &lt;li&gt;{{ $error }}&lt;\/li&gt;\n                @endforeach\n            &lt;\/ul&gt;\n        &lt;\/div&gt;\n    @endif\n\n    &lt;form action=\"{{ route('form.submit') }}\" method=\"POST\"&gt;\n        @csrf\n        &lt;label for=\"name\"&gt;Name:&lt;\/label&gt;\n        &lt;input type=\"text\" id=\"name\" name=\"name\" required&gt;\n\n        &lt;label for=\"email\"&gt;Email:&lt;\/label&gt;\n        &lt;input type=\"email\" id=\"email\" name=\"email\" required&gt;\n        &lt;button type=\"submit\"&gt;Submit&lt;\/button&gt;\n    &lt;\/form&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/pre><p>Then, add the routes into <strong>web.php<\/strong>, specifying which controller will handle the form submissions. In our case, we need two for the <strong>GET<\/strong> and <strong>POST<\/strong> methods:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">use App\\Http\\Controllers\\FormController;\n\nRoute::get('\/form', [FormController::class, 'show'])-&gt;name('form.show');\nRoute::post('\/form-submit', [FormController::class, 'submit'])-&gt;name('form.submit');<\/pre><p>Now, let&rsquo;s create the controller using the following command:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">php artisan make:controller FormController<\/pre><p>Add the following code to the <strong>FormController.php<\/strong> file to set up your controller, which will validate the user input and compare the data against database entries:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">namespace App\\Http\\Controllers;\n\nuse Illuminate\\Http\\Request;\nuse App\\Models\\User; \/\/ Make sure to import your User model\n\nclass FormController extends Controller\n{\n    public function show()\n    {\n        return view('simple-form');\n    }\n\n    public function submit(Request $request)\n    {\n        \/\/ Validate input\n        $request-&gt;validate([\n            'name' =&gt; 'required|string|max:255',\n            'email' =&gt; 'required|email|max:255|exists:users,email', \/\/ Check if email exists\n        ]);\n\n        return redirect()-&gt;route('form.show')-&gt;with('success', 'Form submitted successfully!');\n    }\n}<\/pre><p>As specified in the Blade file, if the input username and email exist in the database, your front-end view will return a success message. Otherwise, it will output an error.<\/p><p>If you want more thorough checks, you can enforce an authorization system using gates and policies.<\/p><h2 class=\"wp-block-heading\" id=\"h-advanced-laravel-techniques\">Advanced Laravel techniques<\/h2><p>Here are several advanced Laravel techniques that can improve your web application development efficiency.<\/p><h3 class=\"wp-block-heading\">Using Laravel PHP Artisan command line<\/h3><p><a href=\"https:\/\/laravel.com\/docs\/11.x\/artisan\" target=\"_blank\" rel=\"noopener\">PHP Artisan<\/a> is a command-line application that lets you interact with your application framework, automate complex tasks, and manage resources for a more efficient development process. It comes pre-configured with your Laravel installation.<\/p><p>To list the available PHP Artisan commands, run the following:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">php artisan list<\/pre><p>Meanwhile, use the <strong>help<\/strong> argument to check a command&rsquo;s manual, including the acceptable options. For example, run the following to check the <strong>migrate <\/strong>utility:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">php artisan help migrate<\/pre><p>One of the most commonly used PHP Artisan commands is <strong>make<\/strong>, which lets you create various items, including another command, controller, and middleware. Here&rsquo;s the syntax:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">php artisan make:item [option]<\/pre><p>Another important command is<strong> serve<\/strong>, which lets you deploy your Laravel application:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">php artisan serve<\/pre><p>You can also manage caches with the PHP artisan command. For example, use the following to wipe your Laravel routing cache:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">php artisan route:clear<\/pre><p>\n\n\n<div class=\"protip\">\n                    <h4 class=\"title\">Suggested Reading<\/h4>\n                    <p>New to Laravel Artisan commands? Check our article on <a href=\"\/tutorials\/laravel-commands\">Laravel commands<\/a>.<\/p>\n                <\/div>\n\n\n\n<\/p><h3 class=\"wp-block-heading\">Middleware<\/h3><p><a href=\"https:\/\/laravel.com\/docs\/11.x\/middleware\" target=\"_blank\" rel=\"noopener\">Laravel middleware<\/a> is intermediary software between your application and the client. It intercepts user requests before they reach your server and is typically used for filtering traffic and logging. Laravel provides pre-built middleware that you can directly use in your application code base. By default, they are located in your project&rsquo;s <strong>app\/Http\/Middleware<\/strong>. To create a new one, run the following PHP Artisan command:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">php artisan make:middleware-name<\/pre><p>Then, write your PHP script to define the handling logic. Once finished, you can apply middleware to a specific route or globally, intercepting all HTTP requests and methods.<\/p><p>To apply your middleware globally, add it to the <strong>$middleware <\/strong>property inside <strong>app\/Http\/Kernel.php<\/strong>. When working with multiple middleware services, you can group them to simplify routing. To do so, list them under the <strong>$middlewareGroups<\/strong> property inside the <strong>Kernel.php<\/strong> file. Consider this example:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">protected $middlewareGroups = [\n    'custom' =&gt; [\n        \\App\\Http\\Middleware\\EncryptCookies::class,\n        \\Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse::class,\n]<\/pre><p>In the snippet, the <strong>custom <\/strong>group contains two middleware components. You can call them simultaneously into a route using the group name like so:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Route::get('\/example', function () {\n    return 'This route uses the custom middleware group.';\n})-&gt;middleware('custom');<\/pre><h3 class=\"wp-block-heading\">Error handling and debugging<\/h3><p>Laravel ships with an error handling mechanism that helps you handle issues more flexibly. To set up a custom exception handler, add the logic inside the <strong>App\\Exceptions\\Handler<\/strong> class.<\/p><p>You can use different methods to customize how Laravel will display an exception. For example, the following code uses<strong> render()<\/strong> to display specific errors as HTTP responses:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public function render($request, Throwable $exception)\n{\n    if ($exception instanceof CustomException) {\n        return response()-&gt;view('errors.custom', [], 500);\n    }\n\n    return parent::render($request, $exception);\n}<\/pre><p>Another method is <strong>report()<\/strong>, which modifies how Laravel logs errors in the<strong> storage\/logs <\/strong>directory. You can also create a custom exception class by extending the base <strong>Exception<\/strong> class, like in this code:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">namespace App\\Exceptions;\n\nuse Exception;\n\nclass CustomException extends Exception\n{\n    \/\/ Custom logic or properties\n}<\/pre><p>In addition to enabling you to catch exceptions more efficiently, Laravel provides tools for debugging errors. For example, the<strong> dd() <\/strong>and <strong>dump() <\/strong>lets you check values from a variable, allowing you to see if the output is correct:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">dd($variable)<\/pre><p>Alternatively, use a third-party solution, like <strong>Laravel Debugbar<\/strong>, which provides a graphical user interface in your web browser that displays useful information about your application. For example, you can check its routes, queries, and requests.<\/p><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"1460\" height=\"295\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2024\/09\/laravel-debugbar-user-interface.png\/public\" alt=\"Laravel Debugbar user interface\" class=\"wp-image-116234\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2024\/09\/laravel-debugbar-user-interface.png\/w=1460,fit=scale-down 1460w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2024\/09\/laravel-debugbar-user-interface.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2024\/09\/laravel-debugbar-user-interface.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2024\/09\/laravel-debugbar-user-interface.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2024\/09\/laravel-debugbar-user-interface.png\/w=768,fit=scale-down 768w\" sizes=\"(max-width: 1460px) 100vw, 1460px\" \/><\/figure><\/div><p>You can install this tool via <strong>Composer<\/strong>. If you want to learn more about it, check the <a href=\"https:\/\/github.com\/barryvdh\/laravel-debugbar\" target=\"_blank\" rel=\"noopener\">Laravel Debugbar GitHub repository<\/a>.<\/p><h3 class=\"wp-block-heading\">Building RESTful APIs with Laravel<\/h3><p>RESTful <a href=\"https:\/\/www.postman.com\/what-is-an-api\/\" target=\"_blank\" rel=\"noopener\">application programming interface<\/a> (API) enables applications to communicate using HTTP methods like <strong>GET<\/strong>, <strong>POST,<\/strong> and<strong> DELETE<\/strong>. It lets you integrate services, share data, or set up third-party tools, like monitoring, more easily.<\/p><p>Laravel&rsquo;s robust routing and controller mechanism makes it suitable for developing a RESTful API. Here&rsquo;s how:<\/p><ul class=\"wp-block-list\">\n<li>Open the<strong> routes\/api.php<\/strong> file. It comes with your Laravel installation by default.<\/li>\n\n\n\n<li>Define the route for each API endpoint by specifying which HTTP methods correspond to an action. Here&rsquo;s an example:<\/li>\n<\/ul><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">use App\\Http\\Controllers\\ItemController;\nRoute::get('\/items', [ItemController::class, 'index']);<\/pre><ul class=\"wp-block-list\">\n<li>Create a controller for handling the request from all endpoints:<\/li>\n<\/ul><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">php artisan make:controller ItemController<\/pre><ul class=\"wp-block-list\">\n<li>Define the methods <strong>ItemController<\/strong> will use to handle CRUD operation:<\/li>\n<\/ul><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">namespace App\\Http\\Controllers;\n\nuse Illuminate\\Http\\Request;\nuse App\\Models\\Item;\n\nclass ItemController extends Controller\n{\n    \/\/ GET \/items\n    public function index()\n    {\n        return Item::all();\n    }<\/pre><ul class=\"wp-block-list\">\n<li>Create a model and database migration file to store the application&rsquo;s data for the<strong> Item <\/strong>resource:<\/li>\n<\/ul><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">php artisan make:model Item -m<\/pre><ul class=\"wp-block-list\">\n<li>Set the structure of your<strong> items <\/strong>database table by adding the following code:<\/li>\n<\/ul><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public function up()\n{\n    Schema::create('items', function (Blueprint $table) {\n        $table-&gt;id();\n        $table-&gt;string('name');\n        $table-&gt;timestamps();\n    });\n}<\/pre><ul class=\"wp-block-list\">\n<li>Run the migration to set up the database table:<\/li>\n<\/ul><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">php artisan migrate<\/pre><p>Now, check if your API endpoint works properly by sending a <strong>GET<\/strong> request using <a href=\"\/tutorials\/curl-command-with-examples-linux\/\"><strong>cURL<\/strong><\/a> or <strong>Postman<\/strong>.<\/p><h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2><p>Laravel is a full-stack PHP web development framework that provides various tools to simplify application development. For example, the Blade template lets you seamlessly integrate PHP into HTML, while the Breeze starter kit simplifies authentication system creation.<\/p><p>In this article, we have explained important tools and concepts in Laravel. Here&rsquo;s a short recap:<\/p><ul class=\"wp-block-list\">\n<li><strong>PHP Artisan<\/strong> &ndash; command-line tool for creating and managing Laravel application components.<\/li>\n\n\n\n<li><strong>Routes<\/strong> &ndash; a system that redirects user requests to a specific controller based on the HTTP request for processing.<\/li>\n\n\n\n<li><strong>Controller<\/strong> &ndash; a logic that handles CRUD operations based on the incoming client request.<\/li>\n\n\n\n<li><strong>Model <\/strong>&ndash; a method that enables controllers to interact with schemas from a specific database table.<\/li>\n\n\n\n<li><strong>Views<\/strong> &ndash; the front-end interface of your application, used for taking inputs and showing outputs.<\/li>\n<\/ul><p>To familiarize yourself with this PHP framework, we suggest creating a new project for practice. If you use Hostinger&rsquo;s VPS plan, ask <a href=\"\/blog\/vps-ai-assistant\">Kodee<\/a>, our AI assistant, to guide you through the process. Simply ask, &ldquo;How do I create a new Laravel project on my VPS?&rdquo; and Kodee will provide step-by-step instructions tailored to your server setup.<\/p><h2 class=\"wp-block-heading\" id=\"h-laravel-tutorial-faq\">Laravel tutorial FAQ<\/h2><div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1727267449233\"><h3 class=\"schema-faq-question\">What is Laravel, and what can it be used for?<\/h3> <p class=\"schema-faq-answer\"><a href=\"\/tutorials\/what-is-laravel\">Laravel<\/a> is a PHP web development framework that provides a complete solution for developing various types of applications. For example, you can develop an eCommerce platform or a RESTful application programming interface (API). Since it is a full-stack technology, you can develop both your application&rsquo;s front and back end.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1727267460960\"><h3 class=\"schema-faq-question\">What are the key features of Laravel?<\/h3> <p class=\"schema-faq-answer\">Laravel&rsquo;s key features include the Blade templating engine, which lets you embed PHP into HTML components, PHP Artisan, which enables a more efficient object-oriented database call, and elegant code syntaxes to streamline the development process. It also uses the MVC structure, which helps developers organize their application components more easily.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1727267473743\"><h3 class=\"schema-faq-question\">Is Laravel back-end or front-end?<\/h3> <p class=\"schema-faq-answer\">The Laravel framework is full-stack and can handle both the back and front end. Based on its MVC architecture, you can develop the back end as the model and controller layer while the front end as the view component.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1741092496219\"><h3 class=\"schema-faq-question\">What are some Laravel alternatives for creating web apps?<\/h3> <p class=\"schema-faq-answer\">Symfony and CodeIgniter are popular PHP alternatives, while Django and FastAPI work for Python. JavaScript options like Next.js and Express.js are also widely used. Recently, AI no-code tools like Hostinger Horizons have emerged, enabling users to <a href=\"\/horizons\">create full-stack web apps<\/a> using natural language prompts.<\/p> <\/div> <\/div>\n","protected":false},"excerpt":{"rendered":"<p>Laravel is an open-source PHP framework known for its user-friendly, elegant syntax, and active community. It is popular among PHP [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/tutorials\/laravel-tutorial\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":337,"featured_media":91144,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"Laravel tutorial: Basic tasks to help you build your app","rank_math_description":"Learn the fundamentals of Laravel with this beginner-friendly guide. We'll cover MVC architecture, routing, Blade, Eloquent ORM, and more.","rank_math_focus_keyword":"laravel tutorial","footnotes":""},"categories":[22646,22644],"tags":[],"class_list":["post-116229","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-pre-installed-applications","category-vps"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/laravel-tutorial","default":0},{"locale":"pt-BR","link":"https:\/\/www.hostinger.com\/br\/tutoriais\/tutorial-laravel","default":0},{"locale":"id-ID","link":"https:\/\/www.hostinger.com\/id\/tutorial\/cara-menggunakan-laravel","default":0},{"locale":"en-UK","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/laravel-tutorial","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/laravel-tutorial","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/laravel-tutorial","default":0},{"locale":"pt-PT","link":"https:\/\/www.hostinger.com\/pt\/tutoriais\/tutorial-laravel","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/laravel-tutorial","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/laravel-tutorial","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/laravel-tutorial","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/laravel-tutorial","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/posts\/116229","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/users\/337"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/comments?post=116229"}],"version-history":[{"count":11,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/posts\/116229\/revisions"}],"predecessor-version":[{"id":130714,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/posts\/116229\/revisions\/130714"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/media\/91144"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/media?parent=116229"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/categories?post=116229"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/tags?post=116229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}