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.
122 lines
4.4 KiB
122 lines
4.4 KiB
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
use App\Models\Page;
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\Session;
|
|
|
|
class PageController extends Controller
|
|
{
|
|
protected $view = 'admin.page.';
|
|
protected $redirect = 'admin/pages';
|
|
public function index()
|
|
{
|
|
$settings = Page::orderBy('id','DESC');
|
|
// 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(), [
|
|
|
|
'title' => 'required',
|
|
'status' => 'required',
|
|
'banner_image' => 'file|mimes:jpeg,png,jpg'
|
|
]);
|
|
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
|
|
$count = rand(100,999);
|
|
$out_put_path = User::save_image(\request('banner_image'),$extension,$count,$image_folder_type);
|
|
$image_path1 = $out_put_path[0];
|
|
}
|
|
|
|
$requestData = $request->all();
|
|
if(isset($image_path1)){
|
|
$requestData['banner_image'] = $image_path1;
|
|
}
|
|
|
|
// $requestData['slug'] = Setting::create_slug($requestData['keyword']);
|
|
$setting = Page::create($requestData);
|
|
|
|
Session::flash('success','Page successfully created');
|
|
return redirect($this->redirect);
|
|
}
|
|
|
|
public function edit($id)
|
|
{
|
|
$setting = Page::findorfail($id);
|
|
return view($this->view.'edit',compact('setting'));
|
|
}
|
|
|
|
public function update(Request $request, $id){
|
|
|
|
$setting =Page::findorfail($id);
|
|
$this->validate(\request(), [
|
|
'title' => 'required',
|
|
|
|
'status' => 'required',
|
|
|
|
]);
|
|
|
|
if(\request('banner_image')){
|
|
$this->validate(\request(),[
|
|
'banner_image' => 'file|mimes:jpeg,png,jpg'
|
|
]);
|
|
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
|
|
$count = rand(100,999);
|
|
$out_put_path = User::save_image(\request('banner_image'),$extension,$count,$image_folder_type);
|
|
$image_path1 = $out_put_path[0];
|
|
if (is_file(public_path().'/'.$setting->banner_image) && file_exists(public_path().'/'.$setting->banner_image)){
|
|
unlink(public_path().'/'.$setting->banner_image);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
$requestData = $request->all();
|
|
// $requestData['slug'] = Setting::create_slug($requestData['keyword']);
|
|
if(isset($image_path1)){
|
|
$requestData['banner_image'] = $image_path1;
|
|
}
|
|
$setting->fill($requestData);
|
|
$setting->save();
|
|
|
|
Session::flash('success','Page succesffuly updated.');
|
|
return redirect($this->redirect);
|
|
|
|
}
|
|
|
|
public function delete($id){
|
|
$setting=Page::findorfail($id);
|
|
|
|
if($setting->delete()){
|
|
if (is_file(public_path().'/'.$setting->image) && file_exists(public_path().'/'.$setting->image)){
|
|
unlink(public_path().'/'.$setting->image);
|
|
}
|
|
}
|
|
Session::flash('success','Page is deleted !');
|
|
return redirect($this->redirect);
|
|
}
|
|
}
|
|
|