What's the difference between:
class PostController extends \BaseController {
public function delete($id) {
$deletePost = Post::findOrFail($id);
return View::make('backend.delete')->with('post', $deletePost);
}
}
and
class PostController extends \BaseController {
public function delete(Post $post) {
return View::make('backend.delete')->with('post', $post);
}
}
Can somebody explain to me: public function delete(Post $post)
we are taking a Class named "Post" as a variable $post
?
UPDATE1.
in routes.php:
Route::model('post', 'Post');
Route::get('delete/{post}', array('uses' => 'PostController@delete'));
Route::post('delete', array('uses' => 'PostController@doDelete'));
and in PostController.php:
public function delete(Post $post) {
return View::make('backend.delete')->with('post', $post);
}
public function doDelete() {
$post = Post::findOrFail(Input::get('id'));
$post->delete();
return Redirect::action('PostController@home');
}
but anyway i get an error: No query results for model [Post]. with the 2nd method.