SHARE
TWEET

Untitled

a guest Mar 17th, 2018 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.  
  10.  
  11. class UserController extends Controller
  12. {
  13.     /**
  14.      * Display a listing of the resource.
  15.      *
  16.      * @return \Illuminate\Http\Response
  17.      */
  18.     public function index()
  19.     {
  20.         $users = User::all();
  21.  
  22.         //Load all users on the table and pass the users
  23.         $users = User::where(['archive'=>1])->orderBy('id')->get();
  24.         return view('usercrud.index')->with('users', $users);      
  25.     }
  26.  
  27.     /**
  28.      * Show the form for creating a new resource.
  29.      *
  30.      * @return \Illuminate\Http\Response
  31.      */
  32.     public function create(Request $request)
  33.     {
  34.         //
  35.         $usersC = new User;
  36.  
  37.         $usersC->position = $request->companyPos;
  38.         $usersC->name = $request->fullname;
  39.         $usersC->email = $request->email;
  40.         $usersC->password = bcrypt($request->password);
  41.         $usersC->roles = $request->role_id;
  42.         //$usersC->verifyToken=Str::random(40);
  43.         $usersC->verifyToken=$this-> Str::random(40);
  44.         $usersC -> save();
  45.  
  46.  
  47.         $users = User::all();
  48.         $users = User::where(['archive'=>1])->orderBy('id')->get();
  49.  
  50.         return redirect()->to('userIndex')->with('users', $users);
  51.    
  52.        
  53.     }
  54.  
  55.     /**
  56.      * Store a newly created resource in storage.
  57.      *
  58.      * @param  \Illuminate\Http\Request  $request
  59.      * @return \Illuminate\Http\Response
  60.      */
  61.     public function store(Request $request)
  62.     {
  63.         //
  64.     }
  65.  
  66.     /**
  67.      * Display the specified resource.
  68.      *
  69.      * @param  int  $id
  70.      * @return \Illuminate\Http\Response
  71.      */
  72.     public function show($id)
  73.     {
  74.         //
  75.     }
  76.  
  77.     /**
  78.      * Show the form for editing the specified resource.
  79.      *
  80.      * @param  int  $id
  81.      * @return \Illuminate\Http\Response
  82.      */
  83.     public function edit($id)
  84.     {
  85.         //
  86.         $users = User::where(['id'=>$id])->first();
  87.  
  88.  
  89.         // dd($users);
  90.  
  91.          return view('usercrud.edit',compact('users'));
  92.     }
  93.  
  94.     /**
  95.      * Update the specified resource in storage.
  96.      *
  97.      * @param  \Illuminate\Http\Request  $request
  98.      * @param  int  $id
  99.      * @return \Illuminate\Http\Response
  100.      */
  101.     public function update(Request $request, $id)
  102.     {
  103.         //
  104.         $usersUp = new User;
  105.         $password = bcrypt($request->editpassword);
  106.  
  107.  
  108.         // dd($request->editcompanyPos);
  109.  
  110.         $usersUp = User::where('id',$id)
  111.             ->update(['position'=>$request->editcompanyPos,'name'=>$request->editfullname,'email'=>$request->editemail,'password'=>$password,'roles'=>$request->editrole_id]);
  112.  
  113.         $users = User::all();
  114.         $users = User::where(['archive'=>1])->orderBy('id')->get();
  115.  
  116.         return redirect()->to('userIndex')->with('users', $users);
  117.     }
  118.  
  119.     /**
  120.      * Remove the specified resource from storage.
  121.      *
  122.      * @param  int  $id
  123.      * @return \Illuminate\Http\Response
  124.      */
  125.     public function destroy($id)
  126.     {
  127.         $userDel = User::where('id',$id)->update(['archive'=>0]);
  128.  
  129.         $users = User::all();
  130.         $users = User::where(['archive'=>1])->orderBy('id')->get();
  131.  
  132.         return redirect()->to('userIndex')->with('users', $users);
  133.  
  134.     }
  135. }
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