Eloquent
Once you have created your model in /App you can use it in the Controller to start doing the queries.
Insetead of
- $notes = DB::table('note')->get();
You can replace it for:
- $notes = Note::all();
- return view('<folder>.<file_name>', compact('notes'));
Commands
- <Class>::find($id);
TIP
You can create a direct search using the following, laravel will search by default by ID
Router
Define a router to receive an object:
- Route::get('show/{notes}', 'NoteController@show');
Controller
In this case we are waiting an object of type Note, automatically will find by ID in the database
public function showObj(Note $notes){
return view('notes.show', compact('notes'));
}
View
In the view we receive the object notes
<div>
{{$notes->notes}}
</div>
Comentarios
Publicar un comentario