search != null){ $blogs = $blogs->where('title', 'like', '%'.$request->search.'%'); $sort_search = $request->search; } $blogs = $blogs->paginate(15); return view('backend.blog_system.blog.index', compact('blogs','sort_search')); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { $blog_categories = BlogCategory::all(); return view('backend.blog_system.blog.create', compact('blog_categories')); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $request->validate([ 'category_id' => 'required', 'title' => 'required|max:255', ]); $blog = new Blog; $blog->category_id = $request->category_id; $blog->title = $request->title; $blog->banner = $request->banner; $blog->slug = preg_replace('/[^A-Za-z0-9\-]/', '', str_replace(' ', '-', $request->slug)); $blog->short_description = $request->short_description; $blog->description = $request->description; $blog->meta_title = $request->meta_title; $blog->meta_img = $request->meta_img; $blog->meta_description = $request->meta_description; $blog->meta_keywords = $request->meta_keywords; $blog->save(); flash(translate('Blog post has been created successfully'))->success(); return redirect()->route('blog.index'); } /** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { } /** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $blog = Blog::find($id); $blog_categories = BlogCategory::all(); return view('backend.blog_system.blog.edit', compact('blog','blog_categories')); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $request->validate([ 'category_id' => 'required', 'title' => 'required|max:255', ]); $blog = Blog::find($id); $blog->category_id = $request->category_id; $blog->title = $request->title; $blog->banner = $request->banner; $blog->slug = preg_replace('/[^A-Za-z0-9\-]/', '', str_replace(' ', '-', $request->slug)); $blog->short_description = $request->short_description; $blog->description = $request->description; $blog->meta_title = $request->meta_title; $blog->meta_img = $request->meta_img; $blog->meta_description = $request->meta_description; $blog->meta_keywords = $request->meta_keywords; $blog->save(); flash(translate('Blog post has been updated successfully'))->success(); return redirect()->route('blog.index'); } public function change_status(Request $request) { $blog = Blog::find($request->id); $blog->status = $request->status; $blog->save(); return 1; } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { Blog::find($id)->delete(); return redirect('admin/blogs'); } public function all_blog() { $blogs = Blog::where('status', 1)->orderBy('created_at', 'desc')->paginate(12); return view("frontend.blog.listing", compact('blogs')); } public function blog_details($slug) { $blog = Blog::where('slug', $slug)->first(); return view("frontend.blog.details", compact('blog')); } }