In the index method the last line has an extra indentation level, since it is a chained call:
In that destroy() method `$post$post is only used once after it is assigned:
Post::where('id',$id)->delete();
One could argue thatIn the index() method a more appropriate name forcollection of model records is fetched with the $postall() method:
$post = Post::all();
Perhaps a more descriptive variable name would be $posts since it could contain multiple records.
When calling (thoughwhere on a model class a query builder I.e. Illuminate\Database\Query\Builder Is returned. Thus perhaps a better name than id$post isin the primary key and unique so that wouldn't reallydestroy() method would be possible)$query. If a method like
Helper method to delete records
As firstWhere() wasthe documentation suggests the destroy() method could be used instead ofto delete a record without needing to call the where() thenmethod:
Post::destroy($id);
Though be aware that this may be slower and consume more resources, depending on what handlers for $post wouldevents may be appropriatedefined on the model.
The
destroymethod loads each model individually and calls the delete method so that thedeletinganddeletedevents are properly dispatched for each model. 2