ProfileController.php
index.blade.php
edit.blade.php
web.php
ProfileController
use Illuminate\Support\Facades\File; use Image; use Illuminate\Support\Facades\Validator; use App\Models\Profile; class ProfileController extends Controller { public function index(){ $all_data = Profile::select('*')->orderBy('id', 'DESC')->get(); return view('admin.profile.index',compact('all_data')); } public function store(Request $request){ $all_data = new Profile; $all_data ->name = $request->name; $all_data ->detail = $request->detail; $all_data ->gender = $request->gender; $all_data ->hobbies = json_encode($request->hobbies); $all_data ->profession = $request->profession; if($request->hasfile('image')){ $file = $request->file('image'); // $name = $file->getClientOriginalName(); $name = date('YmdHis').".".$file->getClientOriginalExtension(); $path = public_path('/images/profile'); $img = Image::make($file->path()); $img->resize(100, 100)->save($path.'/'.$name); $all_data->image = $name; } $all_data->save(); return redirect()->back()->with('success', 'Added Successfully Done'); } public function edit($id){ $data = Profile::find($id); return view('admin.profile.edit', compact('data')); } public function update(Request $request, $id){ $data = Profile::find($id); $data->name = $request->name; $data->detail = $request->detail; $data->gender = $request->gender; $data->hobbies = json_encode($request->hobbies); $data->profession = $request->profession; if($request->hasfile('image')){ $destination = 'images/profile/'.$data->image; if(File::exists($destination)){ File::delete($destination); } $file=$request->file('image'); //$name=$file->getClientOriginalName(); $name=date('YmdHis').".".$file->getClientOriginalExtension(); $path = public_path('/images/profile'); $img = Image::make($file->path()); $img->resize(100, 100)->save($path.'/'.$name); $data->image = $name; } $data->update(); return redirect()->to('/')->with('success', 'Updated Successfully Done'); } public function delete($id){ $data = Profile::find($id); $destination = 'images/profile/'.$data->image; if(File::exists($destination)){ File::delete($destination); } $data->delete(); return redirect()->back()->with('error', 'Deleted Successfully Done'); } }
index
@extends('layouts.backend') @section('css')
@endsection @section('content')
Dashboard
Profile
Create
Create
@csrf
Name :
Image :
Detail :
Gender :
Male
Female
Others
Hobbies :
Playing
Drwing
Profession :
Choose
Student
Business
Job
#
Name
Image
Detail
Gender
Hobbies
Profession
Action
@foreach($all_data as $data)
{{$loop->index+1}}
{{$data->name}}
{!!$data->detail!!}
{{$data->gender}}
@php $hobby_show = json_decode($data->hobbies); @endphp @if(!is_null($hobby_show)) @foreach($hobby_show as $hobby) {{$hobby}}, @endforeach @endif
{{$data->profession}}
Show
Edit
Delete
Show
Delete
Are you sure ?
@endforeach
@endsection @section('js') @endsection
edit
@extends('layouts.backend') @section('css') @endsection @section('content') @php $hobby = json_decode($data->hobbies); @endphp
Back
@csrf @method('put')
Name :
Image
:
Gender :
gender=="Male"){ echo "checked"; } ?> >
Male
gender=="Female"){ echo "checked"; } ?> >
Female
gender=="Others"){ echo "checked"; } ?> >
Others
@if(!is_null($hobby))
Hobbies :
Playing
Drwing
@endif
Hobbies :
Playing
Drwing
Profession :
{{$data->profession}}
Student
Business
Job
Detail :
{!!$data->detail!!}
Save changes
@endsection @section('js') @endsection
web
use App\Http\Controllers\ProfileController; // ProfileController Route::get('/', [ProfileController::class, 'index']); Route::post('/admin/profile/store', [ProfileController::class, 'store']); Route::get('/admin/profile/edit/{id}', [ProfileController::class, 'edit']); Route::put('/admin/profile/update/{id}', [ProfileController::class, 'update']); Route::get('/admin/profile/delete/{id}', [ProfileController::class, 'delete']);