Advertisement
Guest User

Untitled

a guest
Mar 25th, 2018
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.77 KB | None | 0 0
  1. //usercontroller
  2. <?php
  3.  
  4. namespace App\Http\Controllers;
  5.  
  6. use App\User;
  7. use Illuminate\Http\Request;
  8. use Illuminate\Support\Str;
  9. use Mail;
  10. use App\Mail\verifyEmail;
  11.  
  12.  
  13. class UserController extends Controller
  14. {
  15. /**
  16. * Display a listing of the resource.
  17. *
  18. * @return \Illuminate\Http\Response
  19. */
  20. public function index()
  21. {
  22. $users = User::all();
  23.  
  24. //Load all users on the table and pass the users
  25. $users = User::where(['archive'=>1])->orderBy('id')->get();
  26. return view('usercrud.index')->with('users', $users);
  27. }
  28.  
  29. /**
  30. * Show the form for creating a new resource.
  31. *
  32. * @return \Illuminate\Http\Response
  33. */
  34.  
  35. public function verifyEmailFirst(Request $request)
  36. {
  37. //
  38. return view('usercrud.verifyEmailFirst');
  39. }
  40.  
  41. /* public function emailtoken(Request $request)
  42. {
  43. //
  44. return
  45.  
  46. } */
  47.  
  48. /**
  49. * Store a newly created resource in storage.
  50. *
  51. * @param \Illuminate\Http\Request $request
  52. * @return \Illuminate\Http\Response
  53. */
  54. public function store(Request $request)
  55. {
  56. //
  57. }
  58.  
  59. /**
  60. * Display the specified resource.
  61. *
  62. * @param int $id
  63. * @return \Illuminate\Http\Response
  64. */
  65. public function show($id)
  66. {
  67. //
  68. }
  69.  
  70. /**
  71. * Show the form for editing the specified resource.
  72. *
  73. * @param int $id
  74. * @return \Illuminate\Http\Response
  75. */
  76. public function edit($id)
  77. {
  78. //
  79. $users = User::where(['id'=>$id])->first();
  80.  
  81.  
  82. // dd($users);
  83.  
  84. return view('usercrud.edit',compact('users'));
  85. }
  86.  
  87. /**
  88. * Update the specified resource in storage.
  89. *
  90. * @param \Illuminate\Http\Request $request
  91. * @param int $id
  92. * @return \Illuminate\Http\Response
  93. */
  94. public function update(Request $request, $id)
  95. {
  96. //
  97. $usersUp = new User;
  98. $password = bcrypt($request->editpassword);
  99.  
  100.  
  101. // dd($request->editcompanyPos);
  102.  
  103. $usersUp = User::where('id',$id)
  104. ->update(['position'=>$request->editcompanyPos,'name'=>$request->editfullname,'email'=>$request->editemail,'password'=>$password,'roles'=>$request->editrole_id]);
  105.  
  106. $users = User::all();
  107. $users = User::where(['archive'=>1])->orderBy('id')->get();
  108.  
  109. return redirect()->to('userIndex')->with('users', $users);
  110. }
  111.  
  112. /**
  113. * Remove the specified resource from storage.
  114. *
  115. * @param int $id
  116. * @return \Illuminate\Http\Response
  117. */
  118. public function destroy($id)
  119. {
  120. $userDel = User::where('id',$id)->update(['archive'=>0]);
  121.  
  122. $users = User::all();
  123. $users = User::where(['archive'=>1])->orderBy('id')->get();
  124.  
  125. return redirect()->to('userIndex')->with('users', $users);
  126.  
  127. }
  128.  
  129. public function sendEmail($thisUser)
  130. {
  131. Mail::to($thisUser['email'])->send(new verifyEmail($thisUser));
  132. }
  133.  
  134. public function sendEmailDone($email, $verifyToken)
  135. {
  136. $user = User::where(['email'=>$email, 'verifyToken'=>$verifyToken])->first();
  137. //return $user;
  138. if ($user){
  139. return user::where(['email'=>$email, 'verifyToken'=>$verifyToken])->update(['status'=>'1','verifyToken'=>NULL]);
  140.  
  141. }else{
  142. return 'user not found';
  143. }
  144.  
  145. }
  146.  
  147.  
  148.  
  149. }
  150. ________________________________________________
  151. //web.php
  152.  
  153. Route::get('/', function () {
  154. return view('bgcbus');
  155. });
  156.  
  157. Auth::routes();
  158.  
  159. Route::get('/home', 'HomeController@index')->name('home');
  160. Route::get('/home/submitsurvey',['uses'=>'HomeController@submitsurvey','as'=>'surveysubmit']);
  161.  
  162.  
  163. Route::resource('/users', 'UserController');
  164.  
  165. //UserCreate
  166. Route::post('/create','UserController@create');
  167. Route::get('/userIndex','UserController@index');
  168. //User Update
  169. Route::match(['get','post'],'/userUpdate/{id}','UserController@update');
  170. //User Edit
  171. Route::get('/userEdit/{id}','UserController@edit');
  172. //User Delete
  173. Route::get('/userDelete/{id}','UserController@destroy');
  174.  
  175. //Bus
  176. Route::resource('/buses', 'BusController');
  177. //Bus Create
  178. Route::post('/buscreate','BusController@create');
  179. Route::get('/busindex','BusController@index');
  180. //Bus Edt
  181. Route::get('/busEdit/{id}','BusController@edit');
  182. //Bus Update
  183. Route::match(['get','post'],'/busUpdate/{id}','BusController@update');
  184. //Bus Delete
  185. Route::get('/busDelete/{id}','BusController@destroy');
  186.  
  187.  
  188. //Bus Routes
  189. Route::resource('/bgcroutes', 'BgcrouteController');
  190. //Bus Route create
  191. Route::post('/bgcroutecreate', 'BgcrouteController@create');
  192. Route::get('/bgcrouteindex', 'BgcrouteController@index');
  193. //Bus Route Edit
  194. Route::get('/bgcrouteEdit/{id}','BgcrouteController@edit');
  195. //Bus Route update
  196. Route::match(['get','post'],'/bgcrouteUpdate/{id}','BgcrouteController@update');
  197. //Bus Route Delete
  198. Route::get('/bgcrouteDelete/{id}','BgcrouteController@destroy');
  199.  
  200. //Questions
  201. Route::resource('/questions', 'SurveyquestionController');
  202. //Questions create
  203. Route::post('/questioncreate', 'SurveyquestionController@create');
  204. Route::get('/questionindex', 'SurveyquestionController@index');
  205. //Questions Edit
  206. Route::get('/questionEdit/{id}','SurveyquestionController@edit');
  207. //Questions update
  208. Route::match(['get','post'],'/questionUpdate/{id}','SurveyquestionController@update');
  209. //Questions Delete
  210. Route::get('/questionDelete/{id}','SurveyquestionController@destroy');
  211.  
  212. //Applying Active Value
  213. Route::post('/question/apply',['uses'=>'SurveyquestionController@apply','as'=>'applyQuestion']);
  214.  
  215. // Selecting Emoji
  216. Route::get('/home/surveyvote',['uses'=>'HomeController@surveyvote','as'=>'surveyvoting']);
  217.  
  218.  
  219.  
  220. //2ndQuestions
  221. Route::resource('/scndquestions', 'QuestionsurveyController');
  222. //2ndQuestions create
  223. Route::post('/scndquestionscreate', 'QuestionsurveyController@create');
  224. Route::get('/scndquestionsindex', 'QuestionsurveyController@index');
  225. //2ndQuestions Edit
  226. Route::get('/scndquestionsEdit/{id}','QuestionsurveyController@edit');
  227. //2ndQuestions update
  228. Route::match(['get','post'],'/scndquestionsUpdate/{id}','QuestionsurveyController@update');
  229. //2ndQuestions Delete
  230. Route::get('/scndquestionsDelete/{id}','QuestionsurveyController@destroy');
  231.  
  232. //Applying Active Value in 2nd Question
  233. Route::post('/scndquestion/setapply', ['uses' => 'QuestionsurveyController@setapply','as'=>'setapplyscndQuestion']);
  234.  
  235.  
  236.  
  237. //Dashboard
  238.  
  239. Route::get('/driverDashboard', 'DashboardfirstController@index');
  240.  
  241. Route::post('/driverDashboard/data',['uses'=>'ChartsController@getData','as'=>'getPiechart']);
  242.  
  243. //verification email
  244. Route::get('verify/{email}/{verifyToken}','UserController@sendEmailDone')->name('sendEmailDone');
  245.  
  246. ___________________________
  247. //verifyemail
  248. <?php
  249.  
  250. namespace App\Mail;
  251.  
  252. use Illuminate\Bus\Queueable;
  253. use Illuminate\Mail\Mailable;
  254. use Illuminate\Queue\SerializesModels;
  255. use Illuminate\Contracts\Queue\ShouldQueue;
  256. use App\User;
  257.  
  258. class verifyEmail extends Mailable
  259. {
  260. use Queueable, SerializesModels;
  261.  
  262. /**
  263. * Create a new message instance.
  264. *
  265. * @return void
  266. */
  267. public $user;
  268. public function __construct(User $user)
  269. {
  270. //
  271. $this->user=$user;
  272.  
  273. }
  274.  
  275. /**
  276. * Build the message.
  277. *
  278. * @return $this
  279. */
  280. public function build()
  281. {
  282. return $this->view('usercrud.sendView');
  283. }
  284. }
  285. __________________________
  286. //model
  287. //User
  288.  
  289. <?php
  290.  
  291. namespace App;
  292.  
  293. use Illuminate\Notifications\Notifiable;
  294. use Illuminate\Foundation\Auth\User as Authenticatable;
  295. use Illuminate\Support\Str;
  296.  
  297. class User extends Authenticatable
  298. {
  299. use Notifiable;
  300.  
  301. /**
  302. * The attributes that are mass assignable.
  303. *
  304. * @var array
  305. */
  306. protected $fillable = [
  307. 'name', 'email', 'password', 'position', 'roles', 'verifyToken'
  308. ];
  309.  
  310. /**
  311. * The attributes that should be hidden for arrays.
  312. *
  313. * @var array
  314. */
  315. protected $hidden = [
  316. 'password', 'remember_token',
  317. ];
  318. }
  319.  
  320. _________________
  321. //view
  322. //usercrud.index
  323. @extends ('layouts.dashboards')
  324.  
  325. @section('content')
  326.  
  327. <link rel="stylesheet" type="text/css" href="">
  328.  
  329. <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal"><i class="fa fa-user-plus"></i>
  330. </button>
  331.  
  332. <!-- Modal -->
  333. <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  334. <div class="modal-dialog" role="document">
  335. <div class="modal-content">
  336. <div class="modal-header">
  337. <h5 class="modal-title" id="exampleModalLabel">Create New User's</h5>
  338. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  339. <span aria-hidden="true">&times;</span>
  340. </button>
  341. </div>
  342.  
  343. <div class="modal-body">
  344.  
  345.  
  346. <form method="post" action="{{url('create')}}" class="login">
  347. {{ csrf_field() }}
  348. <div class="form-group">
  349. <label for="exampleInputEmail1">Employee Number</label>
  350. <input name="empid" type="text" class="form-control" placeholder="Enter Employee Number">
  351. </div>
  352. <div class="form-group">
  353. <label for="exampleInputEmail1">Company Job Position</label>
  354. <input name="companyPos" type="text" class="form-control" placeholder="Enter Job Position">
  355. </div>
  356. <div class="form-group">
  357. <label for="exampleInputEmail1">Name</label>
  358. <input name="fullname" type="text" class="form-control" placeholder="Enter your Name">
  359. </div>
  360. <div class="form-group">
  361. <label for="exampleInputPassword1">E-mail</label>
  362. <input name="email" type="email" class="form-control" id="exampleInputPassword1" placeholder="Enter your E-MAIL">
  363. <small id="emailHelp" class="form-text text-muted">Please Enter E-mail</small>
  364. </div>
  365. <div class="form-group">
  366. <label for="exampleInputPassword1">Password</label>
  367. <input name="password" type="password" class="form-control" id="exampleInputPassword1" placeholder="Enter Password">
  368.  
  369. </div>
  370.  
  371. <div class="form-group">
  372. <label>Choose Type of User:</label>
  373. <select name="role_id" class="custom-select" id="inputGroupSelect04">
  374. <option selected>---Please Pick Type of User---</option>
  375. <option value="1">Admin</option>
  376. <option value="2">Dispatcher</option>
  377. <option value="3">Driver</option>
  378. </select>
  379. </div>
  380. <div class="form-group">
  381. <label>Upload Image</label>
  382. <input type="file" name="images" id="images">
  383. </div>
  384. <div class="modal-footer">
  385. <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
  386. <button type="submit" class="btn btn-primary">Submit</button>
  387. </div>
  388. </form>
  389. </div>
  390. </div>
  391. </div>
  392. </div>
  393.  
  394.  
  395. <div class="col-md-12">
  396.  
  397.  
  398. <div class="card-body table-full-width table-responsive">
  399. <h2>Driver's and Management Accounts</h2>
  400. <p>You can Create, Edit and Delete in here</p>
  401. <table id="myTable" ctable class="table table-hover table-striped" >
  402. <thead>
  403. <tr>
  404. <th>ID</th>
  405. <th>Position</th>
  406. <th>Name</th>
  407. <th>E-mail</th>
  408. <th>Action</th>
  409. </tr>
  410. </thead>
  411. <tbody>
  412. <tr>
  413. @foreach ($users as $value)
  414. <td>{{ $value->id }}</td>
  415. <td>{{ $value->position }}</td>
  416. <td>{{ $value->name }}</td>
  417. <td>{{ $value->email }}</td>
  418. <td>
  419. <a href="{{ url('userEdit', $value->id)}}" class="btn btn-primary"><i class="fa fa-edit"></i></a>
  420.  
  421. <a href="{{ url('userDelete', $value->id)}}" class="btn btn-danger"><i class="fa fa-trash"></i></a>
  422. </td>
  423. </tr>
  424. @endforeach
  425. </tbody>
  426. </table>
  427. </div>
  428. </div>
  429.  
  430.  
  431. <!-- $(document).ready(function(){
  432. $('#myTable').DataTable();
  433. });
  434. -->
  435.  
  436. @endsection
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement