PHP Laravel CRUD Application Tutorial for Beginners

Today, We want to share with you PHP Laravel CRUD Application Tutorial for Beginners.In this post we will show you wordpress plugin require another plugin, hear for PHP CRUD Create, edit, update and delete posts with MySQL database we will give you demo and example for implement.In this post, we will learn about Laravel CRUD Tutorial Example Step By Step From Scratch with an example.

PHP Laravel CRUD Application Tutorial for Beginners

There are the Following The simple About simple crud operation in php Laravel using ajax Full Information With Example and source code.

As I will cover this Post with live Working example to develop CRUD Operations in Laravel PHP Framework, so the Laravel 5.8 Basic CRUD Operations In-Depth Example is used for this example is following below.

Step 1: Laravel CRUD Database Configuration

set up in .env and database.php file

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=latest_movie_download
DB_USERNAME=root
[email protected]#$

Step 2: Create Movie Table

simple creating a movie table using migration

php artisan make:migration create_movies_table

public function up()
{
    Schema::create('movies', function (Blueprint $table)
    {
         $table->increments('id');
         $table->string('title');
         $table->text('description');
         $table->timestamps();
    });
}


/**
* Reverse the migrations.
* @return void
*/
public function down()
{
    Schema::dropIfExists('movies');
}

run the command -> setup table into the database

php artisan migrate

Step 3: Laravel Migration with Create model or controller

php artisan make:model Movie -mcr

Step 4: Setup Laravel Model

movie.php

protected $fillable = [ 'title', 'description'];

Step 5: Laravel Create a Controller

Movie Controller index()

public function index()
{
    $movies = Movie::all();
    return view('movies.index',compact('movies',$movies));
}

Movie Controller create()

public function create()
{
    return view('movies.create');
}

Laravel Movie Controller store()

READ :  Laravel INSERT UPDATE DELETE Example Step By Step

here To insert All the data into the MySQL database, copy paste the following PHP Laravel source code into Laravel Controller store function.

E-junkie: Sell digital downloads online

E-junkie Provides a Copy-paste buy-now, and cart buttons for selling downloads, codes and tangible products on any website, blog, social media, email and messenger!

Also see:

  1. The Top 10+ Best Webinar Software Platforms For 2020-2021
  2. Build Your Future Godaddy Careers And Jobs
  3. Introduction To Web Hosting Services

public function store(Request $request)
{
    // Validate
    $request->validate([
        'title' => 'required|min:3',
        'description' => 'required',
    ]);   
    $movie = Movie::create(['title' => $request->title,'description' => $request->description]);
    return redirect('/movies/'.$movie->id);
}

Movie show()

public function show(Movie $movie)
{
    return view('movies.show',compact('movie',$movie));
}

Movie Edit ()

public function edit(Movie $movie)
{
    return view('movies.edit',compact('movie',$movie));
}

Movie Destroy()

public function destroy(Request $request, Movie $movie)

{
    $movie->delete();
    $request->session()->flash('message', 'Successfully deleted the movie!');
    return redirect('movies');
}

Step 5: Simple Create View Laravel – CRUD(Insert Update Delete)

Create.blade.php

@extends('layout.layout')
@section('content')
<h1>Add New Movie</h1>
<hr>
<form action="/movies" method="post">
{{ csrf_field() }}
    <div class="form-group">
        <label for="title">Movie Title</label>
        <input type="text" class="form-control" id="movieTitle"  name="title">
    </div>
    <div class="form-group">
        <label for="description">Movie Description</label>
        <input type="text" class="form-control" id="movieDescription" name="description">
    </div>
    
    @if ($errors->any())
    <div class="alert alert-danger">
        <ul>
            @foreach ($errors->all() as $error)
            <li>{{ $error }}</li>
            @endforeach
        </ul>
    </div>
    @endif
    <button type="submit" class="btn btn-primary">Submit</button>
</form>
@endsection

Step 6: Display View

@extends('layout.layout')
@section('content')

<h1>Showing Movie {{ $movie->title }}</h1>
<div class="jumbotron text-center">
    <p>
        <strong>Movie Title:</strong> {{ $movie->title }}<br>
        <strong>Description:</strong> {{ $movie->description }}
    </p>
</div>
@endsection

Step 7: Edit Form View

@extends('layout.layout')
@section('content')

<h1>Edit Movie</h1>
<hr>
<form action="{{url('movies', [$movie->id])}}" method="POST">
    <input type="hidden" name="_method" value="PUT">
    {{ csrf_field() }}
    <div class="form-group">
        <label for="title">Movie Title</label>
        <input type="text" value="{{$movie->title}}" class="form-control" id="movieTitle"  name="title" >
    </div>
    <div class="form-group">
        <label for="description">Movie Description</label>
        <input type="text" value="{{$movie->description}}" class="form-control" id="movieDescription" name="description" >
    </div>
    
    @if ($errors->any())
    <div class="alert alert-danger">
        <ul>
            @foreach ($errors->all() as $error)
             <li>{{ $error }}</li>
            @endforeach
        </ul>
    </div>
    @endif
     
    <button type="submit" class="btn btn-primary">Submit</button>

</form>
@endsection

Step 8: Delete Actions

<form action="{{url('movies', [$movie->id])}}" method="POST">
    <input type="hidden" name="_method" value="DELETE">
    <input type="hidden" name="_token" value="{{ csrf_token() }}">
    <input type="submit" class="btn btn-danger" value="Delete"/>
</form>

Step 9: Routes

Laravel Define all Routes

Route::get('/', function () {
   return view('welcome');
});
Auth::routes();
Route::get('/home', '[email protected]')->name('home');
Route::get('/create','[email protected]');
Route::get('/movie', '[email protected]');
Route::get('/edit/movie/{id}','[email protected]');
Route::post('/edit/movie/{id}','[email protected]');
Route::delete('/delete/movie/{id}','[email protected]');

Web Programming Tutorials Example with Demo

Read :

READ :  Trigger button click on enter key JavaScript

Summary

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

I hope you get an idea about laravel 6 crud example download.
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.