Laravel 6 CRUD Tutorial With Example from scratch

Today, We want to share with you Laravel 6 CRUD Tutorial With Example.In this post we will show you Laravel 6 CRUD (Create Read Update Delete) Example from scratch, hear for Laravel 6 CRUD Application for Starter we will give you demo and example for implement.In this post, we will learn about Laravel 6 – simple crud operation with example with an demo.

Laravel 6 CRUD Tutorial With Example

There are the Following The simple About Laravel 6 CRUD Tutorial With Example Full Information With Example and source code.

As I will cover this Post with live Working example to develop Laravel 6 Crud Example Tutorial, so the some major files and Directory structures for Laravel 6 CRUD (Create Read Update Delete) From Scratch is following below.

Latest Laravel 6 Features & New Updates

There are the following the list of Laravel 6 Release New Features and Upgrade

  • Declaration Of Primary Key Type
  • Update on Eloquent BelongsTo::update Method
  • Added cursor method in Eloquent
  • Carbon 2.0 Supported
  • String & Array Helpers Moved To Package

Step 1 : Install Laravel 6

fresh Laravel 6 version application

composer create-project --prefer-dist laravel/laravel movies

Step 2: Database Configuration

.env : Laravel 6 CRUD Tutorial With Example from scratch

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=movies_list
DB_USERNAME=root
[email protected]

Step 3: Create Migration

Laravel 6 php artisan command

php artisan make:migration create_movies_table --create=movies

“database/migrations”

<?php
 
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
  
class CreateMoviesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('movies', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->text('detail');
            $table->timestamps();
        });
    }
  
    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('movies');
    }
}

run this migration

php artisan migrate

Step 4: Add Resource Route

routes/web.php

Route::resource('movies','MovieController');

Step 5: Add Controller and Model

create new controller as MovieController

php artisan make:controller MovieController --resource --model=Movie

app/Http/Controllers/MovieController.php

<?php
  
namespace App\Http\Controllers;
  
use App\Movie;
use Illuminate\Http\Request;
  
class MovieController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $movies = Movie::latest()->paginate(5);
  
        return view('movies.index',compact('movies'))
            ->with('i', (request()->input('page', 1) - 1) * 5);
    }
   
    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('movies.create');
    }
  
    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $request->validate([
            'name' => 'required',
            'detail' => 'required',
        ]);
  
        Movie::create($request->all());
   
        return redirect()->route('movies.index')
                        ->with('success','Movie created successfully.');
    }
   
    /**
     * Display the specified resource.
     *
     * @param  \App\Movie  $movie
     * @return \Illuminate\Http\Response
     */
    public function show(Movie $movie)
    {
        return view('movies.show',compact('movie'));
    }
   
    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\Movie  $movie
     * @return \Illuminate\Http\Response
     */
    public function edit(Movie $movie)
    {
        return view('movies.edit',compact('movie'));
    }
  
    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Movie  $movie
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, Movie $movie)
    {
        $request->validate([
            'name' => 'required',
            'detail' => 'required',
        ]);
  
        $movie->update($request->all());
  
        return redirect()->route('movies.index')
                        ->with('success','Movie updated successfully');
    }
  
    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Movie  $movie
     * @return \Illuminate\Http\Response
     */
    public function destroy(Movie $movie)
    {
        $movie->delete();
  
        return redirect()->route('movies.index')
                        ->with('success','Movie deleted successfully');
    }
}

app/Movie.php

<?php
  
namespace App;
  
use Illuminate\Database\Eloquent\Model;
   
class Movie extends Model
{
    protected $fillable = [
        'name', 'detail'
    ];
}

Step 6: Add Blade Files

resources/views/movies/layout.blade.php

<!DOCTYPE html>
<html>
<head>
    <title>Laravel 6 CRUD Application - TamilRokers free Download</title>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha/css/bootstrap.css" rel="stylesheet">
</head>
<body>
  
<div class="container">
    @yield('content')
</div>
   
</body>
</html>

resources/views/movies/index.blade.php

@extends('movies.layout')
 
@section('content')
    <div class="row">
        <div class="col-lg-12 margin-tb">
            <div class="pull-left">
                <h2>Laravel 6 CRUD Example from scratch - TamilRokers free Download</h2>
            </div>
            <div class="pull-right">
                <a class="btn btn-success" href="{{ route('movies.create') }}"> Create New Movie</a>
            </div>
        </div>
    </div>
   
    @if ($message = Session::get('success'))
        <div class="alert alert-success">
            <p>{{ $message }}</p>
        </div>
    @endif
   
    <table class="table table-bordered">
        <tr>
            <th>No</th>
            <th>Name</th>
            <th>Details</th>
            <th width="280px">Action</th>
        </tr>
        @foreach ($movies as $movie)
        <tr>
            <td>{{ ++$i }}</td>
            <td>{{ $movie->name }}</td>
            <td>{{ $movie->detail }}</td>
            <td>
                <form action="{{ route('movies.destroy',$movie->id) }}" method="POST">
   
                    <a class="btn btn-info" href="{{ route('movies.show',$movie->id) }}">Show</a>
    
                    <a class="btn btn-primary" href="{{ route('movies.edit',$movie->id) }}">Edit</a>
   
                    @csrf
                    @method('DELETE')
      
                    <button type="submit" class="btn btn-danger">Delete</button>
                </form>
            </td>
        </tr>
        @endforeach
    </table>
  
    {!! $movies->links() !!}
      
@endsection

resources/views/movies/create.blade.php

@extends('movies.layout')
  
@section('content')
<div class="row">
    <div class="col-lg-12 margin-tb">
        <div class="pull-left">
            <h2>Add New Movie</h2>
        </div>
        <div class="pull-right">
            <a class="btn btn-primary" href="{{ route('movies.index') }}"> Back</a>
        </div>
    </div>
</div>
   
@if ($errors->any())
    <div class="alert alert-danger">
        <strong>Whoops!</strong> There were some problems with your input.<br><br>
        <ul>
            @foreach ($errors->all() as $error)
                <li>{{ $error }}</li>
            @endforeach
        </ul>
    </div>
@endif
   
<form action="{{ route('movies.store') }}" method="POST">
    @csrf
  
     <div class="row">
        <div class="col-xs-12 col-sm-12 col-md-12">
            <div class="form-group">
                <strong>Name:</strong>
                <input type="text" name="name" class="form-control" placeholder="Name">
            </div>
        </div>
        <div class="col-xs-12 col-sm-12 col-md-12">
            <div class="form-group">
                <strong>Detail:</strong>
                <textarea class="form-control" style="height:150px" name="detail" placeholder="Detail"></textarea>
            </div>
        </div>
        <div class="col-xs-12 col-sm-12 col-md-12 text-center">
                <button type="submit" class="btn btn-primary">Submit</button>
        </div>
    </div>
   
</form>
@endsection

resources/views/movies/edit.blade.php

@extends('movies.layout')
   
@section('content')
    <div class="row">
        <div class="col-lg-12 margin-tb">
            <div class="pull-left">
                <h2>Edit Movie</h2>
            </div>
            <div class="pull-right">
                <a class="btn btn-primary" href="{{ route('movies.index') }}"> Back</a>
            </div>
        </div>
    </div>
   
    @if ($errors->any())
        <div class="alert alert-danger">
            <strong>Whoops!</strong> There were some problems with your input.<br><br>
            <ul>
                @foreach ($errors->all() as $error)
                    <li>{{ $error }}</li>
                @endforeach
            </ul>
        </div>
    @endif
  <h3>Laravel 6 CRUD Tutorial With Example from scratch</h3>
    <form action="{{ route('movies.update',$movie->id) }}" method="POST">
        @csrf
        @method('PUT')
   
         <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12">
                <div class="form-group">
                    <strong>Name:</strong>
                    <input type="text" name="name" value="{{ $movie->name }}" class="form-control" placeholder="Name">
                </div>
            </div>
            <div class="col-xs-12 col-sm-12 col-md-12">
                <div class="form-group">
                    <strong>Detail:</strong>
                    <textarea class="form-control" style="height:150px" name="detail" placeholder="Detail">{{ $movie->detail }}</textarea>
                </div>
            </div>
            <div class="col-xs-12 col-sm-12 col-md-12 text-center">
              <button type="submit" class="btn btn-primary">Submit</button>
            </div>
        </div>
   
    </form>
@endsection

resources/views/movies/show.blade.php

@extends('movies.layout')
@section('content')
    <div class="row">
        <div class="col-lg-12 margin-tb">
            <div class="pull-left">
                <h2> Show Movie</h2>
            </div>
            <div class="pull-right">
                <a class="btn btn-primary" href="{{ route('movies.index') }}"> Back</a>
            </div>
        </div>
    </div>
   
    <div class="row">
        <div class="col-xs-12 col-sm-12 col-md-12">
            <div class="form-group">
                <strong>Name:</strong>
                {{ $movie->name }}
            </div>
        </div>
        <div class="col-xs-12 col-sm-12 col-md-12">
            <div class="form-group">
                <strong>Details:</strong>
                {{ $movie->detail }}
            </div>
        </div>
    </div>
@endsection

Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Develop Exclusive Laravel 6 CRUD Application with Input Validations : Laravel 6 CRUD Tutorial With Example from scratch.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.


Related FAQ

Here are some more FAQ related to this Article:

  1.   Laravel 6 Insert Update and Delete record from MySQL
  2.   Resolved : "register_rest_route was called incorrectly"
  3.   Learn Laravel (Best Laravel Tutorials for Beginners)
  4.   PHP Laravel 6 Form Validation Script
  5.   Blinking text CSS Animation
  6.   Laravel Simple CRUD Application Script
  7.   PHP Variable Scope Global Static & Local
  8.   Vuejs Dynamic Dropdown Select Menu using json
  9.   Laravel 6 Hello world example - PHP framework
  10.   Laravel Insert Update Delete in Eloquent ORM laravel