<?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>separated by commas: ``` Laravel 11 Archives - Artificial Intelligence</title>
	<atom:link href="https://www.aiuniverse.xyz/tag/separated-by-commas-laravel-11/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.aiuniverse.xyz/tag/separated-by-commas-laravel-11/</link>
	<description>Exploring the universe of Intelligence</description>
	<lastBuildDate>Mon, 05 Aug 2024 12:35:38 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>
	<item>
		<title>A Comprehensive Guide to CRUD Operations in Laravel 11</title>
		<link>https://www.aiuniverse.xyz/a-comprehensive-guide-to-crud-operations-in-laravel-11/</link>
					<comments>https://www.aiuniverse.xyz/a-comprehensive-guide-to-crud-operations-in-laravel-11/#respond</comments>
		
		<dc:creator><![CDATA[Maruti Kr.]]></dc:creator>
		<pubDate>Mon, 05 Aug 2024 12:27:22 +0000</pubDate>
				<category><![CDATA[laravel]]></category>
		<category><![CDATA[CRUD functionality Laravel 11]]></category>
		<category><![CDATA[CRUD operations]]></category>
		<category><![CDATA[Laravel 11 application]]></category>
		<category><![CDATA[Laravel 11 blog post]]></category>
		<category><![CDATA[Laravel 11 CRUD example]]></category>
		<category><![CDATA[Laravel 11 development]]></category>
		<category><![CDATA[Laravel 11 tutorial]]></category>
		<category><![CDATA[Laravel CRUD guide]]></category>
		<category><![CDATA[Laravel CRUD operations]]></category>
		<category><![CDATA[separated by commas: ``` Laravel 11]]></category>
		<category><![CDATA[Sure! Here are 10 keywords related to Laravel 11 CRUD operations]]></category>
		<guid isPermaLink="false">https://www.aiuniverse.xyz/?p=19005</guid>

					<description><![CDATA[<p>Hi Everyone, In this post, you will learn how to perform CRUD operations in Laravel 11. We&#8217;ll guide you through building a CRUD application from scratch. This blog post is perfect for beginners looking to understand the basics of CRUD operations in Laravel 11. In this example, we&#8217;ll create a product CRUD application using Laravel <a class="read-more-link" href="https://www.aiuniverse.xyz/a-comprehensive-guide-to-crud-operations-in-laravel-11/">Read More</a></p>
<p>The post <a href="https://www.aiuniverse.xyz/a-comprehensive-guide-to-crud-operations-in-laravel-11/">A Comprehensive Guide to CRUD Operations in Laravel 11</a> appeared first on <a href="https://www.aiuniverse.xyz">Artificial Intelligence</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="1024" height="438" src="https://www.aiuniverse.xyz/wp-content/uploads/2024/08/image-3-1024x438.png" alt="" class="wp-image-19006" srcset="https://www.aiuniverse.xyz/wp-content/uploads/2024/08/image-3-1024x438.png 1024w, https://www.aiuniverse.xyz/wp-content/uploads/2024/08/image-3-300x128.png 300w, https://www.aiuniverse.xyz/wp-content/uploads/2024/08/image-3-768x328.png 768w, https://www.aiuniverse.xyz/wp-content/uploads/2024/08/image-3.png 1217w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>Hi Everyone,</p>



<p>In this post, you will learn how to perform CRUD operations in Laravel 11. We&#8217;ll guide you through building a CRUD application from scratch. This blog post is perfect for beginners looking to understand the basics of CRUD operations in Laravel 11.</p>



<p>In this example, we&#8217;ll create a product CRUD application using Laravel 11. We&#8217;ll start by creating a products table with Laravel migration, followed by setting up routes, controllers, views, and models for the product module. To design the user interface, we&#8217;ll use Bootstrap 5.</p>



<p>So, let&#8217;s get started with creating a CRUD operation in Laravel 11.</p>



<h3 class="wp-block-heading">Step 1: Install Laravel 11</h3>



<p>First, we&#8217;ll install the Laravel 11 application. If you already have a project set up, you can skip this step.</p>



<pre class="wp-block-code"><code>composer create-project laravel/laravel example-app</code></pre>



<h3 class="wp-block-heading">Step 2: Database Configuration</h3>



<p>Open the <code><strong>.env</strong></code> file and update the database connection details as shown below:</p>



<pre class="wp-block-code"><code>DB_CONNECTION=mysql
 DB_HOST=127.0.0.1
 DB_PORT=3306
 DB_DATABASE=laravel_crud_db
 DB_USERNAME=root
 DB_PASSWORD=</code></pre>



<h3 class="wp-block-heading">Step 3: Create Migration</h3>



<p>Create a <code>categories</code> table in your MySQL database using the Laravel Artisan command as follows:</p>



<pre class="wp-block-code"><code>php artisan make:migration create_categories_table --create=categories</code></pre>



<p>After running this command, a migration file will be generated at <code><strong>database/migrations/2024_00_00_000000_create_categories_table.php</strong></code>. You need to add the following code to this migration file to define the structure of the <code>categories</code> table.</p>



<pre class="wp-block-code"><code>&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('categories', function (Blueprint $table) {
            $table-&gt;id();
            $table-&gt;string('name');
            $table-&gt;string('description');
            $table-&gt;boolean('status')-&gt;default(1)-&gt;comment('1=visible,0=hidden');
            $table-&gt;timestamps();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('categories');
    }
};</code></pre>



<p>Now, let&#8217;s migrate our database using the following command:</p>



<pre class="wp-block-code"><code>php artisan migrate</code></pre>



<p><strong>Step 4: Create a Model Using the Following Command:</strong></p>



<pre class="wp-block-code"><code>php artisan make:model Category</code></pre>



<p>After running this command, you will find the <code><strong>Category.php</strong></code> file in the <code><strong>app/Models</strong></code> directory. Open this file and insert the following code:</p>



<pre class="wp-block-code"><code>&lt;?php

namespace  App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Category extends Model
{
    use HasFactory;

    protected $table = 'categories';

    protected $fillable = &#91;
        'name',
        'description',
        'status'
    ];
}</code></pre>



<p><strong>Step 5:</strong> To create a new controller named <code>CategoryController</code>, run the following command:</p>



<pre class="wp-block-code"><code>php artisan make:controller CategoryController --resource</code></pre>



<p>After the controller is created, navigate to the <code>CategoryController.php</code> file located at <code><strong>app/Http/Controllers/CategoryController.php</strong></code> and replace its contents with the code provided below:</p>



<pre class="wp-block-code"><code>&lt;?php

namespace App\Http\Controllers;

use App\Models\Category;
use Illuminate\Http\Request;

class CategoryController extends Controller
{
    /**
     * Display a listing of the resource.
     */
    public function index()
    {
        $categories = Category::paginate(10);
        return view('category.index', &#91;
            'categories' =&gt; $categories
        ]);
    }

    /**
     * Show the form for creating a new resource.
     */
    public function create()
    {
        return view('category.create');
    }

    /**
     * Store a newly created resource in storage.
     */
    public function store(Request $request)
    {
        $request-&gt;validate(&#91;
            'name' =&gt; 'required|string|max:255',
            'description' =&gt; 'required|string|max:255',
            'status' =&gt; 'nullable',
        ]);

        Category::create(&#91;
            'name' =&gt; $request-&gt;name,
            'description' =&gt; $request-&gt;description,
            'status' =&gt; $request-&gt;status == true ? 1:0,
        ]);

        return redirect('/category')-&gt;with('status','Category Created Successfully');
    }

    /**
     * Display the specified resource.
     */
    public function show(Category $category)
    {
        return view('category.show', compact('category'));
    }

    /**
     * Show the form for editing the specified resource.
     */
    public function edit(Category $category)
    {
        return view('category.edit', compact('category'));
    }

    /**
     * Update the specified resource in storage.
     */
    public function update(Request $request, Category $category)
    {
        $request-&gt;validate(&#91;
            'name' =&gt; 'required|string|max:255',
            'description' =&gt; 'required|string|max:255',
            'status' =&gt; 'nullable',
        ]);

        $category-&gt;update(&#91;
            'name' =&gt; $request-&gt;name,
            'description' =&gt; $request-&gt;description,
            'status' =&gt; $request-&gt;status == true ? 1:0,
        ]);

        return redirect('/category')-&gt;with('status','Category Updated Successfully');
    }

    /**
     * Remove the specified resource from storage.
     */
    public function destroy(Category $category)
    {
        $category-&gt;delete();
        return redirect('/category')-&gt;with('status','Category Deleted Successfully');
    }
}</code></pre>



<h3 class="wp-block-heading">Step 6: Add Resource Route</h3>



<p>Open the <code><strong>routes/web.php</strong></code> file and add the following route to handle resourceful actions for the <code>CategoryController</code>:</p>



<pre class="wp-block-code"><code>&lt;?php

use App\Http\Controllers\ProfileController;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\CategoryController;



Route::get('/', function () {
    return view('welcome');
});

Route::get('/dashboard', function () {
    return view('dashboard');
})-&gt;middleware(&#91;'auth', 'verified'])-&gt;name('dashboard');

Route::middleware('auth')-&gt;group(function () {
    Route::get('/profile', &#91;ProfileController::class, 'edit'])-&gt;name('profile.edit');
    Route::patch('/profile', &#91;ProfileController::class, 'update'])-&gt;name('profile.update');
    Route::delete('/profile', &#91;ProfileController::class, 'destroy'])-&gt;name('profile.destroy');    
    Route::resource('/category', CategoryController::class);
});

require __DIR__.'/auth.php';
</code></pre>



<h3 class="wp-block-heading">Step 7: Create Blade View Files</h3>



<p>Navigate to the <strong><code>resources/views/</code> directory</strong>. Inside this directory, create a folder named <code>category</code>. Within the <code>category</code> folder, create the following Blade view files:</p>



<ol class="wp-block-list">
<li><code>index.blade.php</code></li>



<li><code>create.blade.php</code></li>



<li><code>edit.blade.php</code></li>



<li><code>show.blade.php</code></li>



<li><code>layout.blade.php</code></li>
</ol>



<p>Here’s how to create these files and add the necessary code:</p>



<ol class="wp-block-list">
<li><strong><code>resources/views/category/layout.blade.php</code></strong></li>
</ol>



<pre class="wp-block-code"><code>&lt;!doctype html&gt;
&lt;html lang="{{ str_replace('_', '-',  app()-&gt;getLocale()) }}"&gt;
&lt;head&gt;
    &lt;meta charset="utf-8"&gt;
    &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;

    &lt;!-- CSRF Token --&gt;
    &lt;meta name="csrf-token" content="{{ csrf_token() }}"&gt;

    &lt;title&gt;Laravel 11 CRUD  Application&lt;/title&gt;

    &lt;!-- Fonts --&gt;
    &lt;link rel="dns-prefetch" href="//fonts.gstatic.com"&gt;
    &lt;link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet"&gt;

    &lt;!-- Styles --&gt;
    &lt;link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ" crossorigin="anonymous"&gt;

&lt;/head&gt;
&lt;body&gt;

    &lt;div class="container"&gt;
        @yield('content')
    &lt;/div&gt;

    &lt;script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ENjdO4Dr2bkBIFxQpeoTz1HIcje39Wm4jDKdf19U8gI4ddQ3GYNS7NTKfAdVQSZe" crossorigin="anonymous"&gt;&lt;/script&gt;

&lt;/body&gt;
&lt;/html&gt;</code></pre>



<ol class="wp-block-list" start="2">
<li><strong><code>resources/views/category/index.blade.php</code></strong></li>
</ol>



<pre class="wp-block-code"><code>@extends('category.layout')

@section('content')

    &lt;div class="container"&gt;
        &lt;div class="row"&gt;
            &lt;div class="col-md-12"&gt;

                @session('status')
                &lt;div class="alert alert-success"&gt;
                    {{ session('status') }}
                &lt;/div&gt;
                @endsession

                &lt;div class="card"&gt;
                    &lt;div class="card-header"&gt;
                        &lt;h4&gt;Categories List
                            &lt;a href="{{ url('category/create') }}" class="btn btn-primary float-end"&gt;Add Category&lt;/a&gt;
                        &lt;/h4&gt;
                    &lt;/div&gt;
                    &lt;div class="card-body"&gt;
                        &lt;table class="table table-stiped table-bordered"&gt;
                            &lt;thead&gt;
                                &lt;tr&gt;
                                    &lt;th&gt;Id&lt;/th&gt;
                                    &lt;th&gt;Name&lt;/th&gt;
                                    &lt;th&gt;Description&lt;/th&gt;
                                    &lt;th&gt;Status&lt;/th&gt;
                                    &lt;th&gt;Action&lt;/th&gt;
                                &lt;/tr&gt;
                            &lt;/thead&gt;
                            &lt;tbody&gt;
                                @foreach ($categories as $category)
                                &lt;tr&gt;
                                    &lt;td&gt;{{ $category-&gt;id }}&lt;/td&gt;
                                    &lt;td&gt;{{ $category-&gt;name }}&lt;/td&gt;
                                    &lt;td&gt;{{ $category-&gt;description }}&lt;/td&gt;
                                    &lt;td&gt;{{ $category-&gt;status == 1 ? 'Visible':'Hidden' }}&lt;/td&gt;
                                    &lt;td&gt;
                                        &lt;a href="{{ route('category.edit', $category-&gt;id) }}" class="btn btn-success"&gt;Edit&lt;/a&gt;
                                        &lt;a href="{{ route('category.show', $category-&gt;id) }}" class="btn btn-info"&gt;Show&lt;/a&gt;


                                        &lt;form action="{{ route('category.destroy', $category-&gt;id) }}" method="POST" class="d-inline"&gt;
                                            @csrf
                                            @method('DELETE')
                                            &lt;button type="submit" class="btn btn-danger"&gt;Delete&lt;/button&gt;
                                        &lt;/form&gt;
                                    &lt;/td&gt;
                                &lt;/tr&gt;
                                @endforeach
                            &lt;/tbody&gt;
                        &lt;/table&gt;

                        {{ $categories-&gt;links() }}</code></pre>



<ol class="wp-block-list" start="3">
<li><strong><code>resources/views/category/create.blade.php</code></strong></li>
</ol>



<pre class="wp-block-code"><code>@extends('category.layout')

@section('content')

    &lt;div class="container"&gt;
        &lt;div class="row"&gt;
            &lt;div class="col-md-12"&gt;
                &lt;div class="card"&gt;
                    &lt;div class="card-header"&gt;
                        &lt;h4&gt;Create Category
                            &lt;a href="{{ url('category') }}" class="btn btn-danger float-end"&gt;Back&lt;/a&gt;
                        &lt;/h4&gt;
                    &lt;/div&gt;
                    &lt;div class="card-body"&gt;
                        &lt;form action="{{ route('category.store') }}" method="POST"&gt;
                            @csrf

                            &lt;div class="mb-3"&gt;
                                &lt;label&gt;Name&lt;/label&gt;
                                &lt;input type="text" name="name" class="form-control" /&gt;
                                @error('name') &lt;span class="text-danger"&gt;{{ $message }}&lt;/span&gt; @enderror
                            &lt;/div&gt;
                            &lt;div class="mb-3"&gt;
                                &lt;label&gt;Description&lt;/label&gt;
                                &lt;textarea name="description" rows="3" class="form-control"&gt;&lt;/textarea&gt;
                                @error('description') &lt;span class="text-danger"&gt;{{ $message }}&lt;/span&gt; @enderror
                            &lt;/div&gt;
                            &lt;div class="mb-3"&gt;
                                &lt;label&gt;Status&lt;/label&gt;
                                &lt;br/&gt;
                                &lt;input type="checkbox" name="status" checked style="width:30px;height:30px;" /&gt; Checked=visible, unchecked=hidden
                                @error('status') &lt;span class="text-danger"&gt;{{ $message }}&lt;/span&gt; @enderror
                            &lt;/div&gt;
                            &lt;div class="mb-3"&gt;
                                &lt;button type="submit" class="btn btn-primary"&gt;Save&lt;/button&gt;
                            &lt;/div&gt;

                        &lt;/form&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;

@endsection</code></pre>



<ol class="wp-block-list" start="4">
<li><strong><code>resources/views/category/edit.blade.php</code></strong></li>
</ol>



<pre class="wp-block-code"><code>@extends('category.layout')

@section('content')

    &lt;div class="container"&gt;
        &lt;div class="row"&gt;
            &lt;div class="col-md-12"&gt;
                &lt;div class="card"&gt;
                    &lt;div class="card-header"&gt;
                        &lt;h4&gt;Edit Category
                            &lt;a href="{{ url('category') }}" class="btn btn-danger float-end"&gt;Back&lt;/a&gt;
                        &lt;/h4&gt;
                    &lt;/div&gt;
                    &lt;div class="card-body"&gt;
                        &lt;form action="{{ route('category.update', $category-&gt;id) }}" method="POST"&gt;
                            @csrf
                            @method('PUT')

                            &lt;div class="mb-3"&gt;
                                &lt;label&gt;Name&lt;/label&gt;
                                &lt;input type="text" name="name" class="form-control" value="{{ $category-&gt;name }}" /&gt;
                                @error('name') &lt;span class="text-danger"&gt;{{ $message }}&lt;/span&gt; @enderror
                            &lt;/div&gt;
                            &lt;div class="mb-3"&gt;
                                &lt;label&gt;Description&lt;/label&gt;
                                &lt;textarea name="description" rows="3" class="form-control"&gt;{!! $category-&gt;description !!}&lt;/textarea&gt;
                                @error('description') &lt;span class="text-danger"&gt;{{ $message }}&lt;/span&gt; @enderror
                            &lt;/div&gt;
                            &lt;div class="mb-3"&gt;
                                &lt;label&gt;Status&lt;/label&gt;
                                &lt;br/&gt;
                                &lt;input type="checkbox" name="status" {{ $category-&gt;status == 1 ? 'checked':'' }} style="width:30px;height:30px;" /&gt; Checked=visible, unchecked=hidden
                                @error('status') &lt;span class="text-danger"&gt;{{ $message }}&lt;/span&gt; @enderror
                            &lt;/div&gt;
                            &lt;div class="mb-3"&gt;
                                &lt;button type="submit" class="btn btn-primary"&gt;Update&lt;/button&gt;
                            &lt;/div&gt;

                        &lt;/form&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;

@endsection</code></pre>



<ol class="wp-block-list" start="5">
<li><strong><code>resources/views/category/show.blade.php</code></strong></li>
</ol>



<pre class="wp-block-code"><code>@extends('category.layout')

@section('content')

    &lt;div class="container"&gt;
        &lt;div class="row"&gt;
            &lt;div class="col-md-12"&gt;
                &lt;div class="card"&gt;
                    &lt;div class="card-header"&gt;
                        &lt;h4&gt;Show Category Detail
                            &lt;a href="{{ url('category') }}" class="btn btn-danger float-end"&gt;Back&lt;/a&gt;
                        &lt;/h4&gt;
                    &lt;/div&gt;
                    &lt;div class="card-body"&gt;
                        &lt;div class="mb-3"&gt;
                            &lt;label&gt;Name&lt;/label&gt;
                            &lt;p&gt;
                                {{ $category-&gt;name }}
                            &lt;/p&gt;
                        &lt;/div&gt;
                        &lt;div class="mb-3"&gt;
                            &lt;label&gt;Description&lt;/label&gt;
                            &lt;p&gt;
                                {!! $category-&gt;description !!}
                            &lt;/p&gt;
                        &lt;/div&gt;
                        &lt;div class="mb-3"&gt;
                            &lt;label&gt;Status&lt;/label&gt;
                            &lt;br/&gt;
                            &lt;p&gt;
                                {{ $category-&gt;status == 1 ? 'checked':'' }}
                            &lt;/p&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;

@endsection</code></pre>



<p><strong>Step 8: Add the Pagination class to <code>app/Providers/AppServiceProvider.php</code>. If it is already included, you can skip this step.</strong></p>



<pre class="wp-block-code"><code>&lt;?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     */
    public function register(): void
    {
        //
    }

    /**
     * Bootstrap any application services.
     */
    public function boot(): void
    {
        //
    }
}</code></pre>



<p><strong>Step 9:</strong> Serve the application by running the following command:</p>



<pre class="wp-block-code"><code>php artisan serve</code></pre>



<p>Open your web browser, enter the provided URL, and check the app&#8217;s output:</p>



<pre class="wp-block-code"><code>http:&#47;&#47;127.0.0.1:8000/category</code></pre>



<p>That&#8217;s the complete information. I trust this will be helpful to you.</p>
<p>The post <a href="https://www.aiuniverse.xyz/a-comprehensive-guide-to-crud-operations-in-laravel-11/">A Comprehensive Guide to CRUD Operations in Laravel 11</a> appeared first on <a href="https://www.aiuniverse.xyz">Artificial Intelligence</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.aiuniverse.xyz/a-comprehensive-guide-to-crud-operations-in-laravel-11/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
