@ -4,17 +4,17 @@ namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Partner ;
use App\Models\Page ;
use App\Models\User;
use Illuminate\Support\Facades\Session;
class Partner Controller extends Controller
class Page Controller extends Controller
{
protected $view = 'admin.partner .';
protected $redirect = 'admin/partner s';
protected $view = 'admin.page .';
protected $redirect = 'admin/page s';
public function index()
{
$settings = Partner ::orderBy('id','DESC');
$settings = Page ::orderBy('id','DESC');
// if(\request('title')){
// $key = \request('title1');
// $settings = $settings->where('title1','like','%'.$key.'%');
@ -38,57 +38,58 @@ class PartnerController extends Controller
$this->validate(\request(), [
// 'title' => 'required',
'title' => 'required',
'status' => 'required',
'image' => 'required| file|mimes:jpeg,png,jpg'
'banner_ image' => 'file|mimes:jpeg,png,jpg'
]);
if($request->hasFile('image')){
$extension = \request()->file('image')->getClientOriginalExtension();
$image_folder_type = array_search('partner ',config('custom.image_folders')); //for image saved in folder
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('image'),$extension,$count,$image_folder_type);
$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['image'] = $image_path1;
$requestData['banner_ image'] = $image_path1;
}
// $requestData['slug'] = Setting::create_slug($requestData['keyword']);
$setting = Partner ::create($requestData);
$setting = Page ::create($requestData);
Session::flash('success','Partner successfully created');
Session::flash('success','Page successfully created');
return redirect($this->redirect);
}
public function edit($id)
{
$setting = Partner ::findorfail($id);
$setting = Page ::findorfail($id);
return view($this->view.'edit',compact('setting'));
}
public function update(Request $request, $id){
$setting =Partner ::findorfail($id);
$setting =Page ::findorfail($id);
$this->validate(\request(), [
// 'name' => 'required',
'title' => 'required',
'status' => 'required',
'image' => 'file|mimes:jpeg,png,jpg,pdf'
]);
if(\request('image')){
$this->validate(\request(),[
'image' => 'file|mimes:jpeg,png,jpg,pdf '
'banner_ image' => 'file|mimes:jpeg,png,jpg'
]);
if($request->hasFile('image')){
$extension = \request()->file('image')->getClientOriginalExtension();
$image_folder_type = array_search('partner ',config('custom.image_folders')); //for image saved in folder
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('image'),$extension,$count,$image_folder_type);
$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->image) & & file_exists(public_path().'/'.$setting->image)){
unlink(public_path().'/'.$setting->image);
if (is_file(public_path().'/'.$setting->banner_ image) & & file_exists(public_path().'/'.$setting->banner_ image)){
unlink(public_path().'/'.$setting->banner_ image);
}
}
}
@ -97,25 +98,25 @@ class PartnerController extends Controller
$requestData = $request->all();
// $requestData['slug'] = Setting::create_slug($requestData['keyword']);
if(isset($image_path1)){
$requestData['image'] = $image_path1;
$requestData['banner_ image'] = $image_path1;
}
$setting->fill($requestData);
$setting->save();
Session::flash('success','Partner succesffuly updated.');
Session::flash('success','Page succesffuly updated.');
return redirect($this->redirect);
}
public function delete($id){
$setting=Partner ::findorfail($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','Partner is deleted !');
Session::flash('success','Page is deleted !');
return redirect($this->redirect);
}
}