<?php
<!-- Insert Data In Database by laravel FrameWork -->
These Are given step : how to insert data in database laravel smart
1. // Create databse in Mysql
2. // Create Model in Laravel
3. // Create Controller in laravel
4. // Create View page in laravel
5. // Create Route
6. // Edit
7. // Delte
NOte: Edit section value change pls use mind and complet this is only
for example .
** Note ** // Create Same Name Model & Databse Name Like this way
Databse Name : Coursepages //
1. // DataBase Field Name
= $DataBaseFieldName['course_id'];
= $DataBaseFieldName['start_date'];
= $DataBaseFieldName['end_date'];
= $DataBaseFieldName['duration'];
= $DataBaseFieldName['instructor_id'];
= $DataBaseFieldName['total_course_time'];
2. // Create Model Name ;
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Coursepage extends Model
{
//
}
?>
3.// Create Controller
<?php
namespace App\Http\Controllers;
use App\Coursepage;
class CoursepageController extends Controller
{
public function add(Request $request){
if($request->isMethod('post')){
$data = $request->all();
$validatedData = $request->validate
([
'course_id'=>'required|max:90|min:2',
]);
$course_page_data = new Coursepage;
$course_page_data->course_id = $data['course_id']; //index page value
$course_page_data->start_date = $data['start_date'];
$course_page_data->end_date = $data['end_date'];
$course_page_data->duration = $data['duration'];
$course_page_data->instructor_id = $data['instructor_id'];
$course_page_data->total_course_time = $data['total_course_time'];
$course_page_data->save();
if($course_page_data->save())
{
return redirect('/course-page')->with('success','Course Page added successfully');
}
else
{
return redirect('/course-page')->with('errors',COMMON_ERROR);
}
}
$page = 'Add Course Page';
return view('admin.coursepage.insert',compact('page'));
}
}
?>
4. // Create View page
<form action="{{ route('coursepage.insert') }}" method="post"
enctype="multipart/form-data">
<input type="text" name="course_id" >
<input type="text" name="start_date ">
<input type="text" name="end_date ">
<input type="text" name="duration ">
<input type="text" name=" instructor_id">
<input type="text" name="total_course_time ">
<input type="submit" value="submit">
</form>
5. // Route page
Route::get('/coursepage','CoursepageController@index');
Route::post('/data/cuisines','CoursepageController@cuisinesList');
Route::match(['get','post'],'/coursepage/add','CoursepageController@add');
Route::match(['get','post'],'/coursepage/edit/{Coursepage}','CoursepageController@edit');
//soft-delete of cusisine
Route::match(['get','post'],'/coursepage/delete/{Coursepage}','CoursepageController@delete');
6. public function edit(Request $request,$Coursepage)
{
$cuisine_detail = Coursepage::where('id',$Coursepage)->first();
if ($request->isMethod('post')){
$data = $request->all();
$this->validate($request,[
'name'=>'required|max:20|min:3',
]);
$cuisine_detail->name = $data['name'];
if ($cuisine_detail->save()) {
return redirect('/admin/cuisines')->with('success', 'Course Updated');
}else{
return redirect()->back()->with('errors',COMMON_ERROR);
}
}
$page = 'cuisines';
return view('backEnd.contentManagement.cuisines.form',
compact('page','cuisine_detail','Coursepage'));
}
7.
public function delete($Coursepage)
{
$del = Coursepage::where('id',$Coursepage)
->update(['deleted_at'=> date('Y-m-d h:i:s')]);
if ($del)
{
return redirect()->back()->with('success', 'Coursepage deleted');
}
else
{
return redirect()->back()->with('errors',COMMON_ERROR);
}
}
0 comments:
Post a Comment
Thanks