ModalController.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use App\Proposal;
  6. use App\User;
  7. use App\StudentProposal;
  8. use App\Country;
  9. use App\Models\ReferUser;
  10. use App\Models\Admin;
  11. use App\Models\Requirement;
  12. use App\Models\University;
  13. use App\Models\Publication;
  14. use App\Models\FeedbackReason;
  15. use App\Workexperience;
  16. use App\Institution;
  17. use App\Score;
  18. use Hash;
  19. use DB;
  20. use Session;
  21. use Auth;
  22. use Mail;
  23. Use Carbon\Carbon;
  24. class ModalController extends Controller{
  25. public function get(Request $req, $name){
  26. $user = Auth::user();
  27. $carbon=new \Carbon\Carbon;
  28. $data=[
  29. 'name'=>$name,
  30. 'carbon'=>$carbon
  31. ];
  32. if($name=="apply_student_proposal"){
  33. $student =Auth::user();
  34. $data['teacher'] = User::find($req->t_id);
  35. $data['student'] = User::find($student->id);
  36. $data['proposal']= Proposal::where('student_id',$user->id)->get();
  37. }elseif($name=="update_student_proposal"){
  38. $data['std_proposal'] =StudentProposal::find($req->id);
  39. $data['teacher'] = User::find($req->teacher_id);
  40. $data['student'] = User::find($req->student_id);
  41. $data['proposal']= Proposal::where('student_id',$req->student_id)->get();
  42. $data['years']=range((int)date('Y'), date('Y')+1);
  43. }elseif($name=="view_apply_proposal"){
  44. $data['std_proposal'] =StudentProposal::find($req->id);
  45. }elseif($name=="view_student_proposal"){
  46. $data['proposal']= Proposal::where(
  47. 'student_id',$user->id
  48. )->where(
  49. 'id',$req->id
  50. )->first();
  51. }elseif($name=="add_destination"){
  52. }elseif($name=="add_wishlist"){
  53. $user =Auth::guard('teacher')->user();
  54. $data['refer'] = new ReferUser;
  55. }elseif($name=="teacher_invited"){
  56. $data['admin'] =Admin::find($req->id);
  57. }elseif($name=="add_doc_required"){
  58. $data['std_proposal']=StudentProposal::find($req->id);
  59. }elseif($name=="edit_doc_required"){
  60. $data['requirements']=Requirement::find($req->id);
  61. }elseif($name=="landing_register_form"){
  62. $data['countries'] =Country::where('status',1)->orderBy('name','ASC')->get();
  63. //$data['universities'] =University::orderBy('name','ASC')->get();
  64. }elseif($name=="send_email_document_information"){
  65. $data['teacher']=Auth::guard('teacher')->user();
  66. $data['std_proposal']=StudentProposal::find($req->id);
  67. $data['doc_requirement_list']=Requirement::where('std_proposal_id',$req->id)->get();
  68. }elseif($name=="proposal_status_rejected_form"){
  69. $data['teacher']=Auth::guard('teacher')->user();
  70. $data['std_proposal']=StudentProposal::find($req->id);
  71. $data['feedback_reasons'] =FeedbackReason::where('status',1)->orderBy('id','DESC')->get();
  72. }else $name='default';
  73. return view("modal_pages.{$name}", $data);
  74. }
  75. public function post(Request $req, $name){
  76. $user=Auth::user();
  77. $carbon=new \Carbon\Carbon;
  78. if($name=='apply_student_proposal'){
  79. //dd($req->student_id);
  80. $new_rules=[
  81. 'proposal_id'=>'required',
  82. ];
  83. $validator=\Validator::make($req->all(),$new_rules,[
  84. 'proposal_id.required'=>'Please complete your profile to submit your proposal.',
  85. 'startdate'=>'required',
  86. 'startmonth'=>'required',
  87. ]);
  88. if($validator->fails()){
  89. $errors=$validator->errors()->all();
  90. return response(['msg'=>$errors[0]], 422);
  91. }
  92. $student_data =User::where('id',$req->student_id)->where(function($q){
  93. $q->where(
  94. 'is_publication',0
  95. )->orWhere(
  96. 'is_work_experience',0
  97. )->orWhere(
  98. 'is_education',0
  99. )->orWhere(
  100. 'is_test_score',0
  101. );
  102. })->exists();
  103. if($student_data){
  104. return response(['msg'=>'you didn\'t complete your profile.'],403);
  105. }
  106. $awaiting = StudentProposal::where(
  107. 'student_id',$req->student_id
  108. )->where(
  109. 'teacher_id',$req->teacher_id
  110. )->where(
  111. 'proposal_id',$req->proposal_id
  112. )->where(
  113. 'proposal_submit_status',1
  114. )->whereIn(
  115. 'proposal_status',[1,2,3,4] // 1 =New; 2 =In Review; 3=Push; 4=Hold;
  116. )->exists();
  117. if($awaiting){
  118. return response(['msg'=>'Application you have submitted that are currently awaiting decisions'],403);
  119. }
  120. $approved_proposal = StudentProposal::where(
  121. 'student_id',$req->student_id
  122. )->where(
  123. 'teacher_id',$req->teacher_id
  124. )->where(
  125. 'proposal_id',$req->proposal_id
  126. )->where(
  127. 'proposal_submit_status',1
  128. )->where(
  129. 'proposal_status',5 // 5=interest;
  130. )->exists();
  131. if($approved_proposal){
  132. return response(['msg'=>'Application you have submitted that are approved'],403);
  133. }
  134. $currentYear = date('Y');
  135. $currentMonth = date('m');
  136. $selectedMonth =$req->startmonth;
  137. if($currentYear ==$req->startdate && $currentMonth >= $selectedMonth){
  138. return response(['msg'=>'Current or previous month is not supported'],403);
  139. }
  140. $student_proposal =new StudentProposal;
  141. $student_proposal->student_id =$req->student_id;
  142. $student_proposal->teacher_id =$req->teacher_id;
  143. $student_proposal->proposal_id =$req->proposal_id;
  144. $student_proposal->start_year =$req->startdate;
  145. $student_proposal->start_month =$req->startmonth;
  146. $student_proposal->preferred_start_date =$req->startdate.'-'.$req->startmonth.'-'.'01';
  147. $student_proposal->student_apply_ref =studentRefNoGenerate();
  148. $student_proposal->proposal_submit_status = 1;
  149. $student_proposal->submitted_date = now();
  150. $student_proposal->created_by =$req->student_id;
  151. $student_proposal->save();
  152. $student_data =User::find($student_proposal->student_id);
  153. $student_data->freez_profile =1;
  154. $student_data->update();
  155. $teacher =User::find($student_proposal->teacher_id);
  156. if($teacher->university_name){
  157. $university =$teacher->university_name;
  158. }else{
  159. $university = cn($teacher,'university.name','');
  160. }
  161. if($student_data){
  162. $data['name'] = $student_data->first_name.' '.$student_data->last_name;
  163. $data['teacher'] = $teacher->first_name.' '.$teacher->last_name;
  164. $data['university'] = $university;
  165. $data['submission_date'] = $student_data->created_at;
  166. $data['receive_email']=$student_data->email;
  167. //$data['arn'] = $teacher->ref_no;
  168. $user_mail =$student_data->email;
  169. $from = 'asraful@revinr.com';
  170. Mail::send('email.student_proposal_email',$data, function ($message) use ($user_mail,$from,$student_proposal) {
  171. $message->from($from);
  172. $message->to($user_mail)->subject('Apply Ref:' .$student_proposal->student_apply_ref. '- Proposal has been submitted successfully ');
  173. });
  174. }
  175. $proposal =Proposal::where(
  176. 'student_id',$student_proposal->student_id
  177. )->where(
  178. 'id',$student_proposal->proposal_id
  179. )->first();
  180. if($teacher){
  181. $data['name'] = $teacher->first_name.' '.$teacher->last_name;
  182. $data['std_name'] = $user->first_name.' '.$user->last_name;
  183. $data['proposal_title'] =$proposal->title;
  184. $data['date_time']=$student_proposal->submitted_date;
  185. $data['receive_email']=$teacher->email;
  186. $user_mail =$teacher->email;
  187. $from = 'asraful@revinr.com';
  188. Mail::send('email.teacher_proposal_email',$data, function ($message) use ($user_mail,$from) {
  189. $message->from($from);
  190. $message->to($user_mail)->subject('New Proposal Received - Action Required');
  191. });
  192. }
  193. return response(['msg'=>'Proposal send successfully.']);
  194. }elseif($name=="update_student_proposal"){
  195. $new_rules=[
  196. 'proposal_id'=>'required',
  197. ];
  198. $validator=\Validator::make($req->all(),$new_rules,[
  199. 'proposal_id.required'=>'Please complete your profile to submit your proposal.',
  200. 'startdate'=>'required',
  201. 'startmonth'=>'required',
  202. ]);
  203. if($validator->fails()){
  204. $errors=$validator->errors()->all();
  205. return response(['msg'=>$errors[0]], 422);
  206. }
  207. $approved_proposal = StudentProposal::where(
  208. 'student_id',$req->student_id
  209. )->where(
  210. 'teacher_id',$req->teacher_id
  211. )->where(
  212. 'proposal_id',$req->proposal_id
  213. )->where(
  214. 'proposal_submit_status',1
  215. )->where(
  216. 'proposal_status',5 // 5=interest;
  217. )->exists();
  218. if($approved_proposal){
  219. return response(['msg'=>'Already Selected proposal has been submitted'],403);
  220. }
  221. $awaiting = StudentProposal::where(
  222. 'student_id',$req->student_id
  223. )->where(
  224. 'teacher_id',$req->teacher_id
  225. )->where(
  226. 'proposal_id',$req->proposal_id
  227. )->where(
  228. 'proposal_submit_status',1
  229. )->whereIn(
  230. 'proposal_status',[1,2,3,4] // 1 =New; 2 =In Review; 3=Push; 4=Hold;
  231. )->exists();
  232. if($awaiting){
  233. return response(['msg'=>'Application you have submitted that are currently awaiting decisions'],403);
  234. }
  235. $currentYear = date('Y');
  236. $currentMonth = date('m');
  237. $selectedMonth =$req->startmonth;
  238. if($currentYear ==$req->startdate && $currentMonth >= $selectedMonth){
  239. return response(['msg'=>'Current or previous month is not supported'],403);
  240. }
  241. $student_proposal =StudentProposal::find($req->id);
  242. $student_proposal->proposal_id =$req->proposal_id;
  243. $student_proposal->start_year =$req->startdate;
  244. $student_proposal->start_month =$req->startmonth;
  245. $student_proposal->preferred_start_date =$req->startdate.'-'.$req->startmonth.'-'.'01';
  246. $student_proposal->student_apply_ref =studentRefNoGenerate();
  247. $student_proposal->proposal_submit_status = 1;
  248. $student_proposal->submitted_date = now();
  249. $student_proposal->created_by =$req->student_id;
  250. $student_proposal->draft_status =0; // Q-Form
  251. $student_proposal->update();
  252. $student_data =User::find($student_proposal->student_id);
  253. $student_data->freez_profile =1;
  254. $student_data->update();
  255. $teacher =User::find($student_proposal->teacher_id);
  256. if($teacher->university_name){
  257. $university =$teacher->university_name;
  258. }else{
  259. $university = cn($teacher,'university.name','');
  260. }
  261. if($student_data){
  262. $data['name'] = $student_data->first_name.' '.$student_data->last_name;
  263. $data['teacher'] = $teacher->first_name.' '.$teacher->last_name;
  264. $data['university'] = $university;
  265. $data['submission_date'] = $student_data->created_at;
  266. $data['receive_email']=$student_data->email;
  267. //$data['arn'] = $proposal_user->ref_no;
  268. $user_mail =$student_data->email;
  269. $from = 'asraful@revinr.com';
  270. Mail::send('email.student_proposal_email',$data, function ($message) use ($user_mail,$from,$student_proposal) {
  271. $message->from($from);
  272. $message->to($user_mail)->subject('Apply Ref:' .$student_proposal->student_apply_ref. '- Proposal has been submitted successfully ');
  273. });
  274. }
  275. $proposal =Proposal::where(
  276. 'student_id',$student_proposal->student_id
  277. )->where(
  278. 'id',$student_proposal->proposal_id
  279. )->first();
  280. if($teacher){
  281. $data['name'] = $teacher->first_name.' '.$teacher->last_name;
  282. $data['std_name'] = $student_data->first_name.' '.$student_data->last_name;
  283. $data['proposal_title'] =$proposal->title;
  284. $data['date_time']=$student_proposal->submitted_date;
  285. $data['receive_email']=$teacher->email;
  286. $user_mail =$teacher->email;
  287. $from = 'asraful@revinr.com';
  288. Mail::send('email.teacher_proposal_email',$data, function ($message) use ($user_mail,$from) {
  289. $message->from($from);
  290. $message->to($user_mail)->subject('New Proposal Received - Action Required');
  291. });
  292. }
  293. return response(['msg'=>'Successfully updated.']);
  294. }elseif($name=="add_wishlist"){
  295. $teacher =Auth::guard('teacher')->user();
  296. $validator=\Validator::make($req->all(), [
  297. 'name'=>'required',
  298. 'email'=>'required|email|max:255'
  299. ]);
  300. if($validator->fails()){
  301. $errors=$validator->errors()->all();
  302. return response(['msg'=>$errors[0]], 422);
  303. }
  304. $is_user_exists=User::where('email',$req->email)->where('user_type',1)->exists();
  305. if($is_user_exists){
  306. $user_notify =User::where('email',$req->email)->where('user_type',1)->first();
  307. $is_student_proposal_exists =StudentProposal::where(
  308. 'teacher_id',$teacher->id
  309. )->where(
  310. 'student_id',$user_notify->id
  311. )->whereIn(
  312. 'proposal_status',[1,2,3,4] // 1 =New; 2 =In Review; 3=Push; 4=Hold;
  313. )->exists();
  314. if($is_student_proposal_exists){
  315. return response(
  316. ['msg'=>'Already there is an account associated this email ID. Please login to your account.'],403
  317. );
  318. }else{
  319. $refer =new ReferUser;
  320. $refer->name =$req->name;
  321. $refer->email =$req->email;
  322. $refer->refer_by =$teacher->id;
  323. $refer->teacher_id =$teacher->id;
  324. $refer->save();
  325. }
  326. }else{
  327. $user_data =new User;
  328. $user_data->first_name =$req->name;
  329. $user_data->email =$req->email;
  330. $user_data->user_type =1;
  331. $user_data->status =0;
  332. $user_data->register_type =4; // 1=invitation ; 2= landing/wishlish; 3 =q_form ; 4=student-wishlist
  333. $user_data->invitation_date =now();
  334. $user_data->wishlist_teacher_id =$teacher->id;
  335. $user_data->save();
  336. $refer =new ReferUser;
  337. $refer->name =$req->name;
  338. $refer->email =$req->email;
  339. $refer->refer_by =$teacher->id;
  340. $refer->teacher_id =$teacher->id;
  341. $refer->save();
  342. $teacher =User::where('email',$req->email)->where('user_type',1)->first();
  343. if($teacher->others_department){
  344. $department =$teacher->others_department;
  345. }else{
  346. $department = cn($teacher,'department_name.name','');
  347. }
  348. if($teacher->university_name){
  349. $university =$teacher->university_name;
  350. }else{
  351. $university = cn($teacher,'university.name','');
  352. }
  353. $data['name'] = $refer->name;
  354. $data['teacher_id'] = $refer->teacher_id;
  355. $data['student_id'] = $user_notify->id;
  356. $data['std_email'] = $refer->email;
  357. $data['teacher'] = $teacher->first_name.' '.$teacher->last_name;
  358. $data['arn'] = $teacher->ref_no;
  359. $data['designation'] = $teacher->designation;
  360. $data['department'] = $department;
  361. $data['university'] = $university;
  362. $data['receive_email']=$refer->email;
  363. $user_mail = $refer->email;
  364. $from = 'asraful@revinr.com';
  365. Mail::send('email.wishlist_email',$data, function ($message) use ($user_mail,$from) {
  366. $message->from($from);
  367. $message->to($user_mail)->subject('Research Admission Platform Sign-Up');
  368. });
  369. }
  370. return response(
  371. ['msg'=>'Wishlist saved successfully.']
  372. );
  373. }elseif($name=="teacher_invited"){
  374. $admin =Admin::find($req->id);
  375. $validator=\Validator::make($req->all(), [
  376. 'name'=>'required',
  377. 'email'=>'required|email|max:255'
  378. ]);
  379. if($validator->fails()){
  380. $errors=$validator->errors()->all();
  381. return response(['msg'=>$errors[0]], 422);
  382. }
  383. $isUserExists = User::where(
  384. 'email',$req->email
  385. )->where(
  386. 'user_type',2
  387. )->where(function($q){
  388. $q->where('sign_up',1)->orWhere('sign_up',0);
  389. })->exists();
  390. if($isUserExists){
  391. return response([
  392. 'msg'=>'Already there is an account associated this email ID.'
  393. ],403);
  394. }else{
  395. $user_data =new User;
  396. $user_data->first_name =$req->name;
  397. $user_data->email =$req->email;
  398. $user_data->admin_invite_id =$admin->id;
  399. $user_data->user_type =2;
  400. $user_data->register_type =1; // 1=invitation ; 2=wishlist/landing
  401. $user_data->invitation_date =now();
  402. $user_data->save();
  403. $teacher_user =User::where('email',$req->email)->where('user_type',2)->first();
  404. $refer =new ReferUser;
  405. $refer->name =$req->name;
  406. $refer->email =$req->email;
  407. $refer->refer_by =$admin->id;
  408. $refer->teacher_id =$teacher_user->id;
  409. $refer->save();
  410. $data['name'] = $refer->name;
  411. $data['teacher_id'] = $teacher_user->id;
  412. $data['applicant_name'] = $admin->first_name.' '.$admin->last_name;
  413. $data['email']=$refer->email;
  414. $data['receive_email']=$refer->email;
  415. $user_mail = $refer->email;
  416. $from = 'asraful@revinr.com';
  417. if($req->is_currently_open==1){
  418. Mail::send('email.invitation_to_supervisor_email_with_checked',$data, function ($message) use ($user_mail,$from) {
  419. $message->from($from);
  420. $message->to($user_mail)->subject('Accepting doctoral applications! Expedite the process with pre-screening proposals');
  421. });
  422. }else{
  423. Mail::send('email.invitation_to_supervisor_email',$data, function ($message) use ($user_mail,$from) {
  424. $message->from($from);
  425. $message->to($user_mail)->subject('Optimize Your Workflow: Join our Innovative Doctoral Applicant Management Solution');
  426. });
  427. }
  428. }
  429. $already_invited =ReferUser::where('email',$refer->email)->count();
  430. if($already_invited > 1) {
  431. return response(
  432. ['msg'=>"Successfully saved. Already invitation send {$already_invited} times."]
  433. );
  434. }else{
  435. return response(
  436. ['msg'=>'Invitation saved successfully.']
  437. );
  438. }
  439. }elseif($name=="add_doc_required"){
  440. $user=auth_user();
  441. $new_rules=[
  442. 'others'=>'required|array',
  443. 'others.*.requirement_title'=>'required',
  444. ];
  445. $validator=\Validator::make($req->all(),$new_rules,[
  446. 'others.*.requirement_title.required'=>'Please!, fill-up all requirement field.'
  447. ]);
  448. if($validator->fails()){
  449. $errors=$validator->errors()->all();
  450. return response(['msg'=>$errors[0]], 422);
  451. }
  452. $std_proposal=StudentProposal::find($req->id);
  453. foreach($req->others as $row){
  454. Requirement::create([
  455. 'std_proposal_id'=>$std_proposal->id,
  456. 'requirement_title'=>$row['requirement_title'],
  457. 'need_upload'=>$row['need_upload'],
  458. 'created_by'=>$user->id
  459. ]);
  460. }
  461. return response([
  462. 'msg'=>'Successfully Saved.'
  463. ]);
  464. }elseif($name=="edit_doc_required"){
  465. $requirements=Requirement::find($req->id);
  466. $requirements->requirement_title =$req->requirement_title;
  467. $requirements->need_upload =$req->need_upload;
  468. $requirements->update();
  469. return response([
  470. 'msg'=>'Successfully updated.'
  471. ]);
  472. }elseif($name=="landing_register_form"){
  473. $validator=\Validator::make($req->all(), [
  474. 'name'=>'required',
  475. 'email'=>'required|email|max:255'
  476. ]);
  477. if($validator->fails()){
  478. $errors=$validator->errors()->all();
  479. return response(['msg'=>$errors[0]], 422);
  480. }
  481. $isUserExists = User::where(
  482. 'email',$req->email
  483. )->where(
  484. 'user_type',2
  485. )->where(function($q){
  486. $q->where('sign_up',1)->orWhere('sign_up',0);
  487. })->exists();
  488. if($isUserExists){
  489. return response([
  490. 'msg'=>'Already there is an account associated this email ID. Please login to your account.'
  491. ],403);
  492. }else{
  493. $user_data =new User;
  494. $user_data->first_name =$req->name;
  495. $user_data->email =$req->email;
  496. $user_data->nationality =$req->country_id;
  497. $user_data->university_name =$req->university;
  498. $user_data->uni_website =$req->uni_website;
  499. $user_data->user_type =2;
  500. $user_data->register_type =2; // 1=invitation ; 2= landing/wishlish
  501. // $user_data->invitation_date =now();
  502. $user_data->save();
  503. $user =User::where('email',$req->email)->where('user_type',2)->first();
  504. $refer =new ReferUser;
  505. $refer->name =$req->name;
  506. $refer->email =$req->email;
  507. $refer->teacher_id =$user->id;
  508. $refer->save();
  509. }
  510. return response(
  511. ['msg'=>'Successfully saved.']
  512. );
  513. }elseif($name=="send_email_document_information"){
  514. $data['teacher']=User::find($req->teacher_id);
  515. $data['student']=User::find($req->student_id);
  516. $data['std_proposal']=StudentProposal::find($req->id);
  517. $data['doc_requirement_list']=Requirement::where('std_proposal_id',$req->id)->get();
  518. $student =$data['student'];
  519. $user_mail = $student->email;
  520. $data['receive_email']=$student->email;
  521. $from = 'asraful@revinr.com';
  522. Mail::send('email.send_email_document_information',$data, function ($message) use ($user_mail,$from) {
  523. $message->from($from);
  524. $message->to($user_mail)->subject('Further Information Required');
  525. });
  526. return response(
  527. ['msg'=>'Send email successfully.']
  528. );
  529. }elseif($name=="proposal_status_rejected_form"){
  530. $data['teacher']=Auth::guard('teacher')->user();
  531. $validator=\Validator::make($req->all(), [
  532. 'feedback'=>'required',
  533. ]);
  534. if($validator->fails()){
  535. $errors=$validator->errors()->all();
  536. return response(['msg'=>$errors[0]], 422);
  537. }
  538. $proposal =StudentProposal::find($req->id);
  539. $proposal->proposal_status = 6; // rejected
  540. if($req->feedback=="others"){
  541. $proposal->feedback_msg =$req->feedback_msg;
  542. $proposal->feedback_reason =NULL;
  543. }else{
  544. $proposal->feedback_reason =$req->feedback;
  545. $proposal->feedback_msg =NULL;
  546. }
  547. $proposal->proposal_status_date =now();
  548. $proposal->update();
  549. $student = User::find($proposal->student_id);
  550. $student->freez_profile =0;
  551. $student->update();
  552. $teacher =User::find($proposal->teacher_id);
  553. if($proposal->feedback_msg){
  554. $reason = $proposal->feedback_msg;
  555. }else{
  556. $reason = $proposal->feedback_reason;
  557. }
  558. $data['teacher'] = $teacher->first_name.' '.$teacher->last_name;
  559. $data['student'] = $student->first_name.' '.$student->last_name;
  560. $data['reason'] =$reason;
  561. $data['receive_email']=$student->email;
  562. $from = 'asraful@revinr.com';
  563. $user_mail = $student->email;
  564. Mail::send('email.rejected_status_email',$data, function ($message) use ($user_mail,$from) {
  565. $message->from($from);
  566. $message->to($user_mail)->subject('Rejection of Research Application');
  567. });
  568. return response(
  569. ['msg'=>'Saved successfully.']
  570. );
  571. }
  572. return response(['msg'=>'No name argument found.'], 403);
  573. }
  574. }