SHARE
TWEET

TasksController.php

asimryu Jun 30th, 2020 985 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. namespace App\Http\Controllers;
  4.  
  5. use Illuminate\Http\Request;
  6. use Auth;
  7. use App\Task;
  8.  
  9. class TasksController extends Controller
  10. {
  11.     public function index()
  12.     {
  13.         $user = Auth::user();
  14.         return view('welcome',compact('user'));
  15.     }
  16.  
  17.     public function add()
  18.     {
  19.         return view('add');
  20.     }
  21.  
  22.     public function create(Request $request)
  23.     {
  24.         $task = new Task();
  25.         $task->description = $request->description;
  26.         $task->user_id = Auth::id();
  27.         $task->save();
  28.         return redirect('/');
  29.     }
  30.  
  31.     public function edit(Task $task)
  32.     {
  33.  
  34.         if (Auth::check() && Auth::user()->id == $task->user_id)
  35.         {            
  36.                 return view('edit', compact('task'));
  37.         }          
  38.         else {
  39.              return redirect('/');
  40.          }             
  41.     }
  42.  
  43.     public function update(Request $request, Task $task)
  44.     {
  45.         if(isset($_POST['delete'])) {
  46.             $task->delete();
  47.             return redirect('/');
  48.         }
  49.         else
  50.         {
  51.             $task->description = $request->description;
  52.             $task->save();
  53.             return redirect('/');
  54.         }      
  55.     }
  56. }
  57.  
  58. //source by https://www.parthpatel.net/laravel-tutorial-for-beginner/
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top