198 lines
5.7 KiB
PHP
198 lines
5.7 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Controllers\Admin;
|
||
|
|
|
||
|
|
use Illuminate\Http\Request;
|
||
|
|
use App\Http\Controllers\Controller;
|
||
|
|
use App\Notification;
|
||
|
|
use App\Department;
|
||
|
|
use App\User;
|
||
|
|
use Session;
|
||
|
|
use DB;
|
||
|
|
|
||
|
|
class NotificationsController extends Controller
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* Create a new controller instance.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public function __construct()
|
||
|
|
{
|
||
|
|
$this->middleware('auth:admin');
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* Display a listing of the resource.
|
||
|
|
*
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function index()
|
||
|
|
{
|
||
|
|
$notifications = DB::table('notifications')
|
||
|
|
->orderBy('id', 'desc')
|
||
|
|
->get();
|
||
|
|
return view('admin.notifications.index', compact('notifications'));
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Show the form for creating a new resource.
|
||
|
|
*
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function create()
|
||
|
|
{
|
||
|
|
$languages = DB::table('languages')
|
||
|
|
->orderBy('serial_no', 'asc')
|
||
|
|
->get();
|
||
|
|
$users = User::join('role_user', 'users.id', '=', 'role_user.user_id')
|
||
|
|
->join('roles', 'role_user.role_id', '=', 'roles.id')
|
||
|
|
->where('users.working_status', '=', '1')
|
||
|
|
->where('users.status', '=', '1')
|
||
|
|
->select('users.*', 'roles.name as role_name', 'roles.id as role_id', 'users.id as id')
|
||
|
|
->orderBy('roles.id', 'asc')
|
||
|
|
->get();
|
||
|
|
$departments = Department::where('status', 1)->orderBy('id', 'asc')->get();
|
||
|
|
return view('admin.notifications.create', compact('users', 'languages', 'departments'));
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Store a newly created resource in storage.
|
||
|
|
*
|
||
|
|
* @param \Illuminate\Http\Request $request
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function store(Request $request)
|
||
|
|
{
|
||
|
|
$validatedData = $this->validate($request, [
|
||
|
|
'title' => 'required|max:150',
|
||
|
|
'title_tm' => 'required|max:150',
|
||
|
|
'title_ru' => 'required|max:150',
|
||
|
|
'text' => 'required|max:150',
|
||
|
|
'text_tm' => 'required|max:150',
|
||
|
|
'text_ru' => 'required|max:150',
|
||
|
|
'users' => 'required',
|
||
|
|
]);
|
||
|
|
$input = $request->all();
|
||
|
|
$input['users']=json_encode($input['users']);
|
||
|
|
$saved_data=Notification::create($input);
|
||
|
|
if($saved_data)
|
||
|
|
{
|
||
|
|
Session::flash('success_message', 'Notification has been added successfully');
|
||
|
|
return redirect()->route('notifications');
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
Session::flash('error_message', 'We are having some problem. Please try later.');
|
||
|
|
return redirect()->route('add-notification');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Display the specified resource.
|
||
|
|
*
|
||
|
|
* @param int $id
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function show($id)
|
||
|
|
{
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Show the form for editing the specified resource.
|
||
|
|
*
|
||
|
|
* @param int $id
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function edit($id)
|
||
|
|
{
|
||
|
|
$id=base64_decode($id);
|
||
|
|
$notification = Notification::where('id', '=', $id)->first();
|
||
|
|
$user_lists = DB::table('users')
|
||
|
|
->join('role_user', 'users.id', '=', 'role_user.user_id')
|
||
|
|
->join('roles', 'role_user.role_id', '=', 'roles.id')
|
||
|
|
->where('users.working_status', '=', '1')
|
||
|
|
->select(DB::raw("CONCAT(users.first_name, ' ',users.last_name) AS user_details"), 'users.id', 'roles.name as role_name')
|
||
|
|
->orderBy('users.id', 'desc')
|
||
|
|
->get()
|
||
|
|
->toArray();
|
||
|
|
if($notification):
|
||
|
|
return view('admin.notifications.edit', compact('notification', 'user_lists'));
|
||
|
|
else:
|
||
|
|
Session::flash('error_message', 'Invalid notification id.');
|
||
|
|
return redirect()->route('notifications');
|
||
|
|
endif;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Update the specified resource in storage.
|
||
|
|
*
|
||
|
|
* @param \Illuminate\Http\Request $request
|
||
|
|
* @param int $id
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function update(Request $request, $id)
|
||
|
|
{
|
||
|
|
$id=base64_decode($id);
|
||
|
|
$notification = Notification::findOrFail($id);
|
||
|
|
$validatedData = $this->validate($request, [
|
||
|
|
'title' => 'required|max:150',
|
||
|
|
'title_tm' => 'required|max:150',
|
||
|
|
'title_ru' => 'required|max:150',
|
||
|
|
'text' => 'required|max:150',
|
||
|
|
'text_tm' => 'required|max:150',
|
||
|
|
'text_ru' => 'required|max:150',
|
||
|
|
'users' => 'required',
|
||
|
|
]);
|
||
|
|
$input = $request->all();
|
||
|
|
$input['users']=json_encode($input['users']);
|
||
|
|
$saved_data=$notification->fill($input)->save();
|
||
|
|
if($saved_data):
|
||
|
|
Session::flash('success_message', 'Notification has been updated successfully');
|
||
|
|
return redirect()->route('notifications');
|
||
|
|
else:
|
||
|
|
Session::flash('error_message', 'We are having some problem. Please try later.');
|
||
|
|
return redirect()->route('edit-notification');
|
||
|
|
endif;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Remove the specified resource from storage.
|
||
|
|
*
|
||
|
|
* @param int $id
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function destroy($id)
|
||
|
|
{
|
||
|
|
$id=base64_decode($id);
|
||
|
|
$notification = Notification::findOrFail($id);
|
||
|
|
$delete_notification = $notification->delete();
|
||
|
|
if($delete_notification):
|
||
|
|
Session::flash('success_message', 'Notification has been deleted successfully');
|
||
|
|
return redirect()->route('notifications');
|
||
|
|
else:
|
||
|
|
Session::flash('error_message', 'We are having some problem. Please try later.');
|
||
|
|
return redirect()->route('notifications');
|
||
|
|
endif;
|
||
|
|
}
|
||
|
|
public function statusupdate($id)
|
||
|
|
{
|
||
|
|
$id=base64_decode($id);
|
||
|
|
$find_notification = Notification::findOrFail($id);
|
||
|
|
if($find_notification->status==1)
|
||
|
|
$status=0;
|
||
|
|
else
|
||
|
|
$status=1;
|
||
|
|
$input=[
|
||
|
|
'status'=>$status
|
||
|
|
];
|
||
|
|
$saved_data=$find_notification->fill($input)->save();
|
||
|
|
if($saved_data):
|
||
|
|
Session::flash('success_message', 'Notification has been updated successfully');
|
||
|
|
return redirect()->route('notifications');
|
||
|
|
else:
|
||
|
|
Session::flash('error_message', 'We are having some problem. Please try later.');
|
||
|
|
return redirect()->route('notifications');
|
||
|
|
endif;
|
||
|
|
}
|
||
|
|
}
|