Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Http\Controllers;
- use App\Game;
- use Illuminate\Http\Request;
- class GameController extends Controller
- {
- /**
- * Display a listing of the resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function index()
- {
- $games = Game::all();
- return view('game.index', compact('games'));
- }
- /**
- * Show the form for creating a new resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function create()
- {
- return view('game.create');
- }
- /**
- * Store a newly created resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @return \Illuminate\Http\Response
- */
- public function store(Request $request)
- {
- $name = $request->name;
- $developer = $request->developer;
- $objGame = new Game();
- $objGame->name = $name;
- $objGame->developer = $developer;
- $objGame->save();
- return redirect('/games')->with('success', 'Game added');
- }
- /**
- * Display the specified resource.
- *
- * @param \App\Game $game
- * @return \Illuminate\Http\Response
- */
- public function show(Game $objGame)
- {
- }
- /**
- * Show the form for editing the specified resource.
- *
- * @param \App\Game $game
- * @return \Illuminate\Http\Response
- */
- public function edit($id)
- {
- $objGame = Game::find($id);
- return view('game.edit', compact('objGame'));
- }
- /**
- * Update the specified resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @param \App\Game $game
- * @return \Illuminate\Http\Response
- */
- public function update(Request $request,$id)
- {
- $request->validate([
- 'name'=>'required',
- 'developer'=> 'required',
- ]);
- $objGame = Game::find($id);
- $objGame->name = $request->get('name');
- $objGame->developer = $request->get('developer');
- $objGame->save();
- return redirect('/games')->with('success', 'Stock has been updated');
- }
- /**
- * Remove the specified resource from storage.
- *
- * @param \App\Game $game
- * @return \Illuminate\Http\Response
- */
- public function destroy($id)
- {
- $objGame = Game::find($id);
- $objGame->delete();
- return redirect('/games')->with('success', 'Deleted Successfully!');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement