<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>blade components in laravel 10 Archives - Codeplaners</title>
	<atom:link href="https://codeplaners.com/tag/blade-components-in-laravel-10/feed/" rel="self" type="application/rss+xml" />
	<link>https://codeplaners.com/tag/blade-components-in-laravel-10/</link>
	<description>Code Solution</description>
	<lastBuildDate>Wed, 01 Jan 2025 06:38:07 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.7</generator>

<image>
	<url>https://codeplaners.com/wp-content/uploads/2020/09/cropped-favicon-social-32x32.png</url>
	<title>blade components in laravel 10 Archives - Codeplaners</title>
	<link>https://codeplaners.com/tag/blade-components-in-laravel-10/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How to Add Blade Components In Laravel 10</title>
		<link>https://codeplaners.com/how-to-add-blade-components-in-laravel-10/</link>
					<comments>https://codeplaners.com/how-to-add-blade-components-in-laravel-10/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Fri, 20 Dec 2024 03:10:43 +0000</pubDate>
				<category><![CDATA[Laravel]]></category>
		<category><![CDATA[Laravel 10]]></category>
		<category><![CDATA[Laravel 8]]></category>
		<category><![CDATA[Laravel 9]]></category>
		<category><![CDATA[blade components in laravel 10]]></category>
		<guid isPermaLink="false">https://codeplaners.com/?p=1664</guid>

					<description><![CDATA[<p>This post was last updated on January 1st, 2025 at 06:38 amHi Dev, Today, we will show you how to add blade components in laravel 10. This article will give you simple example of how to add blade components in laravel 10. Let&#8217;s discuss how to add blade components in laravel 10. In this article, &#8230; <a href="https://codeplaners.com/how-to-add-blade-components-in-laravel-10/" class="more-link">Continue reading<span class="screen-reader-text"> "How to Add Blade Components In Laravel 10"</span></a></p>
<p>The post <a rel="nofollow" href="https://codeplaners.com/how-to-add-blade-components-in-laravel-10/">How to Add Blade Components In Laravel 10</a> appeared first on <a rel="nofollow" href="https://codeplaners.com">Codeplaners</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p class="last-modified">This post was last updated on January 1st, 2025 at 06:38 am</p><p>Hi Dev,</p>
<p>Today, we will show you how to add blade components in laravel 10. This article will give you simple example of how to add blade components in laravel 10. Let&#8217;s discuss how to add blade components in laravel 10. In this article, we will implement a how to add blade components in laravel 10. </p>
<p><strong>What are Laravel blade components?</strong><br />
Laravel Blade components are reusable, self-contained building blocks for your views. They allow you to encapsulate UI elements, making your code cleaner, more maintainable, and promoting the concept of &#8220;Don&#8217;t Repeat Yourself&#8221; (DRY). Components are incredibly versatile and can represent anything from simple buttons to complex form elements.</p>
<h3 class="step_code">Install the Laravel 10</h3>
<pre class="brush: php; title: ; notranslate">
composer create-project --prefer-dist laravel/laravel laravel-app
cd laravel-app
</pre>
<h3 class="step_code">Create a Blade Component</h3>
<p><strong>Now, generate blade component by running the command.</strong></p>
<pre class="brush: php; title: ; notranslate">
php artisan make:component Button
cd laravel-app
</pre>
<p>&#8220;This command will create a new directory in your <strong>resources/views/components</strong> folder that will contain a blade view <strong>(button.blade.php)</strong> and the associated PHP class <strong>(button.php)</strong> within the <strong>views/components directory</strong>.</p>
<h3 class="step_code">Define the Component Blade View</h3>
<p>Navigate to the <strong>button.blade.php</strong> file located in the <strong>resources/views/components</strong> directory. Within this file, define the HTML structure and any necessary logic for your button component. For example</p>
<pre class="brush: php; title: ; notranslate">
&lt;button {{ $attributes-&gt;merge(&#x5B;'class' =&gt; 'bg-blue-500 text-white']) }}&gt;
    {{ $slot }}
&lt;/button&gt;
</pre>
<p>We take advantage of the <strong>$attributes</strong> variable to merge any additional attributes provided to the component. The <strong>$slot</strong> variable represents the content inserted within the component when used in a view.</p>
<h3 class="step_code">Use the Blade Component</h3>
<p>Now that our component is defined, let&#8217;s include it in a view. Open any Blade view (for example, <strong>resources/views/welcome.blade.php</strong>) and include your component using the <x> directive.</p>
<pre class="brush: php; title: ; notranslate">
&lt;x-button&gt;
    Click Me
&lt;/x-button&gt;
</pre>
<h3 class="step_code">Reusable Components with Parameters</h3>
<pre class="brush: php; title: ; notranslate">
&lt;x-button color=&quot;red&quot;&gt;
    Danger
&lt;/x-button&gt;
</pre>
<p>To accomplish this, access the <strong>Button.php</strong> class in the <strong>Views/Components</strong> directory and declare a public property called &#8216;color&#8217;.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

namespace App\View\Components;

use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;

class Button extends Component
{
    public $color;

    /**
    * Create a new component instance.
    */
    public function __construct($color = 'blue')
    {
        $this-&gt;color = $color;
    }

    /**
    * Get the view / contents that represent the component.
    */
    public function render(): View|Closure|string
    {
        return view('components.button');
    }
}
</pre>
<p>use the $color property inside the <strong>button.blade.php</strong> view.</p>
<pre class="brush: php; title: ; notranslate">
&lt;button {{ $attributes-&gt;merge(&#x5B;'class' =&gt; 'bg-' . $color . ' text-white']) }}&gt;
    {{ $slot }}
&lt;/button&gt;
</pre>
<p>I hope it will assist you…</p>
<p>The post <a rel="nofollow" href="https://codeplaners.com/how-to-add-blade-components-in-laravel-10/">How to Add Blade Components In Laravel 10</a> appeared first on <a rel="nofollow" href="https://codeplaners.com">Codeplaners</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codeplaners.com/how-to-add-blade-components-in-laravel-10/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
