php - Laravel Object Oriented -
i new oop, although know interfaces , abstract classes bit. have lot of resource controllers similar in bigger scheme of things, example below, main difference index , pass index view.
what need know is, can oo things bit resource controllers? example, create 1 "main" resource controller in pass correct instances using interface example? tried playing around got error interface wasn't instantiable, had bind it. means bind interface specific controller.
any advice, tips , pointers me out :)
class notescontroller extends controller { public function index() { $notes = note::all(); return view('notes.index', compact('notes')); } public function create() { return view('notes.create'); } public function show(note $note) { return view('notes.show', compact('note')); } public function edit(note $note) { return view('notes.edit', compact('note')); } public function store(request $request, user $user) { $user->getnotes()->create($request->all()); flash()->success('the note has been stored in database.', 'note created.'); return redirect::route('notes.index'); } public function update(note $note, request $request) { $note->update($request->all()); flash()->success('the note has been edited.', 'note edited.'); return redirect::route('notes.index'); } public function delete($slug) { note::where('slug', '=', $slug)->delete(); return redirect::to('notes'); } }
note: totally opinion!
i keep them how have them. makes them easier read , understand later. save time when need update 1 different rest. tried in project worked on , while granted wasn't best implementation, still pain point day.
up though. i'm sure people have done in way love , works great. hasn't been case in experience. doubt @ code though , criticize not doing it.
Comments
Post a Comment