/
home
/
sjslayjy
/
public_html
/
theweavenest
/
app
/
Http
/
Controllers
/
Admin
/
Upload File
HOME
<?php namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use App\Models\Admin\Size; use App\Models\Admin\Post; use Illuminate\Support\Facades\DB; use Illuminate\Http\Request; use Illuminate\Support\Facades\Storage; class SizeController extends Controller { public function index() { $result['data']=Size::all(); return view('admin/size',$result); } public function manage_size(Request $request,$id='') { if($id>0){ $arr=Size::where(['id'=>$id])->get(); $result['size']=$arr['0']->size; $result['status']=$arr['0']->status; $result['id']=$arr['0']->id; }else{ $result['size']=''; $result['status']=''; $result['id']=0; } return view('admin/manage_size',$result); } public function manage_size_process(Request $request) { //return $request->post(); $request->validate([ 'size'=>'required|unique:sizes,size,'.$request->post('id'), ]); if($request->post('id')>0){ $model=Size::find($request->post('id')); $msg="Size updated"; }else{ $model=new Size(); $msg="Size inserted"; } $model->size=$request->post('size'); $model->status=1; $model->save(); $request->session()->flash('message',$msg); return redirect('admin/size'); } public function delete(Request $request,$id){ $model=Size::find($id); $model->delete(); $request->session()->flash('message','Size deleted'); return redirect('admin/size'); } public function status(Request $request,$status,$id){ $model=Size::find($id); $model->status=$status; $model->save(); $request->session()->flash('message','Size status updated'); return redirect('admin/size'); } //POSTS_______Blogs public function index_posts() { // Retrieve all posts from the database using the DB facade $posts = DB::table('posts')->get(); // Pass the posts to the view and return it return view('admin.posts', ['posts' => $posts]); } public function manage_posts(Request $request, $id = '') { $post = new Post(); // Initialize an empty post object // Check if an ID is provided and greater than 0 if ($id > 0) { // If ID is provided, fetch the post data for editing $post = Post::findOrFail($id); } // Retrieve the URL of the old image if it exists $old_image_url = $post->image ?? null; // Pass the post data and old image URL to the view return view('admin.manage_posts', compact('post', 'old_image_url')); } public function manage_posts_process(Request $request) { // Retrieve the ID from the request $id = $request->input('id'); // Check if an ID is provided if ($id) { // If ID is provided, update the existing post $post = Post::findOrFail($id); $msg = "Post updated"; } else { // If no ID is provided, create a new post $post = new Post(); $msg = "Post inserted"; } // Set post properties $post->title = $request->input('title'); $post->description = $request->input('description'); // Check if a new image is uploaded if ($request->hasFile('image')) { // Store the new image $image = $request->file('image'); $ext = $image->extension(); $image_name = time() . '.' . $ext; $image->storeAs('public/media/category', $image_name); $post->image = $image_name; } // Save the post $post->save(); // Redirect back to the posts index with a success message return redirect('admin/posts' )->with('success', $msg); } public function delete_posts(Request $request,$id){ $model=Post::find($id); $model->delete(); $request->session()->flash('message','Blog deleted'); return redirect('admin/posts'); } public function status_posts(Request $request,$status,$id){ $model=Post::find($id); $model->status=$status; $model->save(); $request->session()->flash('message','Blog status updated'); return redirect('admin/posts'); } }