You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					123 lines
				
				4.4 KiB
			
		
		
			
		
	
	
					123 lines
				
				4.4 KiB
			| 
								 
											3 years ago
										 
									 | 
							
								<?php
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								namespace App\Http\Controllers\Admin;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								use App\Http\Controllers\Controller;
							 | 
						||
| 
								 | 
							
								use Illuminate\Http\Request;
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								use App\Models\Page;
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								use App\Models\User;
							 | 
						||
| 
								 | 
							
								use Illuminate\Support\Facades\Session;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								class PageController extends Controller
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								{
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								    protected $view = 'admin.page.';
							 | 
						||
| 
								 | 
							
								    protected $redirect = 'admin/pages';
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								    public function index()
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								        $settings = Page::orderBy('id','DESC');
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								        // if(\request('title')){
							 | 
						||
| 
								 | 
							
								        //     $key = \request('title1');
							 | 
						||
| 
								 | 
							
								        //     $settings = $settings->where('title1','like','%'.$key.'%');
							 | 
						||
| 
								 | 
							
								        // }
							 | 
						||
| 
								 | 
							
								        // if(\request('status')){
							 | 
						||
| 
								 | 
							
								        //     $key = \request('status');
							 | 
						||
| 
								 | 
							
								        //     $settings = $settings->where('status',$key);
							 | 
						||
| 
								 | 
							
								        // }
							 | 
						||
| 
								 | 
							
								        $settings = $settings->paginate(config('custom.per_page'));
							 | 
						||
| 
								 | 
							
								        return view($this->view.'index',compact('settings'));
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    public function create()
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        return view($this->view.'create');
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    public function store(Request $request)
							 | 
						||
| 
								 | 
							
								    {       
							 | 
						||
| 
								 | 
							
								        
							 | 
						||
| 
								 | 
							
								   
							 | 
						||
| 
								 | 
							
								            $this->validate(\request(), [
							 | 
						||
| 
								 | 
							
								             
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								                'title' => 'required',
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								                'status' => 'required',
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								                'banner_image' => 'file|mimes:jpeg,png,jpg'
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								            ]);
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								            if($request->hasFile('banner_image')){
							 | 
						||
| 
								 | 
							
								                $extension = \request()->file('banner_image')->getClientOriginalExtension();
							 | 
						||
| 
								 | 
							
								                $image_folder_type = array_search('page',config('custom.image_folders')); //for image saved in folder
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								                $count = rand(100,999);
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								                $out_put_path = User::save_image(\request('banner_image'),$extension,$count,$image_folder_type);
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								                $image_path1 = $out_put_path[0];
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        $requestData = $request->all();
							 | 
						||
| 
								 | 
							
								        if(isset($image_path1)){
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								            $requestData['banner_image'] = $image_path1;
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								        }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        // $requestData['slug'] = Setting::create_slug($requestData['keyword']);
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								        $setting = Page::create($requestData);
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								        
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								        Session::flash('success','Page successfully created');
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								        return redirect($this->redirect);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    public function edit($id)
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								      $setting = Page::findorfail($id);
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								      return view($this->view.'edit',compact('setting'));
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    public function update(Request $request, $id){
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								                $setting =Page::findorfail($id);
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								                $this->validate(\request(), [
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								                    'title' => 'required',
							 | 
						||
| 
								 | 
							
								                
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								                    'status' => 'required',
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								                    
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								                ]);
							 | 
						||
| 
								 | 
							
								        
							 | 
						||
| 
								 | 
							
								                if(\request('image')){
							 | 
						||
| 
								 | 
							
								                    $this->validate(\request(),[
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								                        'banner_image' => 'file|mimes:jpeg,png,jpg'
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								                    ]);
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								                    if($request->hasFile('banner_image')){
							 | 
						||
| 
								 | 
							
								                        $extension = \request()->file('banner_image')->getClientOriginalExtension();
							 | 
						||
| 
								 | 
							
								                        $image_folder_type = array_search('page',config('custom.image_folders')); //for image saved in folder
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								                        $count = rand(100,999);
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								                        $out_put_path = User::save_image(\request('banner_image'),$extension,$count,$image_folder_type);
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								                        $image_path1 = $out_put_path[0];
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								                        if (is_file(public_path().'/'.$setting->banner_image) && file_exists(public_path().'/'.$setting->banner_image)){
							 | 
						||
| 
								 | 
							
								                            unlink(public_path().'/'.$setting->banner_image);
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								                        }
							 | 
						||
| 
								 | 
							
								                    }
							 | 
						||
| 
								 | 
							
								                }
							 | 
						||
| 
								 | 
							
								        
							 | 
						||
| 
								 | 
							
								        
							 | 
						||
| 
								 | 
							
								                $requestData = $request->all();
							 | 
						||
| 
								 | 
							
								                // $requestData['slug'] = Setting::create_slug($requestData['keyword']);
							 | 
						||
| 
								 | 
							
								                if(isset($image_path1)){
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								                    $requestData['banner_image'] = $image_path1;
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								                }
							 | 
						||
| 
								 | 
							
								                $setting->fill($requestData);
							 | 
						||
| 
								 | 
							
								                $setting->save();
							 | 
						||
| 
								 | 
							
								                
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								                Session::flash('success','Page succesffuly updated.');
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								                return redirect($this->redirect);
							 | 
						||
| 
								 | 
							
								        
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								        
							 | 
						||
| 
								 | 
							
								            public function delete($id){
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								                $setting=Page::findorfail($id);
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								                
							 | 
						||
| 
								 | 
							
								                if($setting->delete()){
							 | 
						||
| 
								 | 
							
								                    if (is_file(public_path().'/'.$setting->image) && file_exists(public_path().'/'.$setting->image)){
							 | 
						||
| 
								 | 
							
								                        unlink(public_path().'/'.$setting->image);
							 | 
						||
| 
								 | 
							
								                    }
							 | 
						||
| 
								 | 
							
								                }
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								                Session::flash('success','Page is deleted !');
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								                return redirect($this->redirect);
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								}
							 |