FooController.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\foo;
  4. use App\Models\User;
  5. use Illuminate\Http\Request;
  6. class FooController extends Controller
  7. {
  8. /**
  9. * Display a listing of the resource.
  10. *
  11. * @return \Illuminate\Http\Response
  12. */
  13. public function index()
  14. {
  15. $users = Foo::all();
  16. return $users;
  17. }
  18. /**
  19. * Show the form for creating a new resource.
  20. *
  21. * @return \Illuminate\Http\Response
  22. */
  23. public function create(Request $request)
  24. {
  25. //
  26. if (!$request->user()->tokenCan('uploader')) {
  27. abort(403,'你沒有上傳權限!');
  28. }
  29. $foo = Foo::Create([
  30. 'name' => 'test4',
  31. 'email' => 'foo2222@gmail.com',
  32. 'fk_tests_id' => 1,
  33. ]);
  34. return $foo;
  35. }
  36. /**
  37. * Store a newly created resource in storage.
  38. *
  39. * @param \Illuminate\Http\Request $request
  40. * @return \Illuminate\Http\Response
  41. */
  42. public function store(Request $request)
  43. {
  44. //
  45. $foo = new Foo;
  46. $foo->name = $request->name;
  47. $foo->email = $request->email;
  48. $foo->email_verified_at = $request->email_verified_at;
  49. $foo->save();
  50. }
  51. /**
  52. * Display the specified resource.
  53. *
  54. * @param \App\Models\foo $foo
  55. * @return \Illuminate\Http\Response
  56. */
  57. public function show(foo $foo)
  58. {
  59. $foo = Foo::where('foos.id', '>', 1)
  60. ->leftjoin('fk_tests', 'fk_tests.id', '=', 'foos.fk_tests_id')
  61. ->select('foos.*', 'fk_tests.name as fk_name', 'fk_tests.id as fk_id')
  62. ->get();
  63. return $foo;
  64. }
  65. /**
  66. * Show the form for editing the specified resource.
  67. *
  68. * @param \App\Models\foo $foo
  69. * @return \Illuminate\Http\Response
  70. */
  71. public function edit(foo $foo)
  72. {
  73. //
  74. }
  75. /**
  76. * Update the specified resource in storage.
  77. *
  78. * @param \Illuminate\Http\Request $request
  79. * @param \App\Models\foo $foo
  80. * @return \Illuminate\Http\Response
  81. */
  82. public function update(Request $request, foo $foo)
  83. {
  84. //
  85. $foo = foo::where('name', 'test2')->get()[0];
  86. // $foo = foo::find(1);
  87. $foo->email = $request->email;
  88. $foo->save();
  89. // foo::where('name', 'oransheep')
  90. // ->update(['email' => $request->email]);
  91. return $foo;
  92. }
  93. /**
  94. * Remove the specified resource from storage.
  95. *
  96. * @param \App\Models\foo $foo
  97. * @return \Illuminate\Http\Response
  98. */
  99. public function destroy(foo $foo)
  100. {
  101. //
  102. }
  103. }