This is the basic codes(used as template) which used in most of the CRUD operation of laravel while using route(resource)
Controller code
<?php
namespace AppHttpControllers;
use AppModelsScenarioMaster;
use AppModelsLogfile;
use IlluminateHttpRequest;
class ScenarioMasterController extends Controller
{
//
public function index()
{
$data = ScenarioMaster::orderBy('created_at', 'asc')->get();
return view('masters.ttm_master.scenario_master.index',['datas'=>$data]);
}
public function create()
{
return view('masters.ttm_master.scenario_master.insert');
}
public function store(Request $request)
{
$story="New Scenario Master Added(".$request->name.") Recorded. ";
Logfile::create([
'story'=>$story
]);
ScenarioMaster::create([
'scenario'=>$request->name,
]);
return redirect('scenario_master')->with('status','Data Created Successfully!');
}
public function edit($id)
{
$data = ScenarioMaster::where('id', $id)->first();
return view('masters.ttm_master.scenario_master.edit', ['data' => $data]);
}
public function update(Request $request)
{
print_r($data = ScenarioMaster::where('id', $request->id)->first());
$data->update([
'scenario' => $request->name,
]);
return redirect('scenario_master')->with('status', 'Data Updated Successfully!');
}
public function destroy(Request $request, $id)
{
$acts = ScenarioMaster::where('id', $id)->first();
if ($acts) {
$acts->delete(); // Delete the record
return redirect('scenario_master')->with('status', 'Data Removed Successfully!');
}
return redirect('scenario_master')->with('error', 'Data Not Found!');
}
}
EDIT Blade file
@extends('layouts/main')
@section('main-section')
<!-- Content wrapper -->
<div class="content-wrapper">
<!-- Content -->
<div class="container-xxl flex-grow-1 container-p-y">
<div class="row">
<div class="col-xxl-12 mb-12 order-0 card">
<!-- code starts -->
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="card-header">
<h4>
Edit {{$data->scenario}}
<a href="{{ url('scenario_master') }}" class="btn btn-danger float-end">Back</a>
</h4>
</div>
@if(session('success'))
<div class="alert alert-success">{{ session('success') }}</div>
@endif
<div class="card-body">
<form action="{{ route('scenario_master.update', [$data->id]) }}" method="POST">
@csrf
@method('PUT')
<input type="hidden" value="{{$data->id}}" name="id">
<div class="row">
<div class="col-md-12 mb-3">
<label for="">Scenario Name</label>
<input type="text" name="name" class="form-control" value="{{ old('name', $data->scenario) }}">
@error('name')
<div class="alert alert-danger">{{$message}}</div>
@enderror
</div>
</div>
<div class="mb-3">
<button type="submit" class="btn btn-primary">Update {{$data->scenario}}</button>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- code ends -->
</div>
</div>
</div>
</div>
@endsection
Index blade page
@extends('layouts/main')
@section('main-section')
<!-- Content wrapper -->
<div class="content-wrapper">
<!-- Content -->
<div class="container-xxl flex-grow-1 container-p-y">
<div class="row">
<div class="col-xxl-12 mb-12 order-0 card">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="card-header">
@if(session('status'))
<div class="alert alert-success alert-dismissible fade show" role="alert">
{{ session('status') }}
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
@endif
</div>
<div class="card-header">
<h4>
Scenario Master
<a href="{{ url('scenario_master/create')}}" class="btn btn-primary float-end">Add </a>
</h4>
</div>
<div class="card-body">
<div class="table-responsive">
<table id="dataTable" class=" display table">
<thead>
<tr>
<th>SL</th>
<th>Scenario</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@foreach ($datas as $index =>$item )
<tr>
<td>{{$index +1}}</td>
<td>{{$item->scenario}}</td>
<td>
<div class="dropdown">
<button type="button" class="btn p-0 dropdown-toggle hide-arrow" data-bs-toggle="dropdown">
<i class="bx bx-dots-vertical-rounded"></i>
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="{{ url('scenario_master/'.$item->id.'/edit')}}"><i class="bx bx-edit-alt me-1"></i> Edit</a>
<button type="button" class="dropdown-item" data-bs-toggle="modal" data-bs-target="#flipInXAnimationModal{{$item->id}}">
<i class=" bx bx-trash me-1"></i> Delete
</button>
</div>
</div>
<!-- Modal -->
<div class="modal animate_animated animate_flipInX" id="flipInXAnimationModal{{$item->id}}" tabindex="-1" aria-labelledby="flipInXAnimationModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Confirmation!!!</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close">
</button>
</div>
<div class="modal-body">
<h3>Are you Sure You want to Delete this.???</h3>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<span type="button" class="btn btn-danger">
<a class="dropdown-item" href="{{ url('scenario_master/'.$item->id.'/delete')}}"><i class=" bx bx-trash me-1"></i> Delete</a>
</span>
</div>
</div>
</div>
</div>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<!-- code ends -->
</div>
</div>
<script>
$(document).ready(function() {
$('#dataTable').DataTable({
"order": [[0, "desc"]] // Orders by the first column (ID) in descending order
});
});
</script>
@endsection
and finally this is create blade page
@extends('layouts/main')
@section('main-section')
<!-- Content wrapper -->
<div class="content-wrapper">
<!-- Content -->
<div class="container-xxl flex-grow-1 container-p-y">
<div class="row">
<div class="col-xxl-12 mb-12 order-0 card">
<!-- code starts -->
<div class="container">
<div class="row">
<div class="col-md-12">
@if(session('status'))
<div class="alert alert-success">{{ session('status') }}</div>
@endif
<div class="card-header">
<h4>
Create Scenario Master
<a href="{{ url('scenario_master') }}" class="btn btn-danger float-end">Back</a>
</h4>
</div>
@if(session('success'))
<div class="alert alert-success">{{session('success')}}</div>
@endif
<div class="card-body">
<form action="{{ url('scenario_master') }}" method="POST">
@csrf
<div class="row">
<div class="col-md-12 mb-3">
<label for=""> Name</label>
<input type="text" name="name" class="form-control" value="{{ old('name') }}">
@error('name')
<div class="alert alert-danger">{{$message}}</div>
@enderror
</div>
</div>
<div class="mb-3">
<button type="submit" class="btn btn-primary">Create </button>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- code ends -->
</div>
</div>
</div>
</div>
@endsection
Controllers, blades create,edit and Update codes
Trending...
Related posts
At Least 20 Tourists Killed In Pahalgam, 'Were Shot For Not Being Muslim': What We Know So Far About J&K Terror Attack Travel
A warm message to that kind of person , Who thinks different.. Blog
Chennai Express Shooting Locations: You Must Visit At Least Once Travel
Chennai Diaries: Kshitiz Kumar's Sunday Stroll at Marina Beach Travel
How to apply application for PHD Entrance test of Ranchi University 2025 Guides
Aryan and Ananya love story at ranchi (Podcast by kshitiz ) Episode :2 Blog
Aryan an Ananya love story starts at ranchi (coverd by kshitiz) part 1 Blog
TCS NQT (National Qualifier Test) Honest Review by Kshitiz Kumar TechWorld
Kasol is a hamlet in the Kullu district of the Indian state of Himachal Pradesh Travel
Haryana: A Land Steeped in History and Nature’s Bounty Travel
Punjab: A Land Where Every Heart Beats to the Rhythm of Bhangra Travel
Uttarakhand: Where Nature and Spirituality Embrace You Travel
Shimla: The Enchanting Queen of Hills Awaits You! 🌄 Travel
Laravel mostly used codes during project development Coding
Bersache is a brand that sells sports and casual footwear for men and women. Blog
Jharkhand Election Result 2024: जीत के बाद बोले सीएम हेमंत सोरेन, ‘साथ चलकर सोना झारखंड के निर्माण का लें संकल्प’ Blog
Netarhat, often referred to as the "Queen of Chotanagpur" Blog
Battlegrounds Mobile India 3.5 will be the biggest update of the year; here is why TechWorld
We celebrate diwali in much happier frame of mind 😊 LifeStyle
Business Insider Business News India: Latest Business News Today, Share TechWorld
I am watching whole ranchi from the top in the night in diwali Blog
Diwali 2024 highlights: The Deepotsav celebrations featured around 1,100 people performing a special aarti on the banks of the Saryu river. LifeStyle
Western Railway to run unreserved special trains for Bandra-Gorakhpur and Udhna-Chhapra routes Travel
South Indian food is known for the use of generous coconut in their curries Food
CMRL stands for Chennai Metro Rail Limited, a joint venture between the Government of India and the Government of Tamil Nadu that builds and operates the Chennai Metro Travel
What can you do for your Fit & Good Healthy Life..? Healthy
You might be interested in
-
Visited Ranchi Johna Fall
2024-11-20 20:36:32 223 views -
I visited a beautiful place at renukoot
2025-06-26 11:11:19 23 views
Home
- No posts available.
Travel
-
I visited a beautiful place at renukoot
26 June 23 views -
Chennai Express Shooting Locations: You Must Visit At Least Once
27 January 2676 views
Guides
-
How to apply application for PHD Entrance test of Ranchi University 2025
08 January 180 views -
Tourist Places in Ranchi
28 November 822 views -
The Sacred Shores of Puri
28 November 227 views
Food
-
आलू पराठा रेसिपी (घर का बना पंजाबी स्टाइल)
17 November 158 views -
Are you black tea lover.????
17 November 230 views -
South Indian food is known for the use of generous coconut in their curries
27 October 273 views
Coding
-
Laravel mostly used codes during project development
24 November 225 views -
How to write email codes without SMTP
24 November 185 views
Review
- No posts available.
Healthy
-
What can you do for your Fit & Good Healthy Life..?
27 October 228 views
LifeStyle
-
Visited Ranchi Johna Fall
20 November 223 views -
We celebrate diwali in much happier frame of mind 😊
17 November 283 views
Blog
-
A warm message to that kind of person , Who thinks different..
01 April 81 views -
Aryan and Ananya love story at ranchi (Podcast by kshitiz ) Episode :2
03 January 153 views -
Aryan an Ananya love story starts at ranchi (coverd by kshitiz) part 1
03 January 181 views
TechWorld
-
The Alternate way to run Laravel site
28 January 128 views -
TCS NQT (National Qualifier Test) Honest Review by Kshitiz Kumar
21 December 220 views -
why we should learn php
18 November 389 views
Lyrics
-
Hanuman Chalisa
17 November 267 views
Categories
Home
Show all Blog Posts.
Travel
Travelling is the cure for Health and Soul.
Guides
We always need a guide for our lives.
Food
Food is a big part of our life.
Coding
Coding is the Era of New Tech India.
Review
Review is now going to import things for Anything.
Healthy
Health is wealth , we should never ignore it.
LifeStyle
Our lifestyle decides our health.
Blog
Blog is a great source of Knowledge and skills.
TechWorld
We are here to define all tech things for our
Lyrics
Songs
Comments
Leave a Reply