<?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>Laravel Archives - Codeplaners</title>
	<atom:link href="https://codeplaners.com/tag/laravel/feed/" rel="self" type="application/rss+xml" />
	<link>https://codeplaners.com/tag/laravel/</link>
	<description>Code Solution</description>
	<lastBuildDate>Mon, 07 Jul 2025 05:24:41 +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>Laravel Archives - Codeplaners</title>
	<link>https://codeplaners.com/tag/laravel/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Laravel 12: Step-by-Step Guide to Comment System with Replies</title>
		<link>https://codeplaners.com/laravel-12-step-by-step-guide-to-comment-system-with-replies/</link>
					<comments>https://codeplaners.com/laravel-12-step-by-step-guide-to-comment-system-with-replies/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Mon, 07 Jul 2025 05:24:41 +0000</pubDate>
				<category><![CDATA[Codeplaners]]></category>
		<category><![CDATA[Laravel]]></category>
		<category><![CDATA[Laravel 12]]></category>
		<guid isPermaLink="false">https://codeplaners.com/?p=1791</guid>

					<description><![CDATA[<p>Hi Dev, People can chat with you and each other. That makes them feel part of something, and they’re more likely to return. When readers comment, they spend more time on your page. They may even come back to reply. That’s good for your blog’s stickiness. Comments tell you what readers liked, didn’t get, or &#8230; <a href="https://codeplaners.com/laravel-12-step-by-step-guide-to-comment-system-with-replies/" class="more-link">Continue reading<span class="screen-reader-text"> "Laravel 12: Step-by-Step Guide to Comment System with Replies"</span></a></p>
<p>The post <a rel="nofollow" href="https://codeplaners.com/laravel-12-step-by-step-guide-to-comment-system-with-replies/">Laravel 12: Step-by-Step Guide to Comment System with Replies</a> appeared first on <a rel="nofollow" href="https://codeplaners.com">Codeplaners</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Hi Dev,</p>
<p> People can chat with you and each other. That makes them feel part of something, and they’re more likely to return. When readers comment, they spend more time on your page. They may even come back to reply. That’s good for your blog’s stickiness. Comments tell you what readers liked, didn’t get, or want more of—great sparks for new posts. Readers’ comments add new words and ideas to your posts. This can help search engines see your page as more valuable.</p>
<p>We’ll begin by adding Laravel UI to set up basic user authentication, including registration and login screens. Next, we’ll build a posts table with title and body fields to allow users to create content. Once users are registered, they&#8217;ll be able to publish posts that other users can view. We’ll enable commenting on posts, and also support replies to those comments for nested discussions. To manage these relationships, we&#8217;ll utilize Laravel’s Eloquent methods—hasMany() for one-to-many and belongsTo() for the inverse connection. Follow along through each step to implement this fully functional, user-driven content system with nested commenting!</p>
<p><strong>Step for Creating Comment System in Laravel 12</strong><br />
<strong>Step 1: </strong>Install Laravel 12<br />
<strong>Step 2:</strong> Create Auth using Scaffold<br />
<strong>Step 3:</strong> Create Posts and Comments Tables<br />
<strong>Step 4:</strong> Create Models<br />
<strong>Step 5:</strong> Create Routes<br />
<strong>Step 6:</strong> Create Controller<br />
<strong>Step 7:</strong> Create and Update Blade Files<br />
Run Laravel App</p>
<h3 class="step_code">Install Laravel 12</h3>
<p>For Installing Laravel application 12 run below command. let&#8217;s start:</p>
<pre class="brush: php; title: ; notranslate">
composer create-project laravel/laravel example-app
</pre>
<h3 class="step_code"> Create Auth using Scaffold</h3>
<p>Now, we will create an auth scaffold command to generate login, register, and dashboard functionalities. So, run the below commands:</p>
<p><strong>Laravel 12 UI Package:</strong></p>
<pre class="brush: php; title: ; notranslate">
composer require laravel/ui 
</pre>
<p><strong>Generate Auth:</strong></p>
<pre class="brush: php; title: ; notranslate">
php artisan ui bootstrap --auth 
</pre>
<pre class="brush: php; title: ; notranslate">
npm install
</pre>
<pre class="brush: php; title: ; notranslate">
npm run build
</pre>
<h3 class="step_code"> Create Posts and Comments Tables</h3>
<p>For Creating Posts and Comments tables run below command.</p>
<pre class="brush: php; title: ; notranslate">
php artisan make:migration create_posts_comments_table
</pre>
<p>now, let&#8217;s update the following migrations table:<br />
<strong>database/migrations/2024_06_19_140622_create_posts_comments_table.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create(&#039;posts&#039;, function (Blueprint $table) {
            $table-&gt;id();
            $table-&gt;string(&#039;title&#039;);
            $table-&gt;text(&#039;body&#039;);
            $table-&gt;timestamps();
        });

        Schema::create(&#039;comments&#039;, function (Blueprint $table) {
            $table-&gt;id();
            $table-&gt;integer(&#039;user_id&#039;)-&gt;unsigned();
            $table-&gt;integer(&#039;post_id&#039;)-&gt;unsigned();
            $table-&gt;integer(&#039;parent_id&#039;)-&gt;unsigned()-&gt;nullable();
            $table-&gt;text(&#039;body&#039;);
            $table-&gt;timestamps();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists(&#039;posts&#039;);
        Schema::dropIfExists(&#039;comments&#039;);
    }
};
</pre>
<p>now, run the following command:</p>
<pre class="brush: php; title: ; notranslate">
php artisan migrate
</pre>
<h3 class="step_code">Create Models</h3>
<p>To implement a comment system in Laravel, you&#8217;ll need to create Post and Comment models, update the User model, also we will right relationship and some model function.</p>
<pre class="brush: php; title: ; notranslate">
php artisan make:model Post
</pre>
<p>Now, With hasMany() relationship we will update the model file.</p>
<p><strong>app/Models/Post.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use HasFactory;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = &#x5B;&#039;title&#039;, &#039;body&#039;];
   
    /**
     * The has Many Relationship
     *
     * @var array
     */
    public function comments()
    {
        return $this-&gt;hasMany(Comment::class)-&gt;whereNull(&#039;parent_id&#039;)-&gt;latest();
    }
}
</pre>
<p><strong>app/Models/Comment.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Comment extends Model
{
    use HasFactory;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = &#x5B;&#039;user_id&#039;, &#039;post_id&#039;, &#039;parent_id&#039;, &#039;body&#039;];
   
    /**
     * The belongs to Relationship
     *
     * @var array
     */
    public function user()
    {
        return $this-&gt;belongsTo(User::class);
    }
   
    /**
     * The has Many Relationship
     *
     * @var array
     */
    public function replies()
    {
        return $this-&gt;hasMany(Comment::class, &#039;parent_id&#039;);
    }
}
</pre>
<h3 class="step_code"> Create Routes</h3>
<p>Now, we need to create some routes. So open your &#8220;routes/web.php&#8221; file and add the following route.<br />
<strong>routes/web.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

use Illuminate\Support\Facades\Route;

use App\Http\Controllers\PostController;

Route::get(&#039;/&#039;, function () {
    return view(&#039;welcome&#039;);
});

Auth::routes();

Route::get(&#039;/home&#039;, &#x5B;App\Http\Controllers\HomeController::class, &#039;index&#039;])-&gt;name(&#039;home&#039;);

Route::middleware(&#039;auth&#039;)-&gt;group(function () {
    Route::get(&#039;/posts&#039;, &#x5B;PostController::class, &#039;index&#039;])-&gt;name(&#039;posts.index&#039;);
    Route::post(&#039;/posts&#039;, &#x5B;PostController::class, &#039;store&#039;])-&gt;name(&#039;posts.store&#039;);
    Route::get(&#039;/posts/{id}&#039;, &#x5B;PostController::class, &#039;show&#039;])-&gt;name(&#039;posts.show&#039;);
    Route::post(&#039;/posts/comment/store&#039;, &#x5B;PostController::class, &#039;commentStore&#039;])-&gt;name(&#039;posts.comment.store&#039;);
});
</pre>
<h3 class="step_code">Create Controller</h3>
<p>In this step, We create a new controoler, PostController. So let&#8217;s put the code below.<br />
<strong>app/Http/Controllers/PostController.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
   
namespace App\Http\Controllers;
   
use Illuminate\Http\Request;
use App\Models\Post;
use App\Models\Comment;
   
class PostController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $posts = Post::latest()-&gt;get();
    
        return view(&#039;posts.index&#039;, compact(&#039;posts&#039;));
    }
    
    /**
     * Write code on Method
     *
     * @return response()
     */
    public function store(Request $request)
    {
        $this-&gt;validate($request, &#x5B;
             &#039;title&#039; =&gt; &#039;required&#039;,
             &#039;body&#039; =&gt; &#039;required&#039;
        ]);
   
        $post = Post::create(&#x5B;
            &#039;title&#039; =&gt; $request-&gt;title,
            &#039;body&#039; =&gt; $request-&gt;body
        ]);
   
        return back()-&gt;with(&#039;success&#039;,&#039;Post created successfully.&#039;);
    }
    
    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        $post = Post::find($id);
        return view(&#039;posts.show&#039;, compact(&#039;post&#039;));
    }

    /**
     * Write code on Method
     *
     * @return response()
     */
    public function commentStore(Request $request)
    {
        $request-&gt;validate(&#x5B;
            &#039;body&#039;=&gt;&#039;required&#039;,
        ]);
   
        $input = $request-&gt;all();
        $input&#x5B;&#039;user_id&#039;] = auth()-&gt;user()-&gt;id;
    
        Comment::create($input);
   
        return back()-&gt;with(&#039;success&#039;,&#039;Comment added successfully.&#039;);
    }
}
</pre>
<h3 class="step_code"> Create and Update Blade Files</h3>
<p>Now, we will update app.blade.php file and create posts.blade file. so, let&#8217;s do it.</p>
<p><strong>resources/views/layouts/app.blade.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;!doctype html&gt;
&lt;html lang=&quot;{{ str_replace(&#039;_&#039;, &#039;-&#039;, app()-&gt;getLocale()) }}&quot;&gt;
&lt;head&gt;
    &lt;meta charset=&quot;utf-8&quot;&gt;
    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;

    &lt;!-- CSRF Token --&gt;
    &lt;meta name=&quot;csrf-token&quot; content=&quot;{{ csrf_token() }}&quot;&gt;

    &lt;title&gt;{{ config(&#039;app.name&#039;, &#039;Laravel&#039;) }}&lt;/title&gt;

    &lt;!-- Fonts --&gt;
    &lt;link rel=&quot;dns-prefetch&quot; href=&quot;//fonts.bunny.net&quot;&gt;
    &lt;link href=&quot;https://fonts.bunny.net/css?family=Nunito&quot; rel=&quot;stylesheet&quot;&gt;

    &lt;!-- Scripts --&gt;
    @vite(&#x5B;&#039;resources/sass/app.scss&#039;, &#039;resources/js/app.js&#039;])

    &lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css&quot; /&gt;

    &lt;style type=&quot;text/css&quot;&gt;
        .img-user{
            width: 40px;
            border-radius: 50%;
        }
        .col-md-1{
            padding-right: 0px !important;
        }
        .img-col{
            width: 5.33% !important;
        }
    &lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;div id=&quot;app&quot;&gt;
        &lt;nav class=&quot;navbar navbar-expand-md navbar-light bg-white shadow-sm&quot;&gt;
            &lt;div class=&quot;container&quot;&gt;
                &lt;a class=&quot;navbar-brand&quot; href=&quot;{{ url(&#039;/&#039;) }}&quot;&gt;
                    Laravel Comment System Example - ItSolutionStuff.com
                &lt;/a&gt;
                &lt;button class=&quot;navbar-toggler&quot; type=&quot;button&quot; data-bs-toggle=&quot;collapse&quot; data-bs-target=&quot;#navbarSupportedContent&quot; aria-controls=&quot;navbarSupportedContent&quot; aria-expanded=&quot;false&quot; aria-label=&quot;{{ __(&#039;Toggle navigation&#039;) }}&quot;&gt;
                    &lt;span class=&quot;navbar-toggler-icon&quot;&gt;&lt;/span&gt;
                &lt;/button&gt;

                &lt;div class=&quot;collapse navbar-collapse&quot; id=&quot;navbarSupportedContent&quot;&gt;
                    &lt;!-- Left Side Of Navbar --&gt;
                    &lt;ul class=&quot;navbar-nav me-auto&quot;&gt;

                    &lt;/ul&gt;

                    &lt;!-- Right Side Of Navbar --&gt;
                    &lt;ul class=&quot;navbar-nav ms-auto&quot;&gt;
                        &lt;!-- Authentication Links --&gt;
                        @guest
                            @if (Route::has(&#039;login&#039;))
                                &lt;li class=&quot;nav-item&quot;&gt;
                                    &lt;a class=&quot;nav-link&quot; href=&quot;{{ route(&#039;login&#039;) }}&quot;&gt;{{ __(&#039;Login&#039;) }}&lt;/a&gt;
                                &lt;/li&gt;
                            @endif

                            @if (Route::has(&#039;register&#039;))
                                &lt;li class=&quot;nav-item&quot;&gt;
                                    &lt;a class=&quot;nav-link&quot; href=&quot;{{ route(&#039;register&#039;) }}&quot;&gt;{{ __(&#039;Register&#039;) }}&lt;/a&gt;
                                &lt;/li&gt;
                            @endif
                        @else
                            &lt;li class=&quot;nav-item&quot;&gt;
                                &lt;a class=&quot;nav-link&quot; href=&quot;{{ route(&#039;posts.index&#039;) }}&quot;&gt;{{ __(&#039;Posts&#039;) }}&lt;/a&gt;
                            &lt;/li&gt;
                            &lt;li class=&quot;nav-item dropdown&quot;&gt;
                                &lt;a id=&quot;navbarDropdown&quot; class=&quot;nav-link dropdown-toggle&quot; href=&quot;#&quot; role=&quot;button&quot; data-bs-toggle=&quot;dropdown&quot; aria-haspopup=&quot;true&quot; aria-expanded=&quot;false&quot; v-pre&gt;
                                    {{ Auth::user()-&gt;name }}
                                &lt;/a&gt;

                                &lt;div class=&quot;dropdown-menu dropdown-menu-end&quot; aria-labelledby=&quot;navbarDropdown&quot;&gt;
                                    &lt;a class=&quot;dropdown-item&quot; href=&quot;{{ route(&#039;logout&#039;) }}&quot;
                                       onclick=&quot;event.preventDefault();
                                                     document.getElementById(&#039;logout-form&#039;).submit();&quot;&gt;
                                        {{ __(&#039;Logout&#039;) }}
                                    &lt;/a&gt;

                                    &lt;form id=&quot;logout-form&quot; action=&quot;{{ route(&#039;logout&#039;) }}&quot; method=&quot;POST&quot; class=&quot;d-none&quot;&gt;
                                        @csrf
                                    &lt;/form&gt;
                                &lt;/div&gt;
                            &lt;/li&gt;
                        @endguest
                    &lt;/ul&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/nav&gt;

        &lt;main class=&quot;py-4&quot;&gt;
            @yield(&#039;content&#039;)
        &lt;/main&gt;
    &lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p><strong>resources/views/posts/index.blade.php</strong></p>
<pre class="brush: php; title: ; notranslate">
@extends(&#039;layouts.app&#039;)

@section(&#039;content&#039;)
&lt;div class=&quot;container&quot;&gt;
    &lt;div class=&quot;row justify-content-center&quot;&gt;
        &lt;div class=&quot;col-md-12&quot;&gt;
            &lt;div class=&quot;card&quot;&gt;
                &lt;div class=&quot;card-header&quot;&gt;&lt;i class=&quot;fa fa-list&quot;&gt;&lt;/i&gt; {{ __(&#039;Posts List&#039;) }}&lt;/div&gt;

                &lt;div class=&quot;card-body&quot;&gt;

                    @session(&#039;success&#039;)
                        &lt;div class=&quot;alert alert-success&quot; role=&quot;alert&quot;&gt; 
                            {{ $value }}
                        &lt;/div&gt;
                    @endsession
                    
                    &lt;p&gt;&lt;strong&gt;Create New Post&lt;/strong&gt;&lt;/p&gt;
                    &lt;form method=&quot;post&quot; action=&quot;{{ route(&#039;posts.store&#039;) }}&quot; enctype=&quot;multipart/form-data&quot;&gt;
                        @csrf
                        &lt;div class=&quot;form-group&quot;&gt;
                            &lt;label&gt;Title:&lt;/label&gt;
                            &lt;input type=&quot;text&quot; name=&quot;title&quot; class=&quot;form-control&quot; /&gt;
                            @error(&#039;title&#039;)
                                &lt;div class=&quot;text-danger&quot;&gt;{{ $message }}&lt;/div&gt;
                            @enderror
                        &lt;/div&gt;
                        &lt;div class=&quot;form-group&quot;&gt;
                            &lt;label&gt;Body:&lt;/label&gt;
                            &lt;textarea class=&quot;form-control&quot; name=&quot;body&quot;&gt;&lt;/textarea&gt;
                            @error(&#039;body&#039;)
                                &lt;div class=&quot;text-danger&quot;&gt;{{ $message }}&lt;/div&gt;
                            @enderror
                        &lt;/div&gt;
                        &lt;div class=&quot;form-group mt-2&quot;&gt;
                            &lt;button type=&quot;submit&quot; class=&quot;btn btn-success btn-block&quot;&gt;&lt;i class=&quot;fa fa-save&quot;&gt;&lt;/i&gt; Submit&lt;/button&gt;
                        &lt;/div&gt;
                    &lt;/form&gt;

                    &lt;p class=&quot;mt-4&quot;&gt;&lt;strong&gt;Post List:&lt;/strong&gt;&lt;/p&gt;
                    
                    @foreach($posts as $post)
                        &lt;div class=&quot;card mt-2&quot;&gt;
                          &lt;div class=&quot;card-body&quot;&gt;
                            &lt;h5 class=&quot;card-title&quot;&gt;{{ $post-&gt;title }}&lt;/h5&gt;
                            &lt;p class=&quot;card-text&quot;&gt;{{ $post-&gt;body }}&lt;/p&gt;
                            &lt;div class=&quot;text-end&quot;&gt;
                                &lt;a href=&quot;{{ route(&#039;posts.show&#039;, $post-&gt;id) }}&quot; class=&quot;btn btn-primary&quot;&gt;View&lt;/a&gt;
                            &lt;/div&gt;
                          &lt;/div&gt;
                        &lt;/div&gt;
                    @endforeach

                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
@endsection
</pre>
<p><strong>resources/views/posts/show.blade.php</strong></p>
<pre class="brush: php; title: ; notranslate">
@extends(&#039;layouts.app&#039;)

@section(&#039;content&#039;)
&lt;div class=&quot;container&quot;&gt;
    &lt;div class=&quot;row justify-content-center&quot;&gt;
        &lt;div class=&quot;col-md-12&quot;&gt;
            &lt;div class=&quot;card&quot;&gt;
                &lt;div class=&quot;card-header&quot;&gt;&lt;h1&gt;&lt;i class=&quot;fa fa-thumbs-up&quot;&gt;&lt;/i&gt; {{ $post-&gt;title }}&lt;/h1&gt;&lt;/div&gt;

                &lt;div class=&quot;card-body&quot;&gt;

                    @session(&#039;success&#039;)
                        &lt;div class=&quot;alert alert-success&quot; role=&quot;alert&quot;&gt; 
                            {{ $value }}
                        &lt;/div&gt;
                    @endsession

                    {{ $post-&gt;body }}

                    &lt;h4 class=&quot;mt-4&quot;&gt;Comments:&lt;/h4&gt;

                    &lt;form method=&quot;post&quot; action=&quot;{{ route(&#039;posts.comment.store&#039;) }}&quot;&gt;
                        @csrf
                        &lt;div class=&quot;form-group&quot;&gt;
                            &lt;textarea class=&quot;form-control&quot; name=&quot;body&quot; placeholder=&quot;Write Your Comment...&quot;&gt;&lt;/textarea&gt;
                            &lt;input type=&quot;hidden&quot; name=&quot;post_id&quot; value=&quot;{{ $post-&gt;id }}&quot; /&gt;
                        &lt;/div&gt;
                        &lt;div class=&quot;form-group text-end&quot;&gt;
                            &lt;button class=&quot;btn btn-success mt-2&quot;&gt;&lt;i class=&quot;fa fa-comment&quot;&gt;&lt;/i&gt; Add Comment&lt;/button&gt;
                        &lt;/div&gt;
                    &lt;/form&gt;
                    
                    &lt;hr/&gt;
                    @include(&#039;posts.comments&#039;, &#x5B;&#039;comments&#039; =&gt; $post-&gt;comments, &#039;post_id&#039; =&gt; $post-&gt;id])
                    
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
@endsection

</pre>
<p><strong>resources/views/posts/comments.blade.php</strong></p>
<pre class="brush: php; title: ; notranslate">
@foreach($comments as $comment)
    &lt;div class=&quot;display-comment row mt-3&quot; @if($comment-&gt;parent_id != null) style=&quot;margin-left:40px;&quot; @endif&gt;
        &lt;div class=&quot;col-md-1 text-end img-col&quot;&gt;
            &lt;img src=&quot;https://randomuser.me/api/portraits/men/43.jpg&quot; class=&quot;img-user&quot;&gt;
        &lt;/div&gt;
        &lt;div class=&quot;col-md-11&quot;&gt;
            &lt;strong&gt;{{ $comment-&gt;user-&gt;name }}&lt;/strong&gt;
            &lt;br/&gt;&lt;small&gt;&lt;i class=&quot;fa fa-clock&quot;&gt;&lt;/i&gt; {{ $comment-&gt;created_at-&gt;diffForHumans() }}&lt;/small&gt;
            &lt;p&gt;{!! nl2br($comment-&gt;body) !!}&lt;/p&gt;
            &lt;form method=&quot;post&quot; action=&quot;{{ route(&#039;posts.comment.store&#039;) }}&quot;&gt;
                @csrf
                &lt;div class=&quot;row&quot;&gt;
                    &lt;div class=&quot;col-md-11&quot;&gt;
                        &lt;div class=&quot;form-group&quot;&gt;
                            &lt;textarea class=&quot;form-control&quot; name=&quot;body&quot; placeholder=&quot;Write Your Reply...&quot; style=&quot;height: 40px;&quot;&gt;&lt;/textarea&gt;
                            &lt;input type=&quot;hidden&quot; name=&quot;post_id&quot; value=&quot;{{ $post_id }}&quot; /&gt;
                            &lt;input type=&quot;hidden&quot; name=&quot;parent_id&quot; value=&quot;{{ $comment-&gt;id }}&quot; /&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;
                    &lt;div class=&quot;col-md-1&quot;&gt;
                        &lt;button class=&quot;btn btn-warning&quot;&gt;&lt;i class=&quot;fa fa-reply&quot;&gt;&lt;/i&gt; Reply&lt;/button&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
            &lt;/form&gt;
            @include(&#039;posts.comments&#039;, &#x5B;&#039;comments&#039; =&gt; $comment-&gt;replies])
        &lt;/div&gt;
    &lt;/div&gt;
@endforeach
</pre>
<p><strong>Run Laravel App:</strong></p>
<pre class="brush: php; title: ; notranslate">
php artisan serve
</pre>
<p><strong>I hope it will assist you…</strong></p>
<p>The post <a rel="nofollow" href="https://codeplaners.com/laravel-12-step-by-step-guide-to-comment-system-with-replies/">Laravel 12: Step-by-Step Guide to Comment System with Replies</a> appeared first on <a rel="nofollow" href="https://codeplaners.com">Codeplaners</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codeplaners.com/laravel-12-step-by-step-guide-to-comment-system-with-replies/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Laravel 12: Managing Routes Without RouteServiceProvider</title>
		<link>https://codeplaners.com/laravel-12-managing-routes-without-routeserviceprovider/</link>
					<comments>https://codeplaners.com/laravel-12-managing-routes-without-routeserviceprovider/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Thu, 26 Jun 2025 07:06:56 +0000</pubDate>
				<category><![CDATA[Laravel]]></category>
		<category><![CDATA[Laravel 12]]></category>
		<guid isPermaLink="false">https://codeplaners.com/?p=1781</guid>

					<description><![CDATA[<p>Hi Dev, before, In laravel routes made in RouteServiceProvider.php file. but, Now laravel 12 give an option to configure about routes in app.php. So, now you will have a question that if we want to create a custom route file without RouteServicesProvider.php file. so what will our next step. But laravel 12 provides options in &#8230; <a href="https://codeplaners.com/laravel-12-managing-routes-without-routeserviceprovider/" class="more-link">Continue reading<span class="screen-reader-text"> "Laravel 12: Managing Routes Without RouteServiceProvider"</span></a></p>
<p>The post <a rel="nofollow" href="https://codeplaners.com/laravel-12-managing-routes-without-routeserviceprovider/">Laravel 12: Managing Routes Without RouteServiceProvider</a> appeared first on <a rel="nofollow" href="https://codeplaners.com">Codeplaners</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Hi Dev,</p>
<p>before, In laravel routes made in RouteServiceProvider.php file. but, Now laravel 12 give an option to configure about routes in app.php.</p>
<p>So, now you will have a question that if we want to create a custom route file without RouteServicesProvider.php file. so what will our next step.<br />
But laravel 12 provides options in app.php file to define custom routes file options and you can customize routes from that file as well.</p>
<p>Before in laravel you created custom route file like below code:<br />
<strong>app/Providers/RouteServiceProvider.php</strong></p>
<pre class="brush: php; title: ; notranslate">
public function boot()
{
  $this-&gt;routes(function () {
    Route::middleware(&#039;web&#039;)
            -&gt;prefix(&#039;admin&#039;)
            -&gt;group(base_path(&#039;routes/admin.php&#039;));
  });
}
</pre>
<p>Now, In laravel 12 you can create custom route file like below code.<br />
<strong>bootstrap/app.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Support\Facades\Route;

return Application::configure(basePath: dirname(__DIR__))
    -&gt;withRouting(
        web: __DIR__.&#039;/../routes/web.php&#039;,
        commands: __DIR__.&#039;/../routes/console.php&#039;,
        channels: __DIR__.&#039;/../routes/channels.php&#039;,
        health: &#039;/up&#039;,
        then: function () {
            Route::middleware(&#039;web&#039;)
                -&gt;prefix(&#039;admin&#039;)
                -&gt;group(base_path(&#039;routes/admin.php&#039;));
        }
    )
    -&gt;withMiddleware(function (Middleware $middleware) {
        //
    })
    -&gt;withExceptions(function (Exceptions $exceptions) {
        //
    })-&gt;create();
</pre>
<p>&#8220;It&#8217;s time to build your own admin.php file, adhering to the following structure.&#8221;<br />
<strong>routes/admin.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

use Illuminate\Support\Facades\Route;

Route::get(&#039;/dashboard&#039;, &#x5B;App\Http\Controllers\HomeController::class, &#039;index&#039;]);
Route::get(&#039;/users&#039;, &#x5B;App\Http\Controllers\UserController::class, &#039;index&#039;]);
Route::get(&#039;/posts&#039;, &#x5B;App\Http\Controllers\PostController::class, &#039;index&#039;]);
</pre>
<p>For seeing the list of routes you can run below command:</p>
<pre class="brush: php; title: ; notranslate">
php artisan route:list
</pre>
<p><strong>I hope it will assist you…</strong></p>
<p>The post <a rel="nofollow" href="https://codeplaners.com/laravel-12-managing-routes-without-routeserviceprovider/">Laravel 12: Managing Routes Without RouteServiceProvider</a> appeared first on <a rel="nofollow" href="https://codeplaners.com">Codeplaners</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codeplaners.com/laravel-12-managing-routes-without-routeserviceprovider/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Laravel 11 vs Laravel 12: नया क्या है और क्या आपको अपग्रेड करना चाहिए?</title>
		<link>https://codeplaners.com/laravel-11-vs-laravel-12-difference-upgrade-guide-hindi/</link>
					<comments>https://codeplaners.com/laravel-11-vs-laravel-12-difference-upgrade-guide-hindi/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Tue, 24 Jun 2025 16:35:00 +0000</pubDate>
				<category><![CDATA[Laravel]]></category>
		<category><![CDATA[Laravel 11]]></category>
		<category><![CDATA[Laravel 12]]></category>
		<category><![CDATA[Laravel 11 vs Laravel 12]]></category>
		<category><![CDATA[Laravel 12 नया क्या है]]></category>
		<category><![CDATA[Laravel comparison]]></category>
		<category><![CDATA[Laravel developer tips]]></category>
		<category><![CDATA[Laravel guide 2025]]></category>
		<category><![CDATA[Laravel Hindi blog]]></category>
		<category><![CDATA[Laravel latest version]]></category>
		<category><![CDATA[Laravel new features]]></category>
		<category><![CDATA[Laravel performance]]></category>
		<category><![CDATA[Laravel tutorial in Hindi]]></category>
		<category><![CDATA[Laravel update]]></category>
		<category><![CDATA[Laravel upgrade]]></category>
		<category><![CDATA[Laravel अपग्रेड गाइड]]></category>
		<category><![CDATA[PHP framework]]></category>
		<category><![CDATA[PHP फ्रेमवर्क हिंदी में]]></category>
		<category><![CDATA[लारवेल 11 बनाम 12]]></category>
		<category><![CDATA[लारवेल ट्यूटोरियल हिंदी]]></category>
		<guid isPermaLink="false">https://codeplaners.com/?p=1769</guid>

					<description><![CDATA[<p>Laravel 11 vs Laravel 12 – कौन बेहतर है? Laravel का हर नया वर्जन developers के लिए नए features, improvements और बेहतर performance लेकर आता है। Laravel 12 फरवरी 2025 में रिलीज़ हुआ है और इसमें कई ऐसे बदलाव किए गए हैं जो Laravel 11 से अलग हैं। आइए विस्तार से जानते हैं Laravel 11 &#8230; <a href="https://codeplaners.com/laravel-11-vs-laravel-12-difference-upgrade-guide-hindi/" class="more-link">Continue reading<span class="screen-reader-text"> "Laravel 11 vs Laravel 12: नया क्या है और क्या आपको अपग्रेड करना चाहिए?"</span></a></p>
<p>The post <a rel="nofollow" href="https://codeplaners.com/laravel-11-vs-laravel-12-difference-upgrade-guide-hindi/">Laravel 11 vs Laravel 12: नया क्या है और क्या आपको अपग्रेड करना चाहिए?</a> appeared first on <a rel="nofollow" href="https://codeplaners.com">Codeplaners</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Laravel 11 vs Laravel 12 – कौन बेहतर है?</h2>
<p>Laravel का हर नया वर्जन developers के लिए नए features, improvements और बेहतर performance लेकर आता है। Laravel 12 फरवरी 2025 में रिलीज़ हुआ है और इसमें कई ऐसे बदलाव किए गए हैं जो Laravel 11 से अलग हैं। आइए विस्तार से जानते हैं Laravel 11 और Laravel 12 के बीच क्या अंतर है।</p>
<h3> इस ब्लॉग में आप जानेंगे:</h3>
<ul>
<li>Laravel 11 और Laravel 12 की मुख्य विशेषताएँ</li>
<li>कौन-सा version किसके लिए बेहतर है?</li>
<li>Laravel 12 में क्या नया है?</li>
<li>Upgrade गाइड: Laravel 11 से 12 में कैसे जाएं?</li>
</ul>
<h2>Laravel 11 vs Laravel 12: मुख्य अंतर</h2>
<table>
<thead>
<tr>
<th>पैरामीटर</th>
<th>Laravel 11</th>
<th>Laravel 12</th>
</tr>
</thead>
<tbody>
<tr>
<td>रिलीज़ डेट</td>
<td>12 मार्च 2024</td>
<td>24 फरवरी 2025</td>
</tr>
<tr>
<td>PHP वर्जन सपोर्ट</td>
<td>8.2 &#8211; 8.4</td>
<td>8.2 &#8211; 8.4</td>
</tr>
<tr>
<td>Frontend Stacks</td>
<td>React, Vue (basic)</td>
<td>New React/Vue + Livewire kits</td>
</tr>
<tr>
<td>New Features</td>
<td>Slim skeleton, built-in scheduler</td>
<td>WorkOS AuthKit, Flux UI, GraphQL</td>
</tr>
<tr>
<td>Performance</td>
<td>Good</td>
<td>Improved with async queues</td>
</tr>
<tr>
<td>Security</td>
<td>Standard</td>
<td>Advanced MFA, Password Hashing</td>
</tr>
<tr>
<td>Upgrade Complexity</td>
<td>Low to Medium</td>
<td>Very Low</td>
</tr>
</tbody>
</table>
<h2>Laravel 12 की नई विशेषताएं</h2>
<ul>
<li><strong>Starter Kits</strong> – Inertia.js 2, TypeScript, Tailwind, Livewire Flux UI</li>
<li><strong>WorkOS AuthKit</strong> – Passkeys, Social Login, SSO</li>
<li><strong>GraphQL Support</strong> – API developers के लिए built-in सपोर्ट</li>
<li><strong>Stricter Typing</strong> – बेहतर code intelligence और कम bugs</li>
<li><strong>Performance Improvements</strong> – Faster routing, better queue handling</li>
<li><strong>Security Upgrades</strong> – Advanced CSRF, password hashing algorithms</li>
</ul>
<h2>Laravel 11 से Laravel 12 में Upgrade कैसे करें?</h2>
<ol>
<li>Composer में Laravel dependency को <code>^12.0</code> पर सेट करें</li>
<li>Carbon 3.x में upgrade करें (2.x सपोर्ट नहीं है)</li>
<li>PHPUnit और Pest के नए वर्जन इस्तेमाल करें</li>
<li>Laravel Installer और Herd CLI को update करें</li>
</ol>
<p> अपग्रेड में 5 मिनट से भी कम लगते हैं अगर आप Laravel 11 पहले से इस्तेमाल कर रहे हैं।</p>
<h2>Conclusion</h2>
<p>अगर आप stability और modern tools चाहते हैं तो Laravel 12 एक बेहतरीन अपग्रेड है। यह secure, तेज़ और future-ready है। Laravel 11 भी अच्छा है, लेकिन 12 में आपको better developer experience और नए stacks का सपोर्ट मिलता है।</p>
<p><strong>क्या आपने Laravel 12 को आज़माया है? नीचे कमेंट में ज़रूर बताएं।</strong></p>
<p>The post <a rel="nofollow" href="https://codeplaners.com/laravel-11-vs-laravel-12-difference-upgrade-guide-hindi/">Laravel 11 vs Laravel 12: नया क्या है और क्या आपको अपग्रेड करना चाहिए?</a> appeared first on <a rel="nofollow" href="https://codeplaners.com">Codeplaners</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codeplaners.com/laravel-11-vs-laravel-12-difference-upgrade-guide-hindi/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to send Real-Time Notifications using Pusher Example in Laravel 12</title>
		<link>https://codeplaners.com/how-to-send-real-time-notifications-using-pusher-example-in-laravel-12/</link>
					<comments>https://codeplaners.com/how-to-send-real-time-notifications-using-pusher-example-in-laravel-12/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Tue, 24 Jun 2025 12:00:07 +0000</pubDate>
				<category><![CDATA[Laravel]]></category>
		<category><![CDATA[Laravel 10]]></category>
		<category><![CDATA[Laravel 12]]></category>
		<guid isPermaLink="false">https://codeplaners.com/?p=1763</guid>

					<description><![CDATA[<p>Hi Dev, In this article, I will show you how to send real-time notification with Pusher in the laravel 12. we will use a pusher driver to send real-time notification using the echo server in the laravel 12 What is Pusher? Pusher: Pusher lets apps talk to each other in real time — like live &#8230; <a href="https://codeplaners.com/how-to-send-real-time-notifications-using-pusher-example-in-laravel-12/" class="more-link">Continue reading<span class="screen-reader-text"> "How to send Real-Time Notifications using Pusher Example in Laravel 12"</span></a></p>
<p>The post <a rel="nofollow" href="https://codeplaners.com/how-to-send-real-time-notifications-using-pusher-example-in-laravel-12/">How to send Real-Time Notifications using Pusher Example in Laravel 12</a> appeared first on <a rel="nofollow" href="https://codeplaners.com">Codeplaners</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Hi Dev,</p>
<p>In this article, I will show you how to send real-time notification with Pusher in the laravel 12. we will use a pusher driver to send real-time notification using the echo server in the laravel 12</p>
<p><strong> What is Pusher?</strong><br />
<strong>Pusher: </strong><br />
Pusher lets apps talk to each other in real time — like live chat or instant updates on your screen.</p>
<p>It uses WebSockets (a fast, always-on connection) so information flows instantly, not by checking every few seconds.</p>
<p>Think of it as a messenger service: your server sends a message using Pusher, and all connected users get it right away.</p>
<p><strong>Here’s what we’ll build in this example:</strong></p>
<p>1. Create authentication scaffolding using Laravel UI to get login/register dashboards up and running.<br />
2. Set up two user roles: a super admin and a normal user, distinguished via an is_admin flag.<br />
3. Define a posts table with title and body columns, and create corresponding Eloquent models.<br />
4. Enable users to create posts through a form, saving them via a controller.<br />
5. Fire a broadcast event (PostCreated) when a post is saved—this triggers a real-time notification via Pusher to admins.</p>
<p><strong>Step 1:</strong> Install Laravel 12<br />
<strong>Step 2:</strong> Create Auth using Scaffold<br />
<strong>Step 3:</strong> Create Migrations<br />
<strong>Step 4:</strong> Create and Update Models<br />
<strong>Step 5:</strong> Create Pusher App<br />
<strong>Step 6:</strong> Setup Pusher &#038; Echo Server<br />
<strong>Step 7:</strong> Create PostCreate Event<br />
<strong>Step 8:</strong> Create Routes<br />
<strong>Step 9:</strong> create Controller<br />
<strong>Step 10:</strong> create Blade Files<br />
<strong>Step 11:</strong> Create admin User </p>
<h3 class="step_code">Install Laravel 12</h3>
<p>For Installing Laravel application 12 run below command. let&#8217;s start:</p>
<pre class="brush: php; title: ; notranslate">
composer create-project laravel/laravel example-app
</pre>
<h3 class="step_code"> Create Auth using Scaffold</h3>
<p>Now, we will create an auth scaffold command to generate login, register, and dashboard functionalities. So, run the below commands:</p>
<p><strong>Laravel 12 UI Package:</strong></p>
<pre class="brush: php; title: ; notranslate">
composer require laravel/ui 
</pre>
<p><strong>Generate Auth:</strong></p>
<pre class="brush: php; title: ; notranslate">
php artisan ui bootstrap --auth 
</pre>
<pre class="brush: php; title: ; notranslate">
npm install
</pre>
<pre class="brush: php; title: ; notranslate">
npm run build
</pre>
<h3 class="step_code">Create Migrations</h3>
<p>Here, we will create posts and add is_admin column to users table. So, run the below commands: </p>
<pre class="brush: php; title: ; notranslate">
php artisan make:migration add_is_admin_column_table
</pre>
<pre class="brush: php; title: ; notranslate">
php artisan make:migration create_posts_table
</pre>
<p><strong>database/migrations/2025_06_23_100454_create_posts_table.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table(&#039;users&#039;, function (Blueprint $table) {
            $table-&gt;tinyInteger(&#039;is_admin&#039;)-&gt;default(0);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        //
    }
};
</pre>
<p><strong>database/migrations/2025_06_23_100442_add_is_admin_column_table.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create(&#039;posts&#039;, function (Blueprint $table) {
            $table-&gt;id();
            $table-&gt;foreignId(&#039;user_id&#039;)-&gt;constrained()-&gt;onDelete(&#039;cascade&#039;);
            $table-&gt;string(&#039;title&#039;);
            $table-&gt;text(&#039;body&#039;);
            $table-&gt;timestamps();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists(&#039;posts&#039;);
    }
};
</pre>
<p>now, Let&#8217;s run the below command:</p>
<pre class="brush: php; title: ; notranslate">
php artisan migrate
</pre>
<h3 class="step_code"> Create and Update Models</h3>
<p>Now, we will create model using below command. we also need to update User model here. we will write relationship and some model function for like and dislike.</p>
<pre class="brush: php; title: ; notranslate">
php artisan make:model Post
</pre>
<p><strong>app/Models/Post.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use HasFactory;

    protected $fillable = &#x5B;&#039;title&#039;, &#039;body&#039;, &#039;user_id&#039;];

    /**
     * Write code on Method
     *
     * @return response()
     */
    public function user()
    {
        return $this-&gt;belongsTo(User::class);
    }
}
</pre>
<p><strong>app/Models/User.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class User extends Authenticatable
{
    use HasFactory, Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = &#x5B;
        &#039;name&#039;,
        &#039;email&#039;,
        &#039;password&#039;,
        &#039;is_admin&#039;
    ];

    /**
     * The attributes that should be hidden for serialization.
     *
     * @var array
     */
    protected $hidden = &#x5B;
        &#039;password&#039;,
        &#039;remember_token&#039;,
    ];

    /**
     * Get the attributes that should be cast.
     *
     * @return array
     */
    protected function casts(): array
    {
        return &#x5B;
            &#039;email_verified_at&#039; =&gt; &#039;datetime&#039;,
            &#039;password&#039; =&gt; &#039;hashed&#039;,
        ];
    }
}
</pre>
<h3 class="step_code">Create Pusher App</h3>
<p>In this step, we will create account on pusher website. Here, you&#8217;ll find the following credentials: App ID, Key, Secret, Cluster.<br />
1. Create Account on Pusher Platform.<br />
2. Now, Click on Get Started button.</p>
<p><img decoding="async" src="https://codeplaners.com/wp-content/uploads/2025/06/screen-1.jpg" alt="" style="width: 80%;border: 2px solid #e5e7eb;border-radius: 0.75rem;box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);object-fit: cover;" /></p>
<p>3. Fill your app name than click on submit button.</p>
<p><img decoding="async" src="https://codeplaners.com/wp-content/uploads/2025/06/screen-2.jpg" alt="" style="width: 80%;border: 2px solid #e5e7eb;border-radius: 0.75rem;box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);object-fit: cover;" /></p>
<p>4. Now, go to App Keys section and copy details. we will use it latter:</p>
<p><img decoding="async" src="https://codeplaners.com/wp-content/uploads/2025/06/screen-3.jpg" alt="" style="width: 80%;border: 2px solid #e5e7eb;border-radius: 0.75rem;box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);object-fit: cover;" /></p>
<h3 class="step_code">Setup Pusher &#038; Echo Server</h3>
<p>For setup Pusher &#038; Echo server you need to run the following command.<br />
Generate broadcasting:</p>
<pre class="brush: php; title: ; notranslate">
php artisan install:broadcasting
</pre>
<p>Now, we will install pusher-php-server to use driver as pusher, so let&#8217;s run the given command:</p>
<pre class="brush: php; title: ; notranslate">
composer require pusher/pusher-php-server
</pre>
<p>Now, we will install laravel echo server. so, let&#8217;s run the below commands:</p>
<pre class="brush: php; title: ; notranslate">
npm install --save-dev laravel-echo pusher-js
</pre>
<p>Now, you will see echo.js file. where you can make a changes:<br />
<strong>resources/js/echo.js</strong></p>
<pre class="brush: php; title: ; notranslate">
import Echo from &#039;laravel-echo&#039;;
 
import Pusher from &#039;pusher-js&#039;;
window.Pusher = Pusher;
 
window.Echo = new Echo({
    broadcaster: &#039;pusher&#039;,
    key: import.meta.env.VITE_PUSHER_APP_KEY,
    cluster: import.meta.env.VITE_PUSHER_APP_CLUSTER,
    forceTLS: false
});
</pre>
<p><strong>.env</strong></p>
<pre class="brush: php; title: ; notranslate">
BROADCAST_CONNECTION=pusher

PUSHER_APP_ID=&quot;1822914&quot;
PUSHER_APP_KEY=&quot;b47df8a8ea52a814246e&quot;
PUSHER_APP_SECRET=&quot;5f9397a869...&quot;
PUSHER_HOST=
PUSHER_PORT=443
PUSHER_SCHEME=&quot;https&quot;
PUSHER_APP_CLUSTER=&quot;ap2&quot;

VITE_APP_NAME=&quot;${APP_NAME}&quot;
VITE_PUSHER_APP_KEY=&quot;${PUSHER_APP_KEY}&quot;
VITE_PUSHER_HOST=&quot;${PUSHER_HOST}&quot;
VITE_PUSHER_PORT=&quot;${PUSHER_PORT}&quot;
VITE_PUSHER_SCHEME=&quot;${PUSHER_SCHEME}&quot;
VITE_PUSHER_APP_CLUSTER=&quot;${PUSHER_APP_CLUSTER}&quot;
</pre>
<p>Now again run build command:</p>
<pre class="brush: php; title: ; notranslate">
npm run build
</pre>
<h3 class="step_code"> Create PostCreate Event</h3>
<p>In this step, we need to create &#8220;Event&#8221;. so let&#8217;s run the command below.</p>
<pre class="brush: php; title: ; notranslate">
php artisan make:event PostCreate
</pre>
<p>Now, you will see a new folder created as &#8220;Events&#8221;. where you can make a changes:<br />
<strong>app/Events/PostCreate.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;

class PostCreate implements ShouldBroadcastNow
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

     public $post;

    /**
     * Create a new event instance.
     */
    public function __construct($post)
    {
        $this-&gt;post = $post;
    }

    /**
     * Write code on Method
     *
     * @return response()
     */
    public function broadcastOn()
    {
        return new Channel(&#039;posts&#039;);
    }

    /**
     * Write code on Method
     *
     * @return response()
     */
    public function broadcastAs()
    {
        return &#039;create&#039;;
    }

    /**
     * Get the data to broadcast.
     *
     * @return array
     */
    public function broadcastWith(): array
    {
        return &#x5B;
            &#039;message&#039; =&gt; &quot;&#x5B;{$this-&gt;post-&gt;created_at}] New Post Received with title &#039;{$this-&gt;post-&gt;title}&#039;.&quot;
        ];
    }
}
</pre>
<h3 class="step_code">Create Routes</h3>
<p>now we need to create some routes. so, add some the following routes. </p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

use Illuminate\Support\Facades\Route;

use App\Http\Controllers\PostController;

Route::get(&#039;/&#039;, function () {
    return view(&#039;welcome&#039;);
});

Auth::routes();

Route::get(&#039;/home&#039;, &#x5B;App\Http\Controllers\HomeController::class, &#039;index&#039;])-&gt;name(&#039;home&#039;);

Route::get(&#039;/posts&#039;, &#x5B;PostController::class, &#039;index&#039;])-&gt;name(&#039;posts.index&#039;);
Route::post(&#039;/posts&#039;, &#x5B;PostController::class, &#039;store&#039;])-&gt;name(&#039;posts.store&#039;);
</pre>
<h3 class="step_code">Create Controller</h3>
<p><strong>app/Http/Controllers/PostController.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Post;
use App\Events\PostCreate;

class PostController extends Controller
{
    /**
     * Write code on Method
     *
     * @return response()
     */
    public function index(Request $request)
    {
        $posts = Post::get();

        return view(&#039;posts&#039;, compact(&#039;posts&#039;));
    }

    /**
     * Write code on Method
     *
     * @return response()
     */
    public function store(Request $request)
    {
        $this-&gt;validate($request, &#x5B;
             &#039;title&#039; =&gt; &#039;required&#039;,
             &#039;body&#039; =&gt; &#039;required&#039;
        ]);
   
        $post = Post::create(&#x5B;
            &#039;user_id&#039; =&gt; auth()-&gt;id(),
            &#039;title&#039; =&gt; $request-&gt;title,
            &#039;body&#039; =&gt; $request-&gt;body
        ]);

        event(new PostCreate($post));
   
        return back()-&gt;with(&#039;success&#039;,&#039;Post created successfully.&#039;);
    }
}
</pre>
<h3 class="step_code">Create and Update Blade Files</h3>
<p>Now, we will update app.blade.php file and create posts.blade file.<br />
<strong>resources/views/layouts/app.blade.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;!doctype html&gt;
&lt;html lang=&quot;{{ str_replace(&#039;_&#039;, &#039;-&#039;, app()-&gt;getLocale()) }}&quot;&gt;
&lt;head&gt;
    &lt;meta charset=&quot;utf-8&quot;&gt;
    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;

    &lt;!-- CSRF Token --&gt;
    &lt;meta name=&quot;csrf-token&quot; content=&quot;{{ csrf_token() }}&quot;&gt;

    &lt;title&gt;{{ config(&#039;app.name&#039;, &#039;Laravel&#039;) }}&lt;/title&gt;

    &lt;!-- Fonts --&gt;
    &lt;link rel=&quot;dns-prefetch&quot; href=&quot;//fonts.bunny.net&quot;&gt;
    &lt;link href=&quot;https://fonts.bunny.net/css?family=Nunito&quot; rel=&quot;stylesheet&quot;&gt;

    &lt;!-- Scripts --&gt;
    @vite(&#x5B;&#039;resources/sass/app.scss&#039;, &#039;resources/js/app.js&#039;])
    
    &lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css&quot; /&gt;
    @yield(&#039;script&#039;)
&lt;/head&gt;
&lt;body&gt;
    &lt;div id=&quot;app&quot;&gt;
        &lt;nav class=&quot;navbar navbar-expand-md navbar-light bg-white shadow-sm&quot;&gt;
            &lt;div class=&quot;container&quot;&gt;
                &lt;a class=&quot;navbar-brand&quot; href=&quot;{{ url(&#039;/&#039;) }}&quot;&gt;
                    Laravel Send Realtime Notification using Pusher
                &lt;/a&gt;
                &lt;button class=&quot;navbar-toggler&quot; type=&quot;button&quot; data-bs-toggle=&quot;collapse&quot; data-bs-target=&quot;#navbarSupportedContent&quot; aria-controls=&quot;navbarSupportedContent&quot; aria-expanded=&quot;false&quot; aria-label=&quot;{{ __(&#039;Toggle navigation&#039;) }}&quot;&gt;
                    &lt;span class=&quot;navbar-toggler-icon&quot;&gt;&lt;/span&gt;
                &lt;/button&gt;

                &lt;div class=&quot;collapse navbar-collapse&quot; id=&quot;navbarSupportedContent&quot;&gt;
                    &lt;!-- Left Side Of Navbar --&gt;
                    &lt;ul class=&quot;navbar-nav me-auto&quot;&gt;

                    &lt;/ul&gt;

                    &lt;!-- Right Side Of Navbar --&gt;
                    &lt;ul class=&quot;navbar-nav ms-auto&quot;&gt;
                        &lt;!-- Authentication Links --&gt;
                        @guest
                            @if (Route::has(&#039;login&#039;))
                                &lt;li class=&quot;nav-item&quot;&gt;
                                    &lt;a class=&quot;nav-link&quot; href=&quot;{{ route(&#039;login&#039;) }}&quot;&gt;{{ __(&#039;Login&#039;) }}&lt;/a&gt;
                                &lt;/li&gt;
                            @endif

                            @if (Route::has(&#039;register&#039;))
                                &lt;li class=&quot;nav-item&quot;&gt;
                                    &lt;a class=&quot;nav-link&quot; href=&quot;{{ route(&#039;register&#039;) }}&quot;&gt;{{ __(&#039;Register&#039;) }}&lt;/a&gt;
                                &lt;/li&gt;
                            @endif
                        @else
                            &lt;li class=&quot;nav-item&quot;&gt;
                                &lt;a class=&quot;nav-link&quot; href=&quot;{{ route(&#039;posts.index&#039;) }}&quot;&gt;{{ __(&#039;Posts&#039;) }}&lt;/a&gt;
                            &lt;/li&gt;
                            &lt;li class=&quot;nav-item dropdown&quot;&gt;
                                &lt;a id=&quot;navbarDropdown&quot; class=&quot;nav-link dropdown-toggle&quot; href=&quot;#&quot; role=&quot;button&quot; data-bs-toggle=&quot;dropdown&quot; aria-haspopup=&quot;true&quot; aria-expanded=&quot;false&quot; v-pre&gt;
                                    {{ Auth::user()-&gt;name }}
                                &lt;/a&gt;

                                &lt;div class=&quot;dropdown-menu dropdown-menu-end&quot; aria-labelledby=&quot;navbarDropdown&quot;&gt;
                                    &lt;a class=&quot;dropdown-item&quot; href=&quot;{{ route(&#039;logout&#039;) }}&quot;
                                       onclick=&quot;event.preventDefault();
                                                     document.getElementById(&#039;logout-form&#039;).submit();&quot;&gt;
                                        {{ __(&#039;Logout&#039;) }}
                                    &lt;/a&gt;

                                    &lt;form id=&quot;logout-form&quot; action=&quot;{{ route(&#039;logout&#039;) }}&quot; method=&quot;POST&quot; class=&quot;d-none&quot;&gt;
                                        @csrf
                                    &lt;/form&gt;
                                &lt;/div&gt;
                            &lt;/li&gt;
                        @endguest
                    &lt;/ul&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/nav&gt;

        &lt;main class=&quot;py-4&quot;&gt;
            @yield(&#039;content&#039;)
        &lt;/main&gt;
    &lt;/div&gt;
&lt;/body&gt;

&lt;/html&gt;
</pre>
<p><strong>resources/views/posts.blade.php</strong></p>
<pre class="brush: php; title: ; notranslate">
@extends(&#039;layouts.app&#039;)

@section(&#039;content&#039;)
&lt;div class=&quot;container&quot;&gt;
    &lt;div class=&quot;row justify-content-center&quot;&gt;
        &lt;div class=&quot;col-md-12&quot;&gt;
            &lt;div class=&quot;card&quot;&gt;
                &lt;div class=&quot;card-header&quot;&gt;&lt;i class=&quot;fa fa-list&quot;&gt;&lt;/i&gt; {{ __(&#039;Posts List&#039;) }}&lt;/div&gt;

                &lt;div class=&quot;card-body&quot;&gt;
                    @session(&#039;success&#039;)
                        &lt;div class=&quot;alert alert-success&quot; role=&quot;alert&quot;&gt; 
                            {{ $value }}
                        &lt;/div&gt;
                    @endsession

                    &lt;div id=&quot;notification&quot;&gt;
                        
                    &lt;/div&gt;
                    
                    @if(!auth()-&gt;user()-&gt;is_admin)
                    &lt;p&gt;&lt;strong&gt;Create New Post&lt;/strong&gt;&lt;/p&gt;
                    &lt;form method=&quot;post&quot; action=&quot;{{ route(&#039;posts.store&#039;) }}&quot; enctype=&quot;multipart/form-data&quot;&gt;
                        @csrf
                        &lt;div class=&quot;form-group&quot;&gt;
                            &lt;label&gt;Title:&lt;/label&gt;
                            &lt;input type=&quot;text&quot; name=&quot;title&quot; class=&quot;form-control&quot; /&gt;
                            @error(&#039;title&#039;)
                                &lt;div class=&quot;text-danger&quot;&gt;{{ $message }}&lt;/div&gt;
                            @enderror
                        &lt;/div&gt;
                        &lt;div class=&quot;form-group&quot;&gt;
                            &lt;label&gt;Body:&lt;/label&gt;
                            &lt;textarea class=&quot;form-control&quot; name=&quot;body&quot;&gt;&lt;/textarea&gt;
                            @error(&#039;body&#039;)
                                &lt;div class=&quot;text-danger&quot;&gt;{{ $message }}&lt;/div&gt;
                            @enderror
                        &lt;/div&gt;
                        &lt;div class=&quot;form-group mt-2&quot;&gt;
                            &lt;button type=&quot;submit&quot; class=&quot;btn btn-success btn-block&quot;&gt;&lt;i class=&quot;fa fa-save&quot;&gt;&lt;/i&gt; Submit&lt;/button&gt;
                        &lt;/div&gt;
                    &lt;/form&gt;
                    @endif

                    &lt;p class=&quot;mt-4&quot;&gt;&lt;strong&gt;Post List:&lt;/strong&gt;&lt;/p&gt;
                    &lt;table class=&quot;table table-bordered data-table&quot;&gt;
                        &lt;thead&gt;
                            &lt;tr&gt;
                                &lt;th width=&quot;70px&quot;&gt;ID&lt;/th&gt;
                                &lt;th&gt;Title&lt;/th&gt;
                                &lt;th&gt;Body&lt;/th&gt;
                            &lt;/tr&gt;
                        &lt;/thead&gt;
                        &lt;tbody&gt;
                            @forelse($posts as $post)
                                &lt;tr&gt;
                                    &lt;td&gt;{{ $post-&gt;id }}&lt;/td&gt;
                                    &lt;td&gt;{{ $post-&gt;title }}&lt;/td&gt;
                                    &lt;td&gt;{{ $post-&gt;body }}&lt;/td&gt;
                                &lt;/tr&gt;
                            @empty
                                &lt;tr&gt;
                                    &lt;td colspan=&quot;5&quot;&gt;There are no posts.&lt;/td&gt;
                                &lt;/tr&gt;
                            @endforelse
                        &lt;/tbody&gt;
                    &lt;/table&gt;

                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
@endsection

@section(&#039;script&#039;)
@if(auth()-&gt;user()-&gt;is_admin)
    &lt;script type=&quot;module&quot;&gt;
            window.Echo.channel(&#039;posts&#039;)
                .listen(&#039;.create&#039;, (data) =&gt; {
                    console.log(&#039;Order status updated: &#039;, data);
                    var d1 = document.getElementById(&#039;notification&#039;);
                    d1.insertAdjacentHTML(&#039;beforeend&#039;, &#039;&lt;div class=&quot;alert alert-success alert-dismissible fade show&quot;&gt;&lt;span&gt;&lt;i class=&quot;fa fa-circle-check&quot;&gt;&lt;/i&gt;  &#039;+data.message+&#039;&lt;/span&gt;&lt;/div&gt;&#039;);
                });
    &lt;/script&gt;
@endif
@endsection
</pre>
<h3 class="step_code"> Create Admin User</h3>
<p>To create admin user we need to create seeder. so run this command.<br />
Let&#8217;s run the migration command:</p>
<pre class="brush: php; title: ; notranslate">
php artisan make:seeder CreateAdminUser
</pre>
<p>Now, we need to do some changes in CreateAdminUser seeder.<br />
<strong>database/seeders/CreateAdminUser.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

namespace Database\Seeders;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use App\Models\User;

class CreateAdminUser extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        User::create(&#x5B;
            &#039;name&#039; =&gt; &#039;Admin&#039;,
            &#039;email&#039; =&gt; &#039;admin@gmail.com&#039;,
            &#039;password&#039; =&gt; bcrypt(&#039;123456&#039;),
            &#039;is_admin&#039; =&gt; 1
        ]);
    }
}
</pre>
<p>now, the run seeder using the below command:</p>
<pre class="brush: php; title: ; notranslate">
php artisan db:seed --class=CreateAdminUser
</pre>
<p><strong>Run Laravel App:</strong></p>
<pre class="brush: php; title: ; notranslate">
php artisan serve
</pre>
<p>Now, you have one admin user and you can register another normal user from registration form.<br />
Now, when you post then admin user will get the notification.</p>
<p><strong>I hope it will assist you…</strong></p>
<p>The post <a rel="nofollow" href="https://codeplaners.com/how-to-send-real-time-notifications-using-pusher-example-in-laravel-12/">How to send Real-Time Notifications using Pusher Example in Laravel 12</a> appeared first on <a rel="nofollow" href="https://codeplaners.com">Codeplaners</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codeplaners.com/how-to-send-real-time-notifications-using-pusher-example-in-laravel-12/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Upload &#038; Store Image in Laravel</title>
		<link>https://codeplaners.com/upload-store-image-in-laravel/</link>
					<comments>https://codeplaners.com/upload-store-image-in-laravel/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Wed, 18 Jun 2025 10:39:47 +0000</pubDate>
				<category><![CDATA[Laravel]]></category>
		<category><![CDATA[Laravel 10]]></category>
		<category><![CDATA[Laravel 12]]></category>
		<guid isPermaLink="false">https://codeplaners.com/?p=1754</guid>

					<description><![CDATA[<p>hi Dev, today in this article we will understand how to upload &#038; Store Image in Laravel. Follow a few straightforward steps to let users upload images via a Blade form and store them in Laravel’s filesystem. So let&#8217;s start : Install Laravel 12 composer create-project laravel/laravel example-image Create Model php artisan create_images_table database/migrations/create_images_table.php &#60;?php &#8230; <a href="https://codeplaners.com/upload-store-image-in-laravel/" class="more-link">Continue reading<span class="screen-reader-text"> "Upload &#038; Store Image in Laravel"</span></a></p>
<p>The post <a rel="nofollow" href="https://codeplaners.com/upload-store-image-in-laravel/">Upload &#038; Store Image in Laravel</a> appeared first on <a rel="nofollow" href="https://codeplaners.com">Codeplaners</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>hi Dev,<br />
today in this article we will understand how to upload &#038; Store Image in Laravel. </p>
<p>Follow a few straightforward steps to let users upload images via a Blade form and store them in Laravel’s filesystem. So let&#8217;s start :</p>
<h3 class="step_code"> Install Laravel 12</h3>
<pre class="brush: php; title: ; notranslate">
composer create-project laravel/laravel example-image
</pre>
<h3 class="step_code"> Create Model</h3>
<pre class="brush: php; title: ; notranslate">
php artisan create_images_table
</pre>
<p><strong>database/migrations/create_images_table.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
   
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
   
return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create(&#039;images&#039;, function (Blueprint $table) {
            $table-&gt;id();
            $table-&gt;string(&#039;title&#039;);
            $table-&gt;string(&#039;image&#039;);
            $table-&gt;timestamps();
        });
   
        DB::statement(&quot;ALTER TABLE images ADD file MEDIUMBLOB&quot;);
    }
   
    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists(&#039;images&#039;);
    }
};
</pre>
<p><strong>app/Models/Image.php</strong></p>
<pre class="brush: plain; title: ; notranslate">
&lt;?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;


class Image extends Model
{
    
    protected $fillable = &#x5B;
        &#039;title&#039;,
        &#039;image&#039;,
    ];

    
}
</pre>
<h3 class="step_code">Create Controller</h3>
<pre class="brush: php; title: ; notranslate">
php artisan make:controller ImageController
</pre>
<p><strong>app/Http/Controllers/ImageController.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

namespace App\Http\Controllers;
use App\Models\Image;
use Illuminate\Http\Request;

class ImageController extends Controller
{
    public function upload(Request $request)
    {
        $file = $request-&gt;file(&#039;file&#039;);
        $imgPath = time().&#039;_&#039;.$file-&gt;getClientOriginalName();
        $file-&gt;move(public_path(&#039;images/imglist&#039;), $imgPath);

        $image = new Image();
        $image-&gt;path = &#039;images/imglist/&#039; . $imgPath;
        $image-&gt;save();

        return redirect()-&gt;route(&#039;images.list&#039;)
                         -&gt;with(&#039;success&#039;, &#039;Image uploaded successfully&#039;);
    }

    public function list()
    {
        $imageData = Image::all();
        return view(&#039;display&#039;, compact(&#039;imageData&#039;));
    }
}

</pre>
<h3 class="step_code">Create Add Routes</h3>
<p><strong>routes/web.php</strong></p>
<pre class="brush: php; title: ; notranslate">

use App\Http\Controllers\ImageController;

Route::get(&#039;/images&#039;, &#x5B;ImageController::class, &#039;list&#039;])-&gt;name(&#039;images.list&#039;);
Route::post(&#039;/upload&#039;, &#x5B;ImageController::class, &#039;upload&#039;])-&gt;name(&#039;images.upload&#039;);

</pre>
<h3 class="step_code">Create Blade File</h3>
<p><strong>resources/views/addpost.blade.php</strong></p>
<pre class="brush: php; title: ; notranslate">
 &lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;&lt;title&gt;Upload Image&lt;/title&gt;&lt;/head&gt;
&lt;body&gt;
  @if(session(&#039;success&#039;))
    &lt;p style=&quot;color: green;&quot;&gt;{{ session(&#039;success&#039;) }}&lt;/p&gt;
  @endif

  &lt;form action=&quot;{{ route(&#039;images.upload&#039;) }}&quot; method=&quot;POST&quot; enctype=&quot;multipart/form-data&quot;&gt;
    @csrf
    &lt;input type=&quot;file&quot; name=&quot;file&quot; required&gt;
    &lt;button type=&quot;submit&quot;&gt;Upload&lt;/button&gt;
  &lt;/form&gt;
  
  &lt;a href=&quot;{{ route(&#039;images.list&#039;) }}&quot;&gt;View Gallery&lt;/a&gt;
&lt;/body&gt;
&lt;/html&gt;

</pre>
<p><strong>resources/views/display.blade.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;&lt;title&gt;Image Gallery&lt;/title&gt;&lt;/head&gt;
&lt;body&gt;
  &lt;h2&gt;Uploaded Images&lt;/h2&gt;
  &lt;a href=&quot;{{ url(&#039;/upload&#039;) }}&quot;&gt;Upload more&lt;/a&gt;
  &lt;div style=&quot;display: flex; flex-wrap: wrap; gap: 10px; margin-top: 15px;&quot;&gt;
    @foreach($imageData as $img)
      &lt;div style=&quot;border: 1px solid #ccc; padding: 5px;&quot;&gt;
        &lt;img src=&quot;{{ asset($img-&gt;path) }}&quot; alt=&quot;Image&quot; style=&quot;width:150px;height:auto;&quot;&gt;
      &lt;/div&gt;
    @endforeach
  &lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;

</pre>
<h3 class="step_code">Run Laravel App:</h3>
<pre class="brush: plain; title: ; notranslate">
php artisan serve
</pre>
<p></html></p>
<p><strong>I hope it will assist you…</strong></p>
<p>The post <a rel="nofollow" href="https://codeplaners.com/upload-store-image-in-laravel/">Upload &#038; Store Image in Laravel</a> appeared first on <a rel="nofollow" href="https://codeplaners.com">Codeplaners</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codeplaners.com/upload-store-image-in-laravel/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Update image in laravel without changing its URL</title>
		<link>https://codeplaners.com/update-image-in-laravel-without-changing-its-url/</link>
					<comments>https://codeplaners.com/update-image-in-laravel-without-changing-its-url/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Wed, 18 Jun 2025 06:31:55 +0000</pubDate>
				<category><![CDATA[Laravel]]></category>
		<category><![CDATA[Laravel 10]]></category>
		<category><![CDATA[Laravel 12]]></category>
		<category><![CDATA[Laravel 8]]></category>
		<category><![CDATA[Laravel 9]]></category>
		<guid isPermaLink="false">https://codeplaners.com/?p=1751</guid>

					<description><![CDATA[<p>Hi Dev, today in this article we will understand how to update image file without changing its URL. So, let’s follow few steps for update image file without changing its URL. Install Laravel 12 composer create-project laravel/laravel example-image Create Model php artisan create_images_table database/migrations/create_images_table.php &#60;?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\DB; return new &#8230; <a href="https://codeplaners.com/update-image-in-laravel-without-changing-its-url/" class="more-link">Continue reading<span class="screen-reader-text"> "Update image in laravel without changing its URL"</span></a></p>
<p>The post <a rel="nofollow" href="https://codeplaners.com/update-image-in-laravel-without-changing-its-url/">Update image in laravel without changing its URL</a> appeared first on <a rel="nofollow" href="https://codeplaners.com">Codeplaners</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Hi Dev,</p>
<p>today in this article we will understand how to update image file without changing its URL. So, let’s follow few steps for update image file without changing its URL.</p>
<h3 class="step_code"> Install Laravel 12</h3>
<pre class="brush: php; title: ; notranslate">
composer create-project laravel/laravel example-image
</pre>
<h3 class="step_code"> Create Model</h3>
<pre class="brush: php; title: ; notranslate">
php artisan create_images_table
</pre>
<p><strong>database/migrations/create_images_table.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
   
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
   
return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create(&#039;images&#039;, function (Blueprint $table) {
            $table-&gt;id();
            $table-&gt;string(&#039;title&#039;);
            $table-&gt;string(&#039;image&#039;);
            $table-&gt;timestamps();
        });
   
        DB::statement(&quot;ALTER TABLE images ADD file MEDIUMBLOB&quot;);
    }
   
    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists(&#039;images&#039;);
    }
};
</pre>
<p><strong>app/Models/Image.php</strong></p>
<pre class="brush: plain; title: ; notranslate">
&lt;?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;


class Image extends Model
{
    
    protected $fillable = &#x5B;
        &#039;title&#039;,
        &#039;image&#039;,
    ];

    
}
</pre>
<h3 class="step_code">Create Controller</h3>
<pre class="brush: php; title: ; notranslate">
php artisan make:controller ImageController
</pre>
<p><strong>app/Http/Controllers/ImageController.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

namespace App\Http\Controllers;
use App\Models\Image;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class ImageController extends Controller
{
   
  

    public function allpost()
    {
        $users = DB::table(&#039;images&#039;)-&gt;get();
        return view(&#039;allpost&#039;, compact(&#039;users&#039;));
    }

    public function addpost()
    {
        return view(&#039;addpost&#039;);
    }

    protected function poststore(Request $request)
{
    $request-&gt;validate(&#x5B;
        &#039;title&#039; =&gt; &#039;required&#039;,
        &#039;image&#039; =&gt; &#039;required|image|mimes:jpeg,png,jpg,gif|max:2048&#039;,
    ]);

    $imageName = null;
    if ($request-&gt;hasFile(&#039;image&#039;)) {
        $image = $request-&gt;file(&#039;image&#039;);
        $imageName = time() . &#039;_&#039; . $image-&gt;getClientOriginalName();
        $image-&gt;move(public_path(&#039;images&#039;), $imageName);
    }

    Image::create(&#x5B;
        &#039;title&#039; =&gt; $request-&gt;input(&#039;title&#039;),
        &#039;image&#039; =&gt; $imageName,
    ]);

    return redirect()-&gt;route(&#039;addpost&#039;)-&gt;with(&#039;success&#039;, &#039;Record inserted successfully&#039;);
}


    function editpost($id){

        $dosen = Post::findOrFail($id); 
         ($id);       
        return view(&#039;editpost&#039;, compact(&#039;dosen&#039;));  
    }
   
public function update(Request $request, $id)
{
    $post = Image::findOrFail($id);

    $post-&gt;title = $request-&gt;title;

    // If new image uploaded
    if ($request-&gt;hasFile(&#039;image&#039;)) {
        // Use existing image name or create one if somehow empty
        $filename = $post-&gt;image ?? &#039;post_&#039; . $post-&gt;id . &#039;.&#039; . $request-&gt;file(&#039;image&#039;)-&gt;getClientOriginalExtension();

        // Overwrite the image file (same name)
        $request-&gt;file(&#039;image&#039;)-&gt;move(public_path(&#039;images&#039;), $filename);

        // Make sure DB value stays same
        $post-&gt;image = $filename;
    }

    $post-&gt;save();

    return redirect(&#039;/allpost&#039;)-&gt;with(&#039;success&#039;, &#039;Item updated successfully&#039;);
}


   
}

</pre>
<h3 class="step_code">Create Add Routes</h3>
<p><strong>routes/web.php</strong></p>
<pre class="brush: php; title: ; notranslate">

Route::get(&#039;/allpost&#039;, &#x5B;App\Http\Controllers\ImageController::class, &#039;allpost&#039;])-&gt;name(&#039;allpost&#039;);
Route::get(&#039;/addpost&#039;, &#x5B;App\Http\Controllers\ImageController::class, &#039;addpost&#039;])-&gt;name(&#039;addpost&#039;);
Route::post(&#039;/poststore&#039;,&#x5B;App\Http\Controllers\ImageController::class, &#039;poststore&#039;])-&gt;name(&#039;poststore&#039;);
Route::get(&#039;/editpost/{id}&#039;, &#x5B;App\Http\Controllers\ImageController::class, &#039;editpost&#039;]);
Route::post(&#039;/editpost/{id}&#039;, &#x5B;App\Http\Controllers\ImageController::class, &#039;update&#039;]);

</pre>
<h3 class="step_code">Create Blade File</h3>
<p><strong>resources/views/addpost.blade.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;form class=&quot;needs-validation&quot; method=&quot;POST&quot; action=&quot;{{ route(&#039;poststore&#039;) }}&quot; enctype=&quot;multipart/form-data&quot; &gt;
@csrf
&lt;label for=&quot;title&quot;&gt;Title Name&lt;/label&gt;
&lt;input type=&quot;text&quot; class=&quot;form-control&quot; name=&quot;title&quot; placeholder=&quot;Title&quot; value=&quot;{{ old(&#039;title&#039;) }}&quot; required&gt;
&lt;input name=&quot;image&quot; type=&quot;file&quot; accept=&quot;image/*&quot; /&gt;
&lt;button type=&quot;submit&quot; name=&quot;submit&quot; class=&quot;btn btn-success&quot;&gt;Save&lt;/button&gt;
&lt;/form&gt;
</pre>
<p><strong>resources/views/editpost.blade.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;form class=&quot;needs-validation&quot; method=&quot;post&quot; action=&quot;{{ url(&#039;editpost&#039;) }}/{{ $dosen-&gt;id }}&quot; enctype=&quot;multipart/form-data&quot; &gt;
@csrf
&lt;label&gt;Post Name&lt;/label&gt;
&lt;input type=&quot;text&quot; class=&quot;form-control&quot; name=&quot;title&quot; value=&quot;{{ old(&#039;title&#039;, $dosen-&gt;title) }}&quot; placeholder=&quot;title&quot; required&gt;
&lt;label&gt;Image&lt;/label&gt;
 &lt;input name=&quot;image&quot; type=&quot;file&quot; class=&quot;form-control&quot; accept=&quot;image/*&quot;&gt;
{{-- Show current image if exists --}}
@if ($dosen-&gt;image)
&lt;div class=&quot;mt-2&quot;&gt;
&lt;img src=&quot;/images/{{ $dosen-&gt;image }}&quot; alt=&quot;Current Image&quot; height=&quot;100&quot;&gt;
&lt;/div&gt;
 @endif
&lt;button type=&quot;submit&quot; name=&quot;submit&quot; class=&quot;btn btn-success&quot;&gt;Update&lt;/button&gt;
&lt;/form&gt;
</pre>
<h3 class="step_code">Run Laravel App:</h3>
<pre class="brush: plain; title: ; notranslate">
php artisan serve
</pre>
<p><strong>I hope it will assist you…</strong></p>
<p>The post <a rel="nofollow" href="https://codeplaners.com/update-image-in-laravel-without-changing-its-url/">Update image in laravel without changing its URL</a> appeared first on <a rel="nofollow" href="https://codeplaners.com">Codeplaners</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codeplaners.com/update-image-in-laravel-without-changing-its-url/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<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>
		<item>
		<title>Select Option Subcategory By Category In PHP</title>
		<link>https://codeplaners.com/select-option-subcategory-by-category-in-php/</link>
					<comments>https://codeplaners.com/select-option-subcategory-by-category-in-php/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sun, 08 Dec 2024 05:09:28 +0000</pubDate>
				<category><![CDATA[Laravel]]></category>
		<category><![CDATA[Laravel 8]]></category>
		<category><![CDATA[Laravel 9]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[category by Subcategory]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[PHP 8]]></category>
		<guid isPermaLink="false">https://codeplaners.com/?p=1438</guid>

					<description><![CDATA[<p>This post was last updated on January 1st, 2025 at 06:38 amHi Dev, Today, i we will show you select option subcategory by category in php. This article will give you simple example of select option subcategory by category in php. you will select option subcategory by category in php. In this article, we will &#8230; <a href="https://codeplaners.com/select-option-subcategory-by-category-in-php/" class="more-link">Continue reading<span class="screen-reader-text"> "Select Option Subcategory By Category In PHP"</span></a></p>
<p>The post <a rel="nofollow" href="https://codeplaners.com/select-option-subcategory-by-category-in-php/">Select Option Subcategory By Category In PHP</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, i we will show you select option subcategory by category in php. This article will give you simple example of select option subcategory by category in php. you will select option subcategory by category in php. In this article, we will implement a select option subcategory by category in php. </p>
<p>So let’s follow few step to create example of select option subcategory by category in php.</p>
<h3 class="step_code">database.php</h3>
<pre class="brush: php; title: ; notranslate">
&lt;?php
	$servername = &quot;localhost&quot;;
	$username = &quot;root&quot;;
	$password = &quot;&quot;;
	$db=&quot;example&quot;;
	$conn = mysqli_connect($servername, $username, $password,$db);
?&gt;
</pre>
<h3 class="step_code">index.php</h3>
<pre class="brush: php; title: ; notranslate">
&lt;?php
include 'database.php';
$result = mysqli_query($conn,&quot;SELECT * FROM category&quot;);
?&gt;
&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
  &lt;title&gt;Select Option Subcategory By Category In PHP - Codeplaners&lt;/title&gt;
  &lt;meta charset=&quot;utf-8&quot;&gt;
  &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;
  &lt;link rel=&quot;stylesheet&quot; href=&quot;https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css&quot;&gt;
  &lt;script src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js&quot;&gt;&lt;/script&gt;
  &lt;script src=&quot;https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js&quot;&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div class=&quot;container&quot;&gt;
	&lt;form&gt;
		&lt;div class=&quot;form-group&quot;&gt;
		  &lt;label &gt;Category&lt;/label&gt;
		  &lt;select class=&quot;form-control&quot; id=&quot;category&quot;&gt;
		  &lt;option value=&quot;&quot;&gt;Select Category&lt;/option&gt;
		    &lt;?php
			while($row = mysqli_fetch_array($result)) {
			?&gt;
				&lt;option value=&quot;&lt;?php echo $row&#x5B;&quot;id&quot;];?&gt;&quot;&gt;&lt;?php echo $row&#x5B;&quot;category_name&quot;];?&gt;&lt;/option&gt;
			&lt;?php
			}
			?&gt;
			
		  &lt;/select&gt;
		&lt;/div&gt;
		&lt;div class=&quot;form-group&quot;&gt;
		  &lt;label for=&quot;sel1&quot;&gt;Sub Category&lt;/label&gt;
		  &lt;select class=&quot;form-control&quot; id=&quot;sub_category&quot;&gt;
			
		  &lt;/select&gt;
		&lt;/div&gt;
	&lt;/form&gt;
&lt;/div&gt;
&lt;script&gt;
$(document).ready(function() {
	$('#category').on('change', function() {
			var category_id = this.value;
			$.ajax({
				url: &quot;get_subcat.php&quot;,
				type: &quot;POST&quot;,
				data: {
					category_id: category_id
				},
				cache: false,
				success: function(dataResult){
					$(&quot;#sub_category&quot;).html(dataResult);
				}
			});
		
		
	});
});
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<h3 class="step_code">get_subcat.php</h3>
<pre class="brush: php; title: ; notranslate">
&lt;?php
	include 'database.php';
	$category_id=$_POST&#x5B;&quot;category_id&quot;];
	$result = mysqli_query($conn,&quot;SELECT * FROM category where category_id=$category_id&quot;);
?&gt;
&lt;option value=&quot;&quot;&gt;Select SubCategory&lt;/option&gt;
&lt;?php
while($row = mysqli_fetch_array($result)) {
?&gt;
	&lt;option value=&quot;&lt;?php echo $row&#x5B;&quot;id&quot;];?&gt;&quot;&gt;&lt;?php echo $row&#x5B;&quot;subcategory_name&quot;];?&gt;&lt;/option&gt;
&lt;?php
}
?&gt;
</pre>
<p>I hope it will assist you…</p>
<p>The post <a rel="nofollow" href="https://codeplaners.com/select-option-subcategory-by-category-in-php/">Select Option Subcategory By Category In PHP</a> appeared first on <a rel="nofollow" href="https://codeplaners.com">Codeplaners</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codeplaners.com/select-option-subcategory-by-category-in-php/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Set Indian Timezone in Laravel</title>
		<link>https://codeplaners.com/set-indian-timezone-in-laravel/</link>
					<comments>https://codeplaners.com/set-indian-timezone-in-laravel/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Fri, 06 Dec 2024 15:53:58 +0000</pubDate>
				<category><![CDATA[Laravel]]></category>
		<category><![CDATA[Laravel 10]]></category>
		<category><![CDATA[Laravel 8]]></category>
		<category><![CDATA[Laravel 9]]></category>
		<category><![CDATA[Laravel 11]]></category>
		<category><![CDATA[timezone]]></category>
		<guid isPermaLink="false">https://codeplaners.com/?p=1740</guid>

					<description><![CDATA[<p>Hi Dev, In this post, I will show you how to set Indian time zone in Laravel By default, Laravel uses UTC time zone. We can set it for India or any other country. Here we are showing you how to set Indian time zone. Let&#8217;s set the Indian time zone to `Asia/Kolkata`. We can &#8230; <a href="https://codeplaners.com/set-indian-timezone-in-laravel/" class="more-link">Continue reading<span class="screen-reader-text"> "Set Indian Timezone in Laravel"</span></a></p>
<p>The post <a rel="nofollow" href="https://codeplaners.com/set-indian-timezone-in-laravel/">Set Indian Timezone in Laravel</a> appeared first on <a rel="nofollow" href="https://codeplaners.com">Codeplaners</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Hi Dev,</p>
<p>In this post, I will show you how to set Indian time zone in Laravel</p>
<p>By default, Laravel uses UTC time zone. We can set it for India or any other country. Here we are showing you how to set Indian time zone. Let&#8217;s set the Indian time zone to `Asia/Kolkata`. We can apply this time zone in two ways:</p>
<h3 class="step_code">Step 1: Update timezone .env file</h3>
<p>.env</p>
<pre class="brush: php; title: ; notranslate">
APP_TIMEZONE=&quot;Asia/Kolkata&quot;
</pre>
<h3 class="step_code">Step 2: Update timezone config file</h3>
<pre class="brush: php; title: ; notranslate">
'timezone' =&gt; 'Asia/Kolkata',
</pre>
<p>You can find out if the time zone is set correctly by following route code</p>
<pre class="brush: php; title: ; notranslate">
Route::get('/', function () {
    dd(now());
});
</pre>
<p><strong>I hope it will assist you…</strong></p>
<p>The post <a rel="nofollow" href="https://codeplaners.com/set-indian-timezone-in-laravel/">Set Indian Timezone in Laravel</a> appeared first on <a rel="nofollow" href="https://codeplaners.com">Codeplaners</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codeplaners.com/set-indian-timezone-in-laravel/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Add DomPDF Add QR Code to PDF in Laravel</title>
		<link>https://codeplaners.com/how-to-add-dompdf-add-qr-code-to-pdf-in-laravel/</link>
					<comments>https://codeplaners.com/how-to-add-dompdf-add-qr-code-to-pdf-in-laravel/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sat, 09 Nov 2024 03:43:45 +0000</pubDate>
				<category><![CDATA[Laravel]]></category>
		<category><![CDATA[Laravel 10]]></category>
		<category><![CDATA[Laravel 8]]></category>
		<category><![CDATA[Laravel 9]]></category>
		<category><![CDATA[DomPDF]]></category>
		<category><![CDATA[DomPDF in laravel]]></category>
		<guid isPermaLink="false">https://codeplaners.com/?p=1653</guid>

					<description><![CDATA[<p>This post was last updated on January 1st, 2025 at 06:40 amHi dev, Today, i show you how to add DomPDF add QR Code to PDF in laravel. In this article will tell you how to add DomPDF add QR Code to PDF in laravel. you will how to add DomPDF add QR Code to &#8230; <a href="https://codeplaners.com/how-to-add-dompdf-add-qr-code-to-pdf-in-laravel/" class="more-link">Continue reading<span class="screen-reader-text"> "How to Add DomPDF Add QR Code to PDF in Laravel"</span></a></p>
<p>The post <a rel="nofollow" href="https://codeplaners.com/how-to-add-dompdf-add-qr-code-to-pdf-in-laravel/">How to Add DomPDF Add QR Code to PDF in Laravel</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:40 am</p><p>Hi dev,</p>
<p>Today, i show you how to add DomPDF add QR Code to PDF in laravel. In this article will tell you how to add DomPDF add QR Code to PDF in laravel. you will how to add DomPDF add QR Code to PDF in laravel. I will show in this example how to integrate QR code PDF. For this we will use two composer packages.</p>
<p>You can also use this example with Laravel 6, Laravel 7, Laravel 8, Laravel 9 and Laravel 10 versions.</p>
<p>So, let’s follow few steps to create example of how to add DomPDF add QR Code to PDF in laravel.</p>
<h3 class="step_code">Step 1: Install Laravel App</h3>
<pre class="brush: php; title: ; notranslate">
composer create-project laravel/laravel example-qrcode
</pre>
<h3 class="step_code">Step 2: Install DomPDF Package</h3>
<pre class="brush: php; title: ; notranslate">
composer require barryvdh/laravel-dompdf
</pre>
<pre class="brush: php; title: ; notranslate">
composer require simplesoftwareio/simple-qrcode
</pre>
<h3 class="step_code">Step 3: Create Controller</h3>
<pre class="brush: php; title: ; notranslate">
php artisan make:controller PDFController
</pre>
<p><strong>app/Http/Controllers/PDFController.php</strong></p>
<pre class="brush: php; title: ; notranslate">
namespace App\Http\Controllers;
    
use Illuminate\Http\Request;
use PDF;
use SimpleSoftwareIO\QrCode\Facades\QrCode;
    
class PDFController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function generatePDF()
    {
        $qrcode = base64_encode(QrCode::format('svg')-&gt;size(200)-&gt;errorCorrection('H')-&gt;generate('string'));
        $data = &#x5B;
            'title' =&gt; 'Welcome to Codeplaners.com',
            'qrcode' =&gt; $qrcode
        ]; 
              
        $pdf = PDF::loadView('myPDF', $data);
  
        return $pdf-&gt;download('codeplaners.pdf');
    }
}
</pre>
<h3 class="step_code">Step 4: Add Route</h3>
<p><strong>routes/web.php</strong></p>
<pre class="brush: php; title: ; notranslate">
use Illuminate\Support\Facades\Route;
  
use App\Http\Controllers\PDFController;

  
Route::get('generate-pdf', &#x5B;PDFController::class, 'generatePDF']);
</pre>
<h3 class="step_code">Step 5: Create View File</h3>
<p><strong>resources/views/myPDF.blade.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;How to Add DomPDF Add QR Code to PDF in Laravel - codeplaners.com&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
  
&lt;div&gt;
    &lt;h1&gt;How to Add DomPDF Add QR Code to PDF in Laravel&lt;/h1&gt;
      
    &lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
    tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,

Ezoic
    quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
    consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
    cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
    proident, sunt in culpa qui officia deserunt mollit anim id est laborum.&lt;/p&gt;
  
    &lt;img src=&quot;data:image/png;base64,{{ $qrcode }}&quot; alt=&quot;&quot;&gt;
    
&lt;/div&gt;
    
&lt;/body&gt;
&lt;/html&gt;	
</pre>
<h3 class="step_code">Run Laravel App:</h3>
<p><strong>routes/web.php</strong></p>
<pre class="brush: php; title: ; notranslate">
php artisan serve
</pre>
<pre class="brush: php; title: ; notranslate">
http://localhost:8000/generate-pdf
</pre>
<p><strong>I hope it will assist you…</strong></p>
<p>The post <a rel="nofollow" href="https://codeplaners.com/how-to-add-dompdf-add-qr-code-to-pdf-in-laravel/">How to Add DomPDF Add QR Code to PDF in Laravel</a> appeared first on <a rel="nofollow" href="https://codeplaners.com">Codeplaners</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codeplaners.com/how-to-add-dompdf-add-qr-code-to-pdf-in-laravel/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
