Root Zanli
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
o5t6x7pgljbm
/
public_html
/
app
/
Http
/
Controllers
/
Admin
/
Filename :
GoalController.php
back
Copy
<?php namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use Illuminate\Http\Request; use App\Models\Goal; use Auth; use Hash; use Session; use DB; use Socialite; use Image; Use Response; use Helpers; //use Illuminate\Foundation\Auth\AuthenticatesUsers; //use Mail; class GoalController extends Controller { public function index() { $goals = Goal::all(); return view('Admin.Goal.index',compact('goals')); } public function goal_list(Request $request) { $columns = array("goal_name","goal_logo","goal_color","scholarship_points","short_description","description","goal_id"); $columns2 =array("goals.goal_name","goals.goal_logo","goals.goal_color","goals.scholarship_points","goals.short_description","goals.description","goals.goal_id"); $totalData = Goal::count(); $limit = $request->input('length'); $start = $request->input('start'); $dir = $request->input('order.0.dir'); $query = Goal::select($columns2); $goals = $query->get(); $totalFiltered = $goals->count(); $goals = $query->offset($start); $goals = $query->limit($limit); if(isset($columns2[$request->input('order.0.column')])){ $order = $columns[$request->input('order.0.column')]; $goals = $query->orderBy($order,$dir); } if(isset($request->sort_by) && $request->sort_by == 1) $goals = $query->orderBy('goals.created_at', 'asc'); else $goals = $query->orderBy('goals.created_at', 'desc'); $goals = $query->get(); //$totalFiltered = $query->count(); $data = array(); if(!empty($goals)) { foreach ($goals as $key => $goal) { $edit = route('goals.edit',$goal->goal_id); $delete = route('goals.destroy', $goal->goal_id); foreach ($columns as $key => $column) { if ($column == 'goal_id') { $nestedData[$column] = "<form action='{$delete}' method='POST' id='goalTable-".$goal->$column."'> <input name='_method' type='hidden' value='DELETE'> <a href='{$edit}' title='EDIT' class='mb-6 btn-floating waves-effect waves-light gradient-45deg-green-teal gradient-shadow'> ".csrf_field()." <i class='material-icons'>edit</i></a> <button type='button' title='DELETE' class='mb-6 btn-floating waves-effect waves-light gradient-45deg-purple-deep-orange gradient-shadow' onclick='delete_goal(".$goal->$column.");'> <i class='material-icons'>clear</i> </button> </form>"; } else if($column == 'created_at') { $nestedData[$column] = date('j M Y h:i a',strtotime($goal->$column)); }else if($column == 'goal_logo') { $nestedData[$column] = '<img src="'.asset($goal->goal_logo).'" width="45px"/>'; } else { $nestedData[$column] = $goal->$column; } } $data[] = $nestedData; } } //echo count($data);exit; $json_data = array( "draw" => intval($request->input('draw')), "recordsTotal" => intval($totalData), "recordsFiltered" => intval($totalFiltered), "data" => $data ); // echo '<pre>';print_r($json_data);die; echo json_encode($json_data); } public function create() { $goals = Goal::get(); return view('Admin.Goal.create',compact('goals')); } public function store(Request $request) { $validate = $request->validate([ 'goal_name' => 'required', 'goal_logo_img' => 'required', 'goal_color' => 'required', 'scholarship_points' => 'required', ]); if($request->hasFile('goal_logo_img')) { $file = $request->file('goal_logo_img'); $imageName = rand().time().'.'.$file->getClientOriginalExtension(); // Save thumbnail image // $img = Image::make($file->getRealPath()); // $img->resize(100, 100, function ($constraint) { // $constraint->aspectRatio(); // })->save(public_path('goal_images/thumb/').$imageName); // Save original size image $file->move(public_path('goal_images'), $imageName); $request['goal_logo'] = $imageName; } Goal::create($request->all()); return redirect()->route('goals.index')->with('success','Record Successfully Inserted.'); } public function edit($id) { $goals = Goal::select('*','goal_logo as goal_images')->where('goals.goal_id',$id)->first(); return view('Admin.Goal.edit',compact('goals')); } public function update(Request $request,$id) { $validate = $request->validate([ 'goal_name' => 'required', 'goal_color' => 'required', 'scholarship_points' => 'required', ]); $goals = Goal::find($id); if($request->hasFile('goal_logo_img')) { $file = $request->file('goal_logo_img'); $imageName = rand().time().'.'.$file->getClientOriginalExtension(); // Save thumbnail image // $img = Image::make($file->getRealPath()); // $img->resize(100, 100, function ($constraint) { // $constraint->aspectRatio(); // })->save(public_path('goal_images/thumb/').$imageName); // Save original size image $file->move(public_path('goal_images'), $imageName); $request['goal_logo'] = $imageName; } $goals->update($request->all()); return redirect()->route('goals.index')->with('success','Record Updated Successfully.'); } public function destroy($id) { $data = Goal::find($id)->delete(); return redirect()->route('goals.index')->with('success','Record Deleted Successfully'); } }