Viewing file: NoticeController.php (4.43 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller; use App\Models\Notice; use Illuminate\Http\Request;
class NoticeController extends Controller { public function index(){
return view('admin.notice.index'); }
public function getAll() {
$customers = auth()->user()->notices()->select(['id', 'title', 'description','for', 'status']); return datatables()->of($customers) ->addColumn('for', function ($q) { if($q->for=='normal'){ $type='Customer' ; }else { $type = ucfirst(str_replace('_', '-', $q->for)); } return $type; }) ->addColumn('description', function ($q) { $desc= clean($q->description); return $desc; }) ->addColumn('status', function ($q) { if($q->status=='active'){ $status= '<strong class="text-white bg-success px-2 py-1 rounded status-font-size"> '.ucfirst($q->status).' </strong>'; }else{ $status= '<strong class="text-white bg-danger px-2 py-1 rounded status-font-size"> '.ucfirst($q->status).' </strong>'; } return $status; }) ->addColumn('action', function (Notice $q) { return "<a class='btn btn-sm btn-info' href='" . route('admin.notice.edit', [$q->id]) . "'>Edit</a>".' <button class="btn btn-sm btn-danger" data-message="Are you sure you want to delete this notice?" data-action=' . route('admin.notice.destroy', [$q]) . ' data-input={"_method":"delete"} data-toggle="modal" data-target="#modal-confirm">Delete</button>'; }) ->rawColumns(['action', 'for', 'description','status']) ->toJson(); } public function create(){
return view('admin.notice.create'); }
public function store(Request $request){ $request->validate([ 'title'=>'required', 'description'=>'required', 'type'=>'required|in:reseller,normal,master_reseller,reseller_customer,master_reseller_customer,all', 'status'=>'required|in:active,inactive', ]); $attached_data=''; if ($request->hasFile('attached_data')) { $file = $request->file('attached_data'); $filename = time() . '.' . $file->getClientOriginalExtension(); $file->move(public_path('/uploads'), $filename); $attached_data = $filename; } $notice= new Notice(); $notice->admin_id=auth()->user()->id; $notice->title=$request->title; $notice->description= clean($request->description); $notice->attached_data=$attached_data; $notice->for=$request->type; $notice->status=$request->status; $notice->save();
return redirect()->route('admin.notice.index')->with('success', trans('admin.message.notice_created')); }
public function edit(Notice $notice){ $data['notice']=$notice; return view('admin.notice.edit', $data); }
public function update(Request $request, Notice $notice){
$request->validate([ 'title'=>'required', 'description'=>'required', 'type'=>'required|in:reseller,normal,master_reseller,reseller_customer,master_reseller_customer,all', 'status'=>'required|in:active,inactive', ]); $notice->admin_id=auth()->user()->id; $notice->title=$request->title; $notice->description=clean($request->description); $notice->for=$request->type; $notice->status=$request->status;
if ($request->hasFile('attached_data')) { $file = $request->file('attached_data'); $filename = time() . '.' . $file->getClientOriginalExtension(); $file->move(public_path('/uploads'), $filename); $notice->attached_data = $filename; } $notice->save();
return redirect()->route('admin.notice.index')->with('success', trans('admin.message.notice_updated')); }
public function destroy(Notice $notice){ $notice->delete(); return redirect()->route('admin.notice.index')->with('success', trans('admin.message.notice_deleted')); }
}
|